-
Notifications
You must be signed in to change notification settings - Fork 4
Module 4 Adding functionality
yeousunn edited this page Aug 24, 2018
·
2 revisions
Smart contracts can have functions that can perform tasks based on user calls on the blockchain. Edit the HelloWorld smart contract as follows:-
pragma solidity ^0.4.22;
contract HelloWorld {
string helloMsg;
constructor() {
helloMsg = "Hello World!!!";
}
function getHelloMsg() returns (string){
return helloMsg;
}
function setHelloMsg(string _helloMsg) returns (bool success){
helloMsg = _helloMsg;
return true;
}
}
On terminal run the following command to compile the smart contract:-
truffle compile
Once it is compiled, migrate the new smart contract to the blockchain:-
truffle migrate --network usc --reset
Connect to truffle console:-
truffle console --network usc
To call getHelloMsg function, type the following command on truffle console:-
HelloWorld.deployed().then(function(d){return d.getHelloMsg.call();});
To set new message call setHelloMsg function:-
HelloWorld.deployed().then(function(d){return d.setHelloMsg("Hello!!!");});