以太坊实验
在自己的电脑上安装配置以太坊开发环境,搭建以太坊私有链,编写一个简单的智能合约,通过以太坊JSON RPC 和JavaScript API编程接口将其部署到所创建的以太坊私有链,并可调用合约获得正确的合约执行结果。
本次作业的最终提交物是一个描述上述过程的完整文档,请把整个过程用文字和截图描述清楚。
- 本机已经安装go
- 安装以太坊Ethereum
brew update
brew upgrade
brew tap ethereum/ethereum
brew install ethereum
- 安装solc编译器
npm install solc
- 创建账户
geth account new
- 编写创始块文件
{
"config": {
"chainId": 10,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000042",
"difficulty": "0x1",
"alloc": {
"14b1d82b1c851ea9a6623a20d9865677ecdac70c":{
"balance": "20000009800000000000000000000"
},
"aa25a7b683fe0564fe6b2a2574e10dc886ecb3ce":{
"balance": "20000009800000000000000000000"
}
},
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0xb2d05e00"
}
-
配置自动解锁账户的脚本
在~/Library/Ethereum下创建password文件内容为创建账户的密码
-
编写启动脚本
#!/bin/bash
geth --rpc --rpcaddr="0.0.0.0" --rpcport "8545" --rpccorsdomain="*" --unlock '0,1' --password ~/Library/Ethereum/password --nodiscover --maxpeers '5' --n etworkid '123' --datadir '~/Library/Ethereum' console --rpcapi "db,eth,net,web3,personal,admin,miner"
- 启动网络
./start.sh
- 通过JRPC与网络交互(均编写在脚