跳至主要内容
本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)

Legacy

TxTypeLegacyTransaction represents a type of transactions existed previously in kaia.

This type of transaction can create an account, transfer tokens, deploy a smart contract, execute a smart contract, or perform a mix of aforementioned.

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

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.

Create a transaction request for a legacy value transfer using prepareTransactionRequest, specifying the recipient address and the value to transfer (0 in this example).

Sign and send the legacy transaction to the Kaia blockchain using the wallet client’s sendTransaction method, and log the transaction hash.

txTypeLegacyTransaction.js

import { createWalletClient, http, kairos, privateKeyToAccount } from "@kaiachain/viem-ext";
const legacyWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount(
"0x28d06bfebe5447d798ec7d1f208a045a15a1d6872b2a3cbb74cc896817bbb90d"
),
});
(async () => {
// legacy tx
const legacyRequest = await legacyWallet.prepareTransactionRequest({
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
value: 0,
});
console.log("populated legacy request", legacyRequest);
const sentLegacyTx = await legacyWallet.sendTransaction(legacyRequest);
console.log("value transfer legacy tx", sentLegacyTx);
})();

output

❯ node txTypeLegacyTransaction.js
populated legacy request {
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: 0,
from: '0x7642e9D6F533DCd6F4c20EF7bA83141b6b210d83',
nonce: 18,
chainId: 1001,
type: 'eip1559',
maxPriorityFeePerGas: 0n,
maxFeePerGas: 30000000000n,
gas: 21000n
}
value transfer legacy tx 0x8da12ab374d592715df3bbf6cc96f11a836175daf0dec7f26295d172d6206056

让这个页面变得更好