智能合约编写01

Hello.sol

pragma solidity ^0.4.22;

contract Hello {
    /* Define variable owner of the type address */
    address public owner;

    /* Define variable greeting of the type string */
    string public greeting ;

    /* Function to recover the funds on the contract */
    function kill() public { 
      if (msg.sender == owner)selfdestruct(owner);
    }

    /* This runs when the contract is executed */
    constructor(string _greeting) public {
        owner = msg.sender;
        greeting = _greeting;
    }

    /* Main function */
    function greet() public constant returns (string) {
        return greeting;
    }
}

编译合约

开启私链或者测试链

测试链开启,请查看前面的章节

私链开启,请查看后面的章节

本例用了私链

部署并使用合约

最后更新于