pragma solidity 0.5.6;
contract Mortal {
/* Define variable owner of the type address */
address payable owner;
/* This function is executed at initialization and sets the owner of the contract */
constructor () public { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() public payable { if (msg.sender == owner) selfdestruct(owner); }
}
contract KlaytnGreeter 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;
}
}
Enter Klaytn's network information into truffle.js.
WARNING: Currently Klaytn Baobab network's gasPrice is fixed to 25 Gpeb (It returns an error if you attempt to use any other number).
$cd..$vitruffle-config.js
Modify configuration as below
// truffle-config.jsmodule.exports= { networks: { klaytn: { host:'127.0.0.1', port:8551, from:'0x75a59b94889a05c03c66c3c84e9d2f8308ca4abd',// enter your account address network_id:'1001',// Baobab network id gas:20000000,// transaction gas limit gasPrice:25000000000,// gasPrice of Baobab is 25 Gpeb }, }, compilers: { solc: { version:"0.5.6"// Specify compiler's version to 0.5.6 } }};
Deploy the contract using the following command.
NOTE: Use --network to select which network to deploy and --reset to overwrite.
NOTE: Make sure that your Klaytn node is running.
Your contract address is displayed followed `KlaytnGreeter:
$truffledeploy--networkklaytn--resetUsingnetwork'klaytn'.Runningmigration:1_initial_migration.jsDeployingMigrations......0x0f5108bd9e51fe6bf71dfc472577e3f55519e0b5d140a99bf65faf26830acfcaMigrations:0x97b1b3735c8f2326a262dbbe6c574a8ea1ba0b7dDeployingKlaytnGreeter......0xcba53b6090cb4a118359b27293ba95116a8f35f66ae50fbd23ae1081ce9ffb9eKlaytnGreeter: [SAVE THISADDRESS!!]# this is your smart contract addressSavingsuccessfulmigrationtonetwork......0x14eb68727ca5a0ac767441c9b7ab077336f9311f71e9854d42c617aebceeec72Savingartifacts...
WARNING: It returns an error when your account is locked.