⚡Execute Contracts
Explains how to execute smart contract functions.
Last updated
Explains how to execute smart contract functions.
Last updated
In the chapter before, we've described how to easily call read-only functions and fetch the results (read state from the contract).
Here, we'll show how you can use the SDK to request your users to execute any state changing function on the smart contract.
The flow you will use is as follows:
Create transaction request on a contract instance
Redirect the user to the link generated for this concrete transaction request
Wait for the user to complete the action and read result
As you can see, there's no complex wallet management or transaction status management included here. You just have to describe to the SDK what you'd like the user to execute, and we take care of the rest.
Before creating the transaction request, you must first obtain the alias of your contract by checking the Dev3 Dashboard.
Create the connection to the contract by initializing the SDK object first as explained in the Initialization section, and then providing the alias found on the dashboard (alias shown in the example above).
Once the connection to the smart contract has been obtained, simply create the transaction request by providing the function name and parameters as defined by the smart contract implementation. You can read the function name and what parameters the function accepts directly from the dashboard, on the contract details page, where you found the contract alias.
In the example above, we expanded the details of 'Mint' function, which is a state changing (write) function on the opened smart contract interface. The function name is highlighted on the right part of the image, and we can actually copy/paste it directly from the dashboard. The function parameters this function accepts are described on the left part, and we should provide the value for these in the SDK execution call. The code snippet to execute such an action will look like something below:
To see all the possibilities when calling more complex functions accepting different function parameters, please refer to the Function Parameters docs. (previous chapter)
Options object provided when building the action can contain the following:
All the fields are optional and can all be skipped by passing an empty object as the configuration. However, if you wish to use some (or all) of these, more detail is given in the options section.
Run this flow on a live coding environment here!
If you're getting the "You don't have enough gas to execute this transaction..." error, then please refer to our FAQ to resolve this issue in no time!