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

パブリック・アカウント・キー

AccountKeyPublicは、1つの公開鍵を持つアカウントに使用される。 アカウントにAccountKeyPublicオブジェクトがある場合、トランザクションの検証処理は以下のように行われる:

@kaiachain/web3js-ext パッケージをインポートして、Web3にKAIAの機能を追加します。

変更する送信者address、送信者private key新しい秘密鍵を定義する。

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

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

プロバイダーを使ってweb3インスタンスを定義する

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

新しい秘密鍵からpublic keyを計算する。

型がAccountKeyType.Publicで、keyフィールドに新しい計算されたpublic keyを持つトランザクションを宣言する。

送信者の財布で取引に署名する。

署名されたTxをブロックチェーンに送信する。 トランザクションのレシートを返す。

AccountUpdateWithPubKey.js

const { Web3, TxType, AccountKeyType, toPeb, getPublicKeyFromPrivate } = require("@kaiachain/web3js-ext");
// Using senderPriv == senderNewPriv to execute this example repeatedly.
// But you might want to register a different private key.
const senderAddr = "0xfb60ded0ae96fe04eed6450aead860aa9d57128e";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const senderNewPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new Web3.providers.HttpProvider("https://public-en-kairos.node.kaia.io");
const web3 = new Web3(provider);
const senderAccount = web3.eth.accounts.privateKeyToAccount(senderPriv);
async function main() {
const senderNewPub = getPublicKeyFromPrivate(senderNewPriv);
console.log({ senderNewPub });
const tx = {
type: TxType.AccountUpdate,
from: senderAddr,
key: {
type: AccountKeyType.Public,
key: senderNewPub,
}
};
const signResult = await senderAccount.signTransaction(tx);
console.log("signedTx", signResult.transactionHash);
const receipt = await web3.eth.sendSignedTransaction(signResult.rawTransaction);
console.log("receipt", receipt);
}
main().catch(console.error);

output

❯ js AccountUpdateWithPubKey.js
pub 0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
sentTx 0x33a634875a49d8915bc6fde14f351b81d1fc470b64aef28bf95d3ea92f2dc4f7
receipt {
to: '0xe15Cd70A41dfb05e7214004d7D054801b2a2f06b',
from: '0xe15Cd70A41dfb05e7214004d7D054801b2a2f06b',
contractAddress: null,
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0xa028', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0xb385b18c2e96c36e7fbbeb121cf2a48c0bb15f1a7af2f2969b133236ff7a14ea',
transactionHash: '0x33a634875a49d8915bc6fde14f351b81d1fc470b64aef28bf95d3ea92f2dc4f7',
logs: [],
blockNumber: 152203491,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x02e456', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

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