跳至主要內容
本頁面使用機器翻譯自英語,可能包含錯誤或不清楚的語言。如需最準確的信息,請參閱英文原文。由於更新頻繁,部分內容可能與英文原文有出入。請加入我們在 Crowdin 上的努力,幫助我們改進本頁面的翻譯。 (Crowdin translation page, Contributing guide)

Value Transfer Memo

TxTypeValueTransferMemo 用於用戶發送帶有特定信息的 KAIA。

Fee Delegation

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

定義發件人地址、發件人私人密鑰、繳費人地址、繳費人私人密鑰和收件人地址

使用指定的 kairos 測試網 URL 設置提供程序。 以太坊中的提供者是訪問區塊鏈數據的只讀抽象。

此外,您還可以將提供商 URL 從 kairos 更改為 quicknode

用私人密鑰創建發件人錢包

用私人密鑰創建繳費人錢包

類型、來自、至、值、輸入等字段聲明事務。

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

發送方的私人密鑰簽署交易

使用付費者的錢包將交易發送到區塊鏈上。 函數 "sendTransactionAsFeePayer "會在發送者的簽名上添加一個帶有 FeePayer 私鑰的簽名,並將其傳輸到區塊鏈網絡。

如果 tx 已成功發送到區塊鏈,wait 函數將返回 tx 收據。

TxTypeFeeDelegatedValueTransferMemo.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.FeeDelegatedValueTransferMemo,
to: recieverAddr,
value: parseKlay("0.01"),
from: senderAddr,
input: "0x1234567890",
};
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 TxTypeFeeDelegatedValueTransferMemo.js
senderTxHashRLP 0x11f88d8203ac850ba43b740082d1f694c40b6909eb7085590e1c26cb3becc25368e249e9872386f26fc1000094a2a8854b1802d8cd5de631e690817c253d6a9153851234567890f847f8458207f5a0bf499bb98ac755430724cb9cf8deb3e2d43baa0f4dc97036d06bd66c91e74f2ca0092f32dbabd626964eeccfe7a1cfc0d14088ece28f7efde952c341428a531785
sentTx 0xac225ead53297c95b747abd84e7224ecbc1b40f459a532fd22a67143aa83b4ae
receipt {
to: '0xC40B6909EB7085590E1c26Cb3beCC25368e249E9',
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
contractAddress: null,
transactionIndex: 0,
gasUsed: BigNumber { _hex: '0x7b0c', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0xbc02b7afb16657cd1ec45bb6b7445767eb265702ae766dfc8bda3503f74d81a7',
transactionHash: '0xac225ead53297c95b747abd84e7224ecbc1b40f459a532fd22a67143aa83b4ae',
logs: [],
blockNumber: 148732018,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x7b0c', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

讓這個頁面變得更好