Write
You can make a "transaction" interacting with a Smart Contract when you need to update some state in the contract.
Import the @kaiachain/ethers-ext modules to add kaia features on web3.
Initializes a public client for read-only interactions with the Kaia blockchain.
Set up a wallet client using createWalletClient, configured with the Kairos chain, an HTTP transport, and the sender’s private key converted to an account.
Set the Abi generated from solidity code
Define contract address to interact with
The writeContract
method is used to call the setNumber function on the contract, passing Date.now() (the current timestamp in milliseconds) as the argument. This creates and sends a transaction to update the contract’s number variable.
Uses the public client to query the number function (a view function that doesn’t modify state) from the contract. This retrieves the current value of the number variable, which should reflect the timestamp set by the previous transaction (if successful).