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

Legacy Account Key

AccountKeyLegacy

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

定义发件人地址私人密钥

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

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

私钥提供者创建发件人钱包

key 字段中声明一个交易,其值为 "AccountKeyType.Legacy`"。

向区块链发送 tx。 函数 "sendTransaction "使用账户的私钥进行内部签名,然后将其传输到区块链网络。

如果已在区块链中完成发送,wait函数将返回发送回执。

AccountUpdateWithLegacy.js

const { ethers } = require("ethers");
const { Wallet, TxType, AccountKeyType} = require("@kaiachain/ethers-ext/v6");
// Using legacy AccountKey to execute this example repeatedly.
// But you might want to register a different Accountkey.
const senderAddr = "0xecbf243ac167a3b5097fef758e07881582a89027";
const senderPriv = "0xc696ccd259792f2ffb87e0012e4a37ae3526a3224686225af679e3aaa2aeab0d";
const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet(senderPriv, provider);
async function main() {
const tx = {
type: TxType.AccountUpdate,
from: senderAddr,
key: {
type: AccountKeyType.Legacy,
}
};
const sentTx = await wallet.sendTransaction(tx);
console.log("sentTx", sentTx.hash);
const receipt = await sentTx.wait();
console.log("receipt", receipt);
}
main().catch(console.error);

output

❯ js AccountUpdateWithLegacy.js
pub 0x026e63942bece2c9c346fba11c493dc0d7ae0ab14b7b75c6d988619228cbb4e996
sentTx 0x5fedabfb343f607fe0f0adfa9ef54d738312bbec98bfc02839cdae2e968f5f90
receipt {
to: '0x24e8eFD18D65bCb6b3Ba15a4698c0b0d69d13fF7',
from: '0x24e8eFD18D65bCb6b3Ba15a4698c0b0d69d13fF7',
contractAddress: null,
transactionIndex: 0,
gasUsed: BigNumber { _hex: '0xa028', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x114a80bfaf346ff14fc818f5053a6a94201684fc02316529d5d2cfdb68e7b98d',
transactionHash: '0x5fedabfb343f607fe0f0adfa9ef54d738312bbec98bfc02839cdae2e968f5f90',
logs: [],
blockNumber: 152203338,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0xa028', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

让这个页面变得更好