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 web3 and @kaiachain/web3js-ext packages to add kaia features on web3
Define sender address and sender private key
Define contract address and Abi, you can retreive it from block explorer and compiled solidity code
Set up the provider with the specified kairos testnet URL. A provider in web3js is a read-only abstraction to access the blockchain data.
Also, you can change the provider URL from kairos to quicknode
Create a KlaytnWeb3 instance using the provider
Convert the sender's private key to an account using web3.eth.accounts.privateKeyToAccount
Create a contract instance using Web3.eth.Contract
with defined contractAbi and address. You can read and write the contract through this instance
Encode the function data for the "setNumber" function to convert the data to bytes
Define a transaction object for the contract execution, params type: TxType.SmartContractExecution
, from: senderAddr
, to: contractAddr
, data: data
are required
Sign the transaction with the sender's private key
Send the signed transaction to blockchain. It will return the transaction receipt