本文へスキップ
このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。Crowdinでの取り組みに参加して、このページの翻訳改善にご協力ください。 (Crowdin translation page, Contributing guide)

レガシー・アカウント・キー

AccountKeyLegacy

ethers.jsにkaiaの機能を追加するために、ethersおよび @kaiachain/ethers-extパッケージをインポートする。

送信者のaddressprivate keyを定義する。

指定されたkairos testnet URLでプロバイダを設定します。 エーテルにおけるプロバイダーとは、ブロックチェーンのデータにアクセスするための読み取り専用の抽象化されたものである。

また、プロバイダのURLをkairosからquicknodeに変更することができます。

private keyプロバイダーを使って送信者のウォレットを作成する。

keyフィールドに AccountKeyType.Legacy という値でトランザクションを宣言する。

ブロックチェーンに送信する。 関数 sendTransaction は内部的にアカウントの秘密鍵で署名し、ブロックチェーンネットワークに送信する。

wait関数は、ブロックチェーン上でtx受信が完了すれば、それを返す。

AccountUpdateWithLegacy.js

const { ethers } = require("ethers");
const { Wallet, TxType, AccountKeyType} = require("@kaiachain/ethers-ext/v5");
// 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.providers.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
}

ページを改善してください。