智能合約 helloworld

windows 平臺 因此直接使用Remix在線編譯環境web

新建hello.sol文件 編輯以下windows

Remix 右邊側欄 setting 選擇合適的編譯器版本 這裏選擇 0.4.19  ui

文件中輸入以下內容   注意版本匹配命令行

pragma  solidity ^0.4.19;3d

contract hello {部署

function sayHello() public returns (string ret)
{
return "Hello , world !";
}
}get

編譯...input

複製 web3deploy 內容 這裏注意 因爲是js版本  我本地不支持var 直接複製到文本 幹掉var變量定義編譯器

而後在geth命令行 建立帳戶 string

personal.newAccount()  

這裏要求輸入密碼 

而後解鎖帳戶

personal.unlockAccount(eth.accounts[0]);

而後將上面複製好的WEB3DEPLOY 內容粘貼

相似  

simplestorageContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]);

simplestorage = simplestorageContract.new( { from: web3.eth.accounts[0], data: '0x6080604052348015600f57600080fd5b5060a08061001e6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636d4ce63c146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b6000439050905600a165627a7a72305820e4f6d169a5bf00bf4117a17cd8c02f49d9c44fa18212a81b735ec793ea524efa0029', gas: '4700000' }, function (e, contract){ console.log(e, contract); if (typeof contract.address !== 'undefined') { console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); } })

miner.start(1); 等待一秒 返回結果 

Contract mined! address 

則說明合約部署成功

miner.stop();

輸入 

simplestorage.get();

相關文章
相關標籤/搜索