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

役割ベースのアカウント・キー

AccountKeyRoleBasedはロールベースのキーを表す。 アカウントにAccountKeyRoleBasedオブジェクトがあり、トランザクションタイプがアカウント更新を除くものである場合、以下のようにそれぞれのロールに応じたバリデーション処理が行われます:

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

送信者のaddress、送信者のprivate key、および変更する新しいrole-based private keyを定義する。

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

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

送信者のウォレットを、更新者ロールの秘密鍵とプロバイダーで作成する。

新しい役割ベースの秘密鍵からpublic keyを計算する。

計算されたrole-based public keykeysフィールドにトランザクションを宣言する。

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

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

AccountUpdateWithRoleBased.js

const { ethers } = require("ethers");
const { Wallet, TxType, AccountKeyType } = require("@kaiachain/ethers-ext/v5");
// Using senderPriv == senderRoleAccountUpdatePriv to execute this example repeatedly.
// But you might want to register a different private key.
const senderAddr = "0x5bd2fb3c21564c023a4a735935a2b7a238c4ccea";
const senderPriv = "0x9ba8cb8f60044058a9e6f815c5c42d3a216f47044c61a1750b6d29ddc7f34bda";
const senderRoleTransactionPriv = "0xc9668ccd35fc20587aa37a48838b48ccc13cf14dd74c8999dd6a480212d5f7ac";
const senderRoleAccountUpdatePriv = "0x9ba8cb8f60044058a9e6f815c5c42d3a216f47044c61a1750b6d29ddc7f34bda";
const senderRoleFeePayerPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new ethers.providers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const updaterWallet = new Wallet(senderAddr, senderRoleAccountUpdatePriv, provider);
async function main() {
const pub1 = ethers.utils.computePublicKey(senderRoleTransactionPriv, true);
const pub2 = ethers.utils.computePublicKey(senderRoleAccountUpdatePriv, true);
const pub3 = ethers.utils.computePublicKey(senderRoleFeePayerPriv, true);
console.log({ pub1, pub2, pub3 });
const tx = {
type: TxType.AccountUpdate,
from: senderAddr,
gasLimit: 1000000,
key: {
type: AccountKeyType.RoleBased,
keys: [
{ type: AccountKeyType.Public, key: pub1 }, // RoleTransaction
{ type: AccountKeyType.Public, key: pub2 }, // RoleAccountUpdate
{ type: AccountKeyType.Public, key: pub3 }, // RoleFeePayer
]
}
};
const sentTx = await updaterWallet.sendTransaction(tx);
console.log("sentTx", sentTx.hash);
const receipt = await sentTx.wait();
console.log("receipt", receipt);
}
main().catch(console.error);

output

❯ js AccountUpdateWithRoleBased.js
{
pub1: '0x03f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2a',
pub2: '0x0263021199702b9fefca617bdcb2a9ed4a810dfa8d270d4e804a1e778450e63ec3',
pub3: '0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd'
}
sentTx 0xcb8e1fc03088f2a00d44c31ce1c5f4913d3cf11403d60014a245ae44aa4c2a2f
receipt {
to: '0x5bD2fb3c21564C023A4A735935a2B7A238C4cCEA',
from: '0x5bD2fb3c21564C023A4A735935a2B7A238C4cCEA',
contractAddress: null,
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0x013c68', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0xb9145a53ef85bc4b375de828d9c3387cadc6bcd8f81a8d8eaf4f0331a2d7a5c0',
transactionHash: '0xcb8e1fc03088f2a00d44c31ce1c5f4913d3cf11403d60014a245ae44aa4c2a2f',
logs: [],
blockNumber: 152203576,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x0377d6', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

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