本文需要先搭建测试链,搭建教程参考之前的博客区块链基础教程1ETH&BTC私链搭建修改genesis.json//genesis.json:"alloc":{"3028667C719A7255192be6d5bEEB665cF5De96B0":{
修改 genesis.json
// genesis.json:
"alloc": {
"3028667C719A7255192be6d5bEEB665cF5De96B0": { "balance": "100000000000" },
"A962e2f0DB8d631E178B9012B53883d0E04048Db": { "balance": "100000000000" }
}
}
其中: 3028667C719A7255192be6d5bEEB665cF5De96B0 对应私钥: f5bdb4dafa29f1994703b1c24fe603923...df1c A962e2f0DB8d631E178B9012B53883d0E04048Db 对应私钥: e2e052903e03a26ed42607e52d1293b5f...1b7
geth init --datadir data genesis.json
修改启动命令如下:
geth --rpc.enabledeprecatedpersonal --datadir ./data --networkid 8888 --nodiscover console 2>geth.log
创建地址:
personal.newAccount()
> eth.getBalance('0x....')
300000
导入账号
personal.importRawKey("私钥", "密码")
发送前需要解锁账户
personal.unlockAccount(eth.accounts[0])
转账测试:
eth.sendTransaction({
from: '0x3028667c719a7255192be6d5beeb665cf5de96b0',
to: '0xa962e2f0db8d631e178b9012b53883d0e04048db',
value: web3.toWei(100, 'wei'),
gas: 21000,
gasPrice: web3.toWei(10, "wei")
})
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!