Smart Contract Execution
TxTypeSmartContractExecution executes a smart contract with the given data. TxTypeSmartContractExecution is accepted only if "to" is a smart contract account.
Import the ethers and @kaiachain/ethers-ext modules to add kaia features on ethers.js.
Define sender and fee payer addresses and private keys
Set up the provider with the specified kairos testnet URL. A provider in ethers is a read-only abstraction to access the blockchain data.
Also, you can change the provider URL from kairos to quicknode
Create a sender's wallet using the sender's private key and the provider
Create a fee payer's wallet using the sender's private key and the provider
Set the contract address you want to execute into the to field and set ABI
Create a contract instance with ethers.Contract, fill in params contractAddr, abi, provider. You can read and write the contract through this instance
Encode the function name and parameter with the encodeFunctionData function
Build the transaction object with type FeeDelegatedSmartContractExecution
Populate the transaction with necessary details
Sign the transaction by the sender's wallet
Send the transaction to blockchain using fee payer's wallet. Function sendTransactionAsFeePayer
adds a signature with FeePayer’s private key to the sender’s signature and transmits it to the blockchain network.
The wait function returns the tx receipt if the tx was sent to the blockchain successfully.