geth私有网络搭建

创建一些可用的私钥账号地址对

Available Accounts
==================
(0) 0x3cd920baad7f3bde18a5634137c2738450be661b
(1) 0x2bba01ea4c178d6875dc0e1bfd204c8ff9bc67fb
(2) 0x014be69aa7036b39c49f381a7e4acdf68542e64e
(3) 0xf4485a5760784ec9072207f76eef4f2378673d06
(4) 0x04fafeb85c6dc77017261bd615fef75b91d17651
(5) 0x5513b4908ebad503a9f3f325df57f7142b7d66a5
(6) 0x15a27919458626a321ba0adcfa422f6d46161423
(7) 0xec9e36edf7cb4cd27f37cd7250cae8bbe9ca1dca
(8) 0x814cdc8753f6d449870fdab6e8e659ce9a9f1b37
(9) 0xe20441f7c2ed14ded8996ac3cda0ec960fff33ca

Private Keys
==================
(0) 7a598ef0406c4694ac92b006a118dd214f600f943d7131d9c6e00abeba3bde2b
(1) 439c95f9352769b777be5d62228e60e732f4d4dc95bfaa8e0dfd2bfa3ba01fd4
(2) 024797212bc4c922bf574fa5bd729bfcbb234e1d6e95b7e00a1b3e38e53169a4
(3) 365a6b0c83207b64b547c91b9299dbb90fef503bf3f510e0b2883183f4ec98d5
(4) 1abe64cf6adfb05cc1e7ee2533b97078e3d0850db209e19bd11bf0552f8572ac
(5) 77354920fe5566f59eaa841d9f6aa263ec02f0cd82b1ed489fcb0640ad3fd0da
(6) a3f79c2a2b01ec7cec9c9d29d69b764b367715dfe005a044cebf8b2d74814634
(7) 72b86c2256b11894a6160114cef960a8309318b65a0c31d97065be9231e4c084
(8) fd9a5e5d5a389f6e87e8a56001976dda010eeab4ae151b74e3a538c74270392d
(9) 49de188c039dfce6b05d4fd1e5ae9966827e8a2a368184479ac1d974fe5a63ec

创建 genesis.json 文件内容如下:

{
        "config": {
                "chainId": 15,
                "homesteadBlock": 0,
                "eip155Block": 0,
                "eip158Block": 0
        },
        "coinbase": "0x0000000000000000000000000000000000000000",
        "difficulty": "0x40",
        "extraData": "",
        "gasLimit": "0xffffffff",
        "nonce": "0x0000000000000042",
        "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "timestamp": "0x00",
        "alloc": {
                "0x3cd920baad7f3bde18a5634137c2738450be661b":{ "balance": "2000000000000000000000" },
                "0x2bba01ea4c178d6875dc0e1bfd204c8ff9bc67fb":{ "balance": "2000000000000000000000" },
                "0x014be69aa7036b39c49f381a7e4acdf68542e64e":{ "balance": "2000000000000000000000" },
                "0xf4485a5760784ec9072207f76eef4f2378673d06":{ "balance": "2000000000000000000000" },
                "0x04fafeb85c6dc77017261bd615fef75b91d17651":{ "balance": "2000000000000000000000" },
                "0x5513b4908ebad503a9f3f325df57f7142b7d66a5":{ "balance": "2000000000000000000000" },
                "0x15a27919458626a321ba0adcfa422f6d46161423":{ "balance": "2000000000000000000000" },
                "0xec9e36edf7cb4cd27f37cd7250cae8bbe9ca1dca":{ "balance": "2000000000000000000000" }
        }
}

$ 初始化
geth –datadir “./blockData” init genesis.json

运行命令启动节点:

geth --datadir "./blockData" --networkid 15 --rpc --rpcaddr 0.0.0.0 --rpcapi "db,eth,net,web3,personal,admin"  --rpccorsdomain "*" --mine --minerthreads=1 --etherbase=0x0af80fe90dac81431c8dc14feae224b8e38b12fb --targetgaslimit=471238899999999

启动命令行:

geth attach http://127.0.0.1:8545

导入账号:

personal.importRawKey("7a598ef0406c4694ac92b006a118dd214f600f943d7131d9c6e00abeba3bde2b", "1")
personal.importRawKey("439c95f9352769b777be5d62228e60e732f4d4dc95bfaa8e0dfd2bfa3ba01fd4", "1")
personal.importRawKey("024797212bc4c922bf574fa5bd729bfcbb234e1d6e95b7e00a1b3e38e53169a4", "1")
personal.importRawKey("365a6b0c83207b64b547c91b9299dbb90fef503bf3f510e0b2883183f4ec98d5", "1")

解锁:

ul = function() {for (i = 0; i < personal.listAccounts.length; i++) {personal.unlockAccount(personal.listAccounts[i],"1",360000)}};

ul();

查询余额:

eth.getBalance("0x3cd920baad7f3bde18a5634137c2738450be661b")

转账:

eth.sendTransaction({from:eth.accounts[0],to:"0x00d7ff1caa4bd58b6461fc35850bffb4b9e2d836",value:web3.toWei(1,"ether"),gas:500000})

查询交易:

eth.getTransaction("0x49603890a3548ea6642a9b17a228d9e7902242e9441895f01474c59460f9f171", function(err,result){console.log(err,JSON.stringify(result,null,4))})

查询交易回执:

eth.getTransactionReceipt("0x49603890a3548ea6642a9b17a228d9e7902242e9441895f01474c59460f9f171", function(err,result){console.log(err,JSON.stringify(result,null,4))})

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 ancjf@163.com

文章标题:geth私有网络搭建

本文作者:ancjf

发布时间:2016-11-23, 17:51:36

最后更新:2020-09-15, 08:34:13

原始链接:http://ancjf.com/2016/11/23/geth%E7%A7%81%E6%9C%89%E7%BD%91%E7%BB%9C%E6%90%AD%E5%BB%BA/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏