Interact with already published smart contracts
In this section we will use Remix to call the functions we defined in our Smart Contract
Last updated
In this section we will use Remix to call the functions we defined in our Smart Contract
Last updated
Now that we have deployed our smart contract, we will want to actually run the functions that we defined in our Register.sol smart contract outlined in Create, compile and publish your first smart contract
We will first navigate to the Deploy & Run Transactions section of the the Remix IDE where we have our Pinned Smart Contract that we deployed.
We see two buttons that have names that correspond to functions we have defined in our Register smart contract. The first being the getInfo function:
And the setInfo button
We will explain why these buttons have different colours soon.
The Contract Application Binary Interface (ABI) is the standard way to interact with contracts in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interaction. Data is encoded according to its type, as described in this specification. The encoding is not self describing and thus requires a schema in order to decode.
When we select the buttons on the left side of the IDE we are executing the functions of our Register contract that was deployed to the blockchain. The IDE knows this since it has both the functional definitions (known as Application Binary Interfaces [ABI]) that we got from compiling the code (and now exists in the JSON files in our workspace), and the Address that the smart contract was deployed to that we found on etherscan.
We can click the button labeled getInfo to fetch the default value of our info variable that we defined in the contract (note, that since it has no default value the return from the contract should be an empty string "").
If we want to set this value to something specific, we need to use the setInfo method. Using the other button and the text box you can set the string to whatever you would like. I will use "Smart Contracts are fun!". Since this function initiates a state change, you will be required to pay the gas fee to the blockchain in the same way we paid to deploy the contract. Also, because this interaction costs gas and changes the data stored on the blockchain, it is marked as an orange button! Blue buttons do not change the data stored on a chain -- they're "read only" interactions. When we change data on a blockchain (or a hard disk!) we are "writing" data to the storage service.
After confirming the transaction, you will receive another update in the terminal window of Remix indicating the status of the transaction, this time specifically for the Register.setInfo state change.
Now if we return to our getInfo button and click it, Remix will "read" the latest data from the blockchain. We will see that value held in the variable info has changed to be the string that we specified in the setInfo method. Congrats! You've made an immutable change to the blockchain ledger!