u=2776538594,1820117301&fm=26&gp=0.jpg

先创建genesis.json

{
  "config": {
        "chainId": 10, 
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

打镜像

#registry.cn-hangzhou.aliyuncs.com/sre_pub/ethereum
FROM ubuntu:latest
 # Get the Ethereum Stuffs
 RUN apt-get update
 RUN apt-get install -y software-properties-common
 RUN apt-get install -y build-essential git
 RUN add-apt-repository ppa:longsleep/golang-backports
 RUN apt-get update
 RUN apt-get install -y golang-go
 RUN git clone https://github.com/ethereum/go-ethereum
 WORKDIR /go-ethereum
 RUN make geth
 WORKDIR /
 # House the data here
 RUN mkdir /block-data
 # Pass in the genesis block.
 COPY genesis.json genesis.json
 RUN ln -sf /go-ethereum/build/bin/geth /bin/geth
 EXPOSE 22 8088 50070 8545
 #networkid要与json的chainId对应,启动--allow-insecure-unlock
 ENTRYPOINT geth --datadir /block-data init /genesis.json; geth --port 3000 --networkid 10 --nodiscover --datadir=/block-data --maxpeers=0  --rpc  --rpcaddr 0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --nousb --allow-insecure-unlock --dev --dev.period 1

pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ethereum-disk
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: "500Gi"
  volumeName: 
  storageClassName: nfs

Deployment svc

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ethereum
spec:
  replicas: 1
  selector:
    matchLabels:
      rpc: ethereum
  template:
    metadata:
      labels:
        rpc: ethereum
    spec:
      #serviceAccountName: registrysecret
      containers:
      - name: ethereum
        image: registry.cn-hangzhou.aliyuncs.com/sre_pub/ethereum
        imagePullPolicy: IfNotPresent
        restartPolicy: OnFailure
        ports:
        - containerPort: 8545
          name: ethereum
          protocol: TCP
        volumeMounts:
        - name: ethereum-disk
          mountPath: /block-data
      volumes:
       - name: ethereum-disk
         persistentVolumeClaim:
           claimName: ethereum-disk 
 --
kind: Service
apiVersion: v1
metadata:
  labels:
    rpc: ethereum
  name: ethereum
spec:
  type: NodePort
  ports:
  - name: ethereum
    port: 8545
    targetPort: 8545
    nodePort: 30087
    protocol: TCP
  selector:
    rpc: ethereum

测试

curl http://172.16.0.12:30087
geth attach http://172.16.0.12:30087
personal.newAccount('12345678')
personal.unlockAccount(eth.accounts[1], "12345678", 15000)
miner.start()


概念和命令

概念

eth:包含一些跟操作区块链相关的方法
net:包含以下查看p2p网络状态的方法
admin:包含一些与管理节点相关的方法
miner:包含启动&停止挖矿的一些方法
personal:主要包含一些管理账户的方法
txpool:包含一些查看交易内存池的方法
web3:包含了以上对象,还包含一些单位换算的方法

用于开始挖掘的常见命令

创建新帐户 : personal.newAccount('12345678') #密码 0x539bcbb3dfc0c06ca9166325bfb6b1bfa51569b3
解锁帐户 : personal.unlockAccount(web3.eth.coinbase, "123456", 15000)
开始挖掘 : miner.start()
停止挖掘 : miner.stop()

执行设置miner地址:

miner.setEtherbase(eth.coinbase)
true

也可以执行执行以下命令进行设置:

miner.setEtherbase(eth.accounts[0])
true

初始化创世区块: geth init ./genesis.json --datadir "D:\Eth"
启动节点:geth --datadir "D:\Eth" --networkid 10 --port 30303 --rpc --rpcaddr 127.0.0.1 --rpcapi "db,eth,personal,net,web3" --allow-insecure-unlock console
开始挖矿:miner.start() miner.stop()
账户余额:eth.getBalance("地址")

创建账户:personal.newAccount("");
"0xf1c4dabd99003feaef5bff65658bf5976627e3fa" 0
"0xccc915534b908fcb4e1ee9063e5b1d0d3be5672d" 1

账号列表:eth.accounts
解锁账号:personal.unlockAccount(eth.accounts[5],"",0) 启动--allow-insecure-unlock
定义数量:amount = web3.toWei(50,'ether')

转账:eth.sendTransaction({from:eth.accounts[0],to:"", value:amount})

挖矿奖励账户:eth.coinbase miner.setEtherbase(eth.accounts[1])

交易池状态:txpool.status
获取区块:eth.getBlock()
获取交易信息:eth.getTransaction("0xbee5007e38adf954f8a6cf699f771d39c9c8235920d71b6f96d66c72254d7724")

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code