温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Mac怎么创建以太坊私有链多节点转账

发布时间:2021-12-31 11:56:43 来源:亿速云 阅读:154 作者:柒染 栏目:互联网科技

这篇文章将为大家详细讲解有关Mac怎么创建以太坊私有链多节点转账,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

一、mac1电脑节点

创建genesis.json文件

{
"config" : {
"chainId": 898,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {
"0x2258b64ee6163edc94f1cd7c98de178adbc0a91c":{ "balance":
"1000000000000000000000" },
"0x4c33529ed970f2dcd645beb91ae6bb985bd8c3c4":{ "balance":
"1000000000000000000000" }
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x000000100",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" :
"0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" :
"0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}

$ cd /Users/shijun/Desktop/blockChain/ethereum/private

$ geth --datadir data0 init genesis.json

$ geth --identity "itari" --datadir data0 --networkid 898 --port 30303 --rpc --rpcaddr localhost --rpcport 8545 --gcmode archive console

注意--gcmode archive参数是将金额保存在硬盘

> personal.newAccount()
Passphrase: 

Repeat passphrase: 

"0x902dbef5c59c10e7e5744eee6aa622c455a05d79"

> personal.newAccount()

Passphrase: 

Repeat passphrase: 

"0x764ad66588b7b3bf4ebd22ca55a419792e3b8456"

> admin.nodeInfo.enode

"enode://dcab3950426148473714e031ace294e0efb607bebb93d2a8312024cd44db48a8691125aa463e2fe2cd1eff2eeb7db86061803b212c3e3b5fed94001ef8c5a50f@[::]:30303"

> INFO [05-21|14:05:46] Block synchronisation started

上面这个是自动同步区块,不是手动输的

> eth.blockNumber

43

> eth.accounts

>eth.getBalance(eth.accounts[0])

Metamask操作

选择本地网络localhost 8545

将帐号json文件导入到MetaMask

/Users/shijun/Desktop/blockChain/ethereum/private/data0/keystore/UTC--2018-05-21T06-00-31.402671377Z--902dbef5c59c10e7e5744eee6aa622c455a05d79

/Users/shijun/Desktop/blockChain/ethereum/private/data0/keystore/UTC--2018-05-21T06-00-51.372530256Z--764ad66588b7b3bf4ebd22ca55a419792e3b8456

二、mac2电脑节点

同上步骤之后,加入节点

> admin.addPeer("enode://619c5b62f9f25ba7e4dee1f7dd3e0cf9ac8a27e46503078df7c86f139f75e465c2818df7735b319c95b4b2d805f92e218d742fb25695987bb4a007d5062eb421@10.85.110.146:30303")

true

INFO [05-21|14:23:37] Block synchronisation started

> personal.newAccount()

> eth.getBalance(eth.accounts[0])

> miner.start(1); admin.sleepBlocks(1); miner.stop();

三、mac1电脑节点

终端操作

> amount=web3.toWei(1,'ether');

"1000000000000000000"

> personal.unlockAccount(personal.listAccounts[0]);

Unlock account 0x902dbef5c59c10e7e5744eee6aa622c455a05d79

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

INFO [05-21|14:31:00] Submitted transaction 

>eth.getBalance(eth.accounts[0])

> miner.start(1); admin.sleepBlocks(1); miner.stop();

true

关闭后再次启动私有链

$ cd /Users/shijun/Desktop/blockChain/ethereum/private

$ geth --identity "itari" --datadir data0 --networkid 899 --port 30303 --rpc --rpcaddr localhost --rpcport 8545 --gcmode archive console
注意--gcmode archive参数是将金额保存在硬盘
使用这个,本地java项目可以联通

注意事项:java调用miner命令使用以下命令启动私有链

非后端运行模式

$ geth --identity "itari" --gcmode archive --datadir data0 --networkid 898 --port 30303 --rpc --rpcaddr localhost --rpcport 8545 --rpcapi "db,web3,eth,personal,miner,net,txpool" --rpccorsdomain "*" console 2>> data.log

注意--gcmode archive参数是将金额保存在硬盘

注意事项:前后端分离运行模式

$ nohup geth --identity "itari" --gcmode archive --datadir data0 --networkid 898 --port 30303 --rpc --rpcaddr localhost --rpcport 8545 --rpcapi "db,web3,eth,personal,miner,net,txpool" --rpccorsdomain "*" &

交互命令

$geth attach ipc:/usr/local/ethereum/private/data0/geth.ipc

注意事项:如果公网远程访问,localhost改为0.0.0.0

关于Mac怎么创建以太坊私有链多节点转账就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mac
AI