http, encodeFunctionData, createWalletClient,
createPublicClient, kairos, TxType, privateKeyToAccount
} from "@kaiachain/viem-ext";
const publicClient = createPublicClient({
const senderWallet = createWalletClient({
account: privateKeyToAccount(
"0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"
const feePayerWallet = createWalletClient({
account: privateKeyToAccount(
"0x9435261ed483b6efa3886d6ad9f64c12078a0e28d8d80715c773e16fc000cff4"
const contractAddr = "0x95Be48607498109030592C08aDC9577c7C2dD505";
const abi = [{ "inputs": [{ "internalType": "uint256", "name": "initNumber", "type": "uint256" }], "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint256", "name": "number", "type": "uint256" }], "name": "SetNumber", "type": "event" }, { "inputs": [], "name": "increment", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "number", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "newNumber", "type": "uint256" }], "name": "setNumber", "outputs": [], "stateMutability": "nonpayable", "type": "function" }];
const data = encodeFunctionData({
functionName: "setNumber",
const tx = await senderWallet.prepareTransactionRequest({
type: TxType.SmartContractExecution,
account: senderWallet.account,
console.log("preparedTx", tx);
const signedTx = await senderWallet.signTransaction(tx);
const sentTx = await senderWallet.request({
method: "klay_sendRawTransaction",
console.log("contract interaction tx", sentTx);
const tx2 = await senderWallet.prepareTransactionRequest({
type: TxType.FeeDelegatedSmartContractExecution,
account: senderWallet.account,
const signedTx2 = await senderWallet.signTransaction(tx2);
const feePayerSignedTx = await feePayerWallet.signTransactionAsFeePayer(
const sentFeePayerTx = await feePayerWallet.request({
method: "klay_sendRawTransaction",
params: [feePayerSignedTx],
console.log("fee payer contract execution tx", sentFeePayerTx);
const result = await publicClient.readContract({
console.log('Current contract value', result);