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

Value Transfer

TxTypeValueTransfer 用于用户发送 KAIA。

  • 由于 kaia 提供了多种交易类型,使每种交易类型只服务于一个目的,因此 TxTypeValueTransfer 只限于将 KAIA 发送到外部拥有的账户(EOA)。

Fee Delegation

导入 ethers@kaiachain/ethers-ext 软件包,在 ethers.js 上添加 kaia 功能

定义发件人地址、发件人私钥和收件人地址

使用指定的 kairos 测试网 URL 设置提供程序。 以太坊中的提供者是访问区块链数据的只读抽象。

此外,您还可以将提供商 URL 从 kairos 更改为 quicknode

用私钥创建寄件人和付费人钱包。

用 ** 类型、来自、至、值** 等字段声明事务。

使用senderWallet.populateTransaction为交易填充附加信息

发送方的私人密钥签署交易

使用付费者的钱包将交易发送到区块链上。 函数 "sendTransactionAsFeePayer "会在发送者的签名上添加一个带有 FeePayer 私钥的签名,并将其传输到区块链网络。

等待交易收据。

TxTypeFeeDelegatedValueTransfer.js

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const ethers = require("ethers");
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const feePayerAddr = "0xcb0eb737dfda52756495a5e08a9b37aab3b271da";
const feePayerPriv = "0x9435261ed483b6efa3886d6ad9f64c12078a0e28d8d80715c773e16fc000cff4";
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";
async function main() {
const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const senderWallet = new Wallet(senderPriv, provider);
const feePayerWallet = new Wallet(feePayerPriv, provider);
let tx = {
type: TxType.FeeDelegatedValueTransfer,
to: recieverAddr,
value: parseKlay("0.01"),
from: senderAddr,
};
tx = await senderWallet.populateTransaction(tx);
console.log(tx);
const senderTxHashRLP = await senderWallet.signTransaction(tx);
console.log("senderTxHashRLP", senderTxHashRLP);
const sentTx = await feePayerWallet.sendTransactionAsFeePayer(senderTxHashRLP);
console.log("sentTx", sentTx);
const rc = await sentTx.wait();
console.log("receipt", rc);
}
main();

output

❯ node TxTypeFeeDelegatedValueTransfer.js
senderTxHashRLP 0x09f8878203ab850ba43b740082cd1494c40b6909eb7085590e1c26cb3becc25368e249e9872386f26fc1000094a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f6a06b4fdf5a4769285549e3bdfec4ba6db98f3439e8a148df1f55b7387a7c207947a0705b7c07749ab7aadab88a6e412a66f1985d821d56104b75d5a5ee6c03924e42
sentTx 0xbd5ca6525bc3364b68846b314e5d621333dd7df4054cbb76f67e5ea9c2aaef33
receipt {
to: '0xC40B6909EB7085590E1c26Cb3beCC25368e249E9',
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
contractAddress: null,
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0x7918', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0xfa10dadd1783e0fa65729336cd14bc8197ae0e15c3e42c3cc505b9fce85ebcac',
transactionHash: '0xbd5ca6525bc3364b68846b314e5d621333dd7df4054cbb76f67e5ea9c2aaef33',
logs: [],
blockNumber: 148722215,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x034b1d', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

让这个页面变得更好