Writing data into a smart contract
Reading data from a smart contract does not modify the state, while writing data into the contract modifies it. State changing methods can be called only by a transaction and with enough gas for execution. The state will be changed if the transaction satisfies all the conditions placed in the contract method.
In this recipe, you will learn how to interact with the contract using state changing methods.
Getting ready
Ensure that your Ethereum node is running. You can also use Ganache to create a development node.
How to do it...
For writing data to smart contracts, we have to follow this procedure:
- Consider the following example contract:
pragma solidity ^0.4.21; contract HelloWorld { // State variable string textToPrint = "hello world"; // State changing function function changeText(string _text) public { textToPrint = _text; } // Read-only function function printSomething() public view returns (string) { return textToPrint...