Contract interaction can be accessed, as with any other contract action, by clicking the respective button - Interact - located at the editor top bar (the mouse icon). Alternatively, the Interact action is also available in the Files hierarchy, under the contract name in contracts directory. The latter will open the Interact mode in a new window instead of splitting up the current window in the main area.
Interaction is only available after a given contract has been deployed. The address of the deployed contract is a requirement for interacting with it. When trying to access Interact mode without having the contract deployed, the following message will appear in the Interact window:
"Missing file(s), contract not deployed?" (or, when the Browser network is selected, "Contract does not exist.")
Taking the Hello World template as an example, deploy the HelloWorld.sol contract by clicking the Deploy button at the editor top bar (the play icon). After the deployment process finishes with a successful message, stating that work has been "Done", the Interact mode will be available.
The interaction window is divided into two main sections: instructions and operations.
The instructions section shares relevant information about what is available and explains the legend of colors, as follows:
- Constant (green color): a constant function which runs outside of a transaction and can return one or many values. Running it does not consume any gas nor can it mutate the state of the contract.
- Transaction (yellow color): a function which always runs inside a transaction. It consumes gas and doesn't allow any ether to be sent with it. A transaction always returns a transaction hash. In order to retrieve the transaction status, it is necessary to read the transaction receipt.
- Payable (red color): a payable function which always runs inside a transaction. It consumes gas and allows ether to be sent along with it. A transaction always returns a transaction hash. In order to retrieve the transaction status, it is necessary to read the transaction receipt.
The second section in the interaction window lists all publicly available operations for a given contract. The data is auto-generated, based on the contract source file. For each operation, there will be a list of input arguments, when the function signature contains such element, and the gas specification parameters (limit and price in Wei). Leaving the gas specification parameters empty, as is, will set the values to suggested configuration defaults.
Clicking the yellow or red button, named after the contract function signature, sends the transaction using the parameters defined in the previous steps, taking into consideration the selected network and account. At the end, after the transaction has been sent, a subsection titled Returns will output the resulting transaction hash.
When deploying to an external network, it is required to use an external provider. The MetaMask browser extension is supported.
As an example, following the Hello World template, set the network to Rinkeby by clicking the Select a Network button located at the top left side of the screen. After having deployed the contract to Rinkeby, sending a transaction requires transaction signature, which is handled by the external provider. Clicking the yellow or red button will call the external provider to confirm, sign and submit the transaction, passing control back to Superblocks Lab at the end of the process. After the external provider finishes intermediation, interacting with the contract works in the same manner as with any other network.
Following the publicly available operations, there can also appear a list of publicly available data and read-only operations, which don't require a transaction to execute. The data for this is also auto-generated, based on the contract source file. For each available operation, there will be a list of input arguments, when the function signature contains such element, followed by a green button named after the contract data or function name.
Below is a list of common errors that occur when trying to send a transaction to interact with a contract using an external provider: