Nhảy tới nội dung
This page uses machine translation from English, which may contain errors or unclear language. For the most accurate information, please see the original English version. Some content may be in the original English due to frequent updates. Help us improve this page's translation by joining our effort on Crowdin. (Crowdin translation page, Contributing guide)

Hủy bỏ

TxTypeCancel hủy việc thực hiện giao dịch với cùng nonce trong nhóm giao dịch. Loại giao dịch này hữu ích khi một giao dịch đã gửi có vẻ như chưa được xử lý trong một khoảng thời gian nhất định.

Nhập các gói @kaiachain/viem-ext để thêm các tính năng kaia trên web3

Chỉ định cấu hình chuỗi kairos để kết nối với mạng thử nghiệm Kaia Kairos.

Thiết lập ứng dụng ví bằng createWalletClient, được cấu hình bằng chuỗi Kairos, phương thức truyền tải HTTPkhóa riêng của người gửi được chuyển đổi thành tài khoản.

Tạo yêu cầu giao dịch cho hủy giao dịch bằng cách sử dụng prepareTransactionRequest, chỉ định loại giao dịch và tài khoản người gửi.

Ký và gửi giao dịch hủy đến blockchain Kaia bằng phương thức sendTransaction của ứng dụng ví và ghi lại mã băm giao dịch.

TxCancelType.js

import { createWalletClient, http, privateKeyToAccount, TxType } from "@kaiachain/viem-ext";
import { kairos } from "viem/chains";
const senderWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount(
"0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"
),
});
// Example usage
(async () => {
const txRequest = await senderWallet.prepareTransactionRequest({
account: senderWallet.account,
type: TxType.Cancel,
});
console.log("txRequest", txRequest);
const sentTx = await senderWallet.sendTransaction(txRequest);
console.log("Cancel tx", sentTx);
})();

output

❯ node TxCancelType.js
txRequest {
account: {
address: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonceManager: undefined,
sign: [AsyncFunction: sign],
signAuthorization: [AsyncFunction: signAuthorization],
signMessage: [AsyncFunction: signMessage],
signTransaction: [AsyncFunction: signTransaction],
signTypedData: [AsyncFunction: signTypedData],
source: 'privateKey',
type: 'local',
publicKey: '0x04dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cdaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79'
},
type: 56,
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonce: 2385,
chainId: 1001,
gas: 53000n,
gasPrice: '0x66720b300',
gasLimit: 132500
}
Cancel tx 0x1bc6db276a8bc2395fcbcd3efd96afba7cf4b5cbcfd18f6bdde541d04838d065

Cải thiện trang này