跳至主要內容

Cancel

TxTypeCancel cancels the execution of the transaction with the same nonce in the transaction pool. This transaction type is useful when a submitted transaction seems unprocessed for a certain amount of time.

Fee Delegation

Import the @kaiachain/viem-ext packages to add kaia features on web3

Set up sender and fee payer wallets using createWalletClient, configured with the Kairos chain, an HTTP transport, and the sender’s private key converted to an account.

Create a transaction request for a value transfer using prepareTransactionRequest, specifying the sender’s account and transaction type (TxType.FeeDelegatedCancel).

Signing the transaction with the wallet client’s signTransaction method, and log the transaction hash.

The fee payer signs the already-signed transaction from the sender with function signTransactionAsFeePayer, agreeing to pay the transaction fees.

Sends the fully signed, fee-delegated transaction (signed by both sender and fee payer) to the Kairos blockchain network using the kaia_sendRawTransaction method, returning the transaction hash or response from the network.

TxFeeDelegatedCancelType.js

import { createWalletClient, http, kairos, privateKeyToAccount, TxType } from "@kaiachain/viem-ext";
const senderWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount(
"0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"
),
})
const feePayerWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount(
"0x9435261ed483b6efa3886d6ad9f64c12078a0e28d8d80715c773e16fc000cff4"
),
});
(async () => {
const txRequest = await senderWallet.prepareTransactionRequest({
account: senderWallet.account,
type: TxType.FeeDelegatedCancel,
});
const signedTx = await senderWallet.signTransaction(txRequest);
console.log("signedTx", signedTx);
const feePayerSignedTx = await feePayerWallet.signTransactionAsFeePayer(
signedTx
);
const res = await feePayerWallet.request({
method: "kaia_sendRawTransaction",
params: [feePayerSignedTx],
});
console.log("fee delegated cancel tx", res);
})();

output

❯ js TxFeeDelegatedCancelType.js
signedTx 0x39f86b82095e85066720b3008302059494a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f6a0e203205f0f0728d964f8da4a8f891b63d2140c9a0144d33a9a682be1db90c212a05a3999602aeefda3cabbf0af3a935b85a9c5e94ffa3c00c8def218a121281343
fee delegated cancel tx 0x4580d6e7599fe0b2623f9942cb0b167449c764e49f40b7a63b15c8ff60053923

讓這個頁面變得更好