truffle 发布 智能合约

参考 这篇https://www.codeooze.com/blockchain/ethereum-geth-private-blockchain/ 说的已经很详细了 html

genesis.json 过期了可参考https://mlgblockchain.com/ethereum-private-network.html修改成以下web

{json

"config" :{api

"chainId": 16,cors

"homesteadBlock": 0,dom

eip155Block": 0,spa

eip158Block":0.net

},code

"nonce": "0x0000000000220042",htm

"timestamp": "0x0",

parentHash": "0x000000000000000000",

"mixhash": "0x000000000000000000",

"gasLimit": "0x8000000",

"difficulty": "0x10",

"alloc":{}

}

geth --datadir privchain init genesis.json

geth --port 3000 --networkid 58342 --nodiscover --datadir="privchain" --maxpeers=0 --rpc --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3"

而后新启动一个终端输入 以下 

geth attach ipc://home/someone/privchain/geth.ipc

geth启动基本也就完成了 

personal.newAccount('password')

 

personal.unlockAccount(web3.eth.coinbase, "password", 15000) 解锁帐户 否则发布的时候会报错  15000应该是时间 超时以后从新解锁帐户就能够了 

miner.start() 保证挖矿状态

truffle migrate --reset (此处为了不遇到错误 我直接带上reset参数)

truffle console

 

HelloWorld.deployed() 就算完成了 

中途遇到2个错误 其一  Error: No network specified. Cannot determine current network异常

缘由是 truffle配置文件中没有指定networkid 

致使上面异常的缘由为是由于truffle.js里面未配置连接合约发布的环境地址,找到对应的truffle.js文件,修改代码为相似以下配置便可解决问题:

module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" // 匹配任何network id } } };其二 Error: Exceeds block gas limitgas给的(或者消耗的)太多超出区块最大的gas限制量了 修改gaslimit
相关文章
相关标签/搜索