原因:
第一个账户未解锁,而合约部署需要支付汽油费
解决:
1、personal.unlockAccount(eth.accounts[0])解锁账户;
2、loadScript("contract.js")部署合约
3、miner.start()矿工挖矿,合约被写到区块链
4、miner.stop()结束挖矿
5、合约地址为:Contract mined! address 后面部分
具体操作如下:
> loadScript("F:/MyGeth/DAPP/chap06/smartContract/section02/PayContract.js");
Error: authentication needed: password or unlock undefined
true
> eth.accounts
["0x1efe2ce884c1837bee9423878f56d9c95d486167", "0x41435e453f279a21b33a6a62e5ad632db9a99e42", "0x1207c73236adff288e563766494eaa4310bded4a"]
> personal.unlockAccount(eth.accounts[0])
Unlock account 0x1efe2ce884c1837bee9423878f56d9c95d486167
Passphrase:
true
> loadScript("F:/MyGeth/DAPP/chap06/smartContract/section02/PayContract.js");
null [object Object]
true
> miner.start()
null
> null [object Object]
Contract mined! address: 0x173cfc4b31bcdfcf18792fe5f30eda6d272d7b9b transactionHash: 0x6190ecdf8a29d347a2ab907a729affa5ed925d04712d0aa7faf124b34f4d228c
> miner.stop()
null
>