The following is a code snippet originally posted by Daniel McClure on GitHub as a Gist.
greeter.sol
“`
pragma solidity ^0.5.0;
contract mortal {
/* Define variable owner of the type address */
address owner;
/* This function is executed at initialisation and sets the owner of the contract */
constructor() public { owner = msg.sender; }
/* Function to recover the funds of the contract */
function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); }
}
contract greeter is mortal {
/* Define variable greeting of the type string */
string greeting;
/* This runs when the contract is executed */
constructor(string memory _greeting) public {
greeting = _greeting;
}
/* Main Function */
function greet() public view returns (string memory) {
return greeting;
}
}
“`
Original Gist
pragma solidity ^0.5.0; | |
contract mortal { | |
/* Define variable owner of the type address */ | |
address owner; | |
/* This function is executed at initialisation and sets the owner of the contract */ | |
constructor() public { owner = msg.sender; } | |
/* Function to recover the funds of the contract */ | |
function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); } | |
} | |
contract greeter is mortal { | |
/* Define variable greeting of the type string */ | |
string greeting; | |
/* This runs when the contract is executed */ | |
constructor(string memory _greeting) public { | |
greeting = _greeting; | |
} | |
/* Main Function */ | |
function greet() public view returns (string memory) { | |
return greeting; | |
} | |
} |
Leave a Reply