美文网首页
build geth local testnet ETH私链搭建

build geth local testnet ETH私链搭建

作者: nemo_test | 来源:发表于2020-08-10 17:18 被阅读0次

geth 下载地址:https://geth.ethereum.org/downloads/

  1. download geth
wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.15-0f77f34b.tar.gz \
    && tar -xzvf geth-linux-amd64-1.9.15-0f77f34b.tar.gz \
    && cp ./geth-linux-amd64-1.9.15-0f77f34b/geth /usr/local/bin/
    && rm -rf geth*
  1. create genesis.json
    将需要有初始ETH的账号配置在此文件中
{
  "config": {
    "chainId": 123,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "ByzantiumBlock": 0
  },
  "difficulty": "1",
  "gasLimit": "2100000",
  "alloc": {
    "0x4fe77cb0cdc5d302778a4096fad97c5c5313d4b5": {
      "balance": "20000000000000000000000000"
    },
    "0xd0da98b9d11a6632e0f534a5ff32152c8bc26629": {
      "balance": "200000000000000000000000000"
    },
    "0x04e98D7A5ca93d3DdcF88DbB0f9Dde1E2910061f": {
      "balance": "2000000000000000000000000000"
    },
    "0xc5E33b3CED9aF1c58875759cE1A179b9Ee06761d": {
      "balance": "2000000000000000000000000000"
    }
  }
}
  1. initialize geth
mkdir ~/gethDataDir/
geth --datadir ~/gethDataDir/ init genesis.json
  1. start geth
geth --mine --miner.threads=1 --datadir ~/gethDataDir --networkid 123 --rpc --rpcaddr 0.0.0.0 --rpcport=8547 --rpcapi="db,eth,net,web3,personal,web3" --allow-insecure-unlock --miner.etherbase=0xEc67A59e54A393b702c7EcCe1faca731E4f0e601
  1. deploy ERC20
    参考:https://learnblockchain.cn/2017/11/24/init-env/
geth attach http://127.0.0.1:8547
# 导入自己地址的私钥,密码为1
>web3.personal.importRawKey("51C2C48AE17D472631D8F2DF567EF9B44A625EBF55FA4D7BB6521E7E9D96E701","1")

# check是否导入成功
>personal.listAccounts  #should contain account 0xc5E33b3CED9aF1c58875759cE1A179b9Ee06761d

# 导入ERC20的bin文件
>loadScript('/opt/nash/bnb.bin')

# 发行成功后,会返回ERC20的合约address
  • 如果遇到ERROR: Error: exceeds block gas limit undefined
geth attach http://127.0.0.1:8547
#获取最新的gaslimit
>eth.getBlock('latest').gasLimit

# 把返回的最新的gaslimit填入bin中对应的字段里,再次loadScript

相关文章

网友评论

      本文标题:build geth local testnet ETH私链搭建

      本文链接:https://www.haomeiwen.com/subject/nlvjdktx.html