建立测试文件夹
$ mkdir test_truffle_geth
$ cd test_truffle_geth/
建立创世块(genesis.json即配置文件)
sudo vim genesis.json
{
"config": {
"chainId": 666,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x00002",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
初始化文件夹
$ geth1 init ./genesis.json --datadir "./chain"
启动私有链
geth1 --identity "mshk.top etherum" --rpcaddr 127.0.0.1 --rpc --rpcport "8545" --rpccorsdomain "*" --maxpeers 2 --rpcapi "personal,eth,net,web3,debug" --networkid 100 --datadir "./chain" --nodiscover --allow-insecure-unlock --dev.period 1 console
创建账户开始挖矿
# 创建帐号
> personal.newAccount("123456")
# 解锁
> personal.unlockAccount(eth.accounts[0],"123456",15000)
# 开始挖矿
> miner.start(1)
还是拿之前测试的合约来运行
首先需要更改truffle-config.js文件:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*", // Match any network id
}
}
};
然后执行truffle migrate即可部署合约
打开index.html

测试通过