Smart Contract #2 - Hello World Part 2 - Change memory

In this smart contract, you will update the smart contract contract memory and synchronize all nodes to have the same contract memory.

Video

The video provides some context about the Smart Contract #2 and shows you how you can run the sample application.

SC_2_GCP

Steps

In a terminal session, trigger a smart contract:

tymlez-sc publish --templateName=SC_HelloWorld_Part2 Hello

If the contract is successfully published, the system will return a valid contract ID:

[INFO] commands.publish - publishing contract SC_HelloWorld_Part2....
[INFO] commands.publish - Signed tx...
[INFO] commands.publish - Post signed tx ....
[INFO] commands.publish - Smart Contract published successfully
[INFO] commands.publish - Contract id: e4897b7a1cb6055bba7fd66c75cbb5f12420f1198938db20b8e3ef5ebe304f9

Now, read the smart contract memory by executing the getGreeting function:

tymlez-sc call --functionName=getGreeting

The memory will then be returned:

[INFO] commands.call - { result: 'Hello' }

Now, update the smart contract memory with the function changeGreeting:

tymlez-sc call --functionName=changeGreeting "HelloWorld"

The value of the smart contract has now been updated.

[INFO] commands.call - contract ID: ce4897b7a1cb6055bba7fd66c75cbb5f12420f1198938db20b8e3ef5ebe304f9
[INFO] commands.call - Signed tx...
[INFO] commands.call - Post signed tx ....
[INFO] commands.call - Smart Contract updated !!!

Verify if the memory has been updated:

tymlez-sc call --functionName=getGreeting

You should now see the updated smart contract memory:

[INFO] commands.call - { result: 'HelloWorld' }

Return to the smart contracts main page