Custom Contract Interaction
Demonstrate how to execute contract calls using Etherspot SDK
Before we continue, please ensure that you have had a look at our Supported Ethereum Chains, followed the steps in Install Etherspot SDK and how to Bootstrap Etherspot SDK. We're assuming that you have completed these steps before going forward.
In this article, we are going to generically explain how to call a contract method using Etherspot SDK. For better Understanding, we will consider stake method to be called from a staking contract.
Before we continue...
Take the contract address and its abi which is available on the respective chain's block explorer and initialise the sdk on the chain where the contract address was found. For this demostration we will consider Klima DAO as an example which is found in Matic Chain.
Create Contract Interface using Etherspot SDK
Next, we are going to call registerContract function on the Etherspot SDK to register the contract details and encode the parameters required for the contract method. You can find the required parameters inside the abi on the name of the function.
After we get the transaction details (stakeTransactionRequest), the data is passed into Etherspot SDK in order to execute the transaction.
Adding your transaction to a batch
When using Etherspot to send transactions, we first add the transaction to a "batch". A batch can contain many transactions for a more gas-efficient operation, but in this example - we're just going to add one transaction to the batch. It will behave as if we are just sending a single transaction.
To see the full SDK reference for the batchExecuteAccountTransaction
, click here.
Estimating your batch
At this point, your batch is ready to have the gas cost estimated. This gives you, or your users, the opportunity to see how much this transaction may cost on the chain that you have instantiated the SDK on. You can read more about instantiating the Etherspot SDK on different chains here:Supported Ethereum Chains.
If you're happy with the cost, proceed to the next and final step.
Submitting your batch
The final step is to submit your batch, containing your one or more transactions, to the Etherspot gateway. The Etherspot gateway will queue and manage your batch, and endeavour to do everything it can to get your transaction onto your chosen blockchain.
If you had previously set up a notification subscription here, then this will fire with different events as your batch is queued, processed and eventually sent to the blockchain.
Last updated