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

Public Account Key

AccountKeyPublic 用於有一個公鑰的賬戶。 如果賬戶有一個 AccountKeyPublic 對象,交易驗證過程如下:

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

定義要更改的發件人地址、發件人私人密鑰新私人密鑰

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

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

私鑰提供者創建發件人錢包

用新私鑰計算公鑰

聲明一個事務,其類型為 賬戶密鑰類型.公鑰密鑰字段為新計算的公鑰

向區塊鏈發送 tx。 函數 "sendTransaction "使用賬戶的私鑰進行內部簽名,然後將其傳輸到區塊鏈網絡。

如果已在區塊鏈中完成發送,wait函數將返回發送回執。

AccountUpdateWithPubKey.js

const { ethers } = require("ethers");
const { Wallet, TxType, AccountKeyType } = require("@kaiachain/ethers-ext/v6");
// Using senderPriv == senderNewPriv to execute this example repeatedly.
// But you should use AccountKeyPublic to register a different private key.
const senderAddr = "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const senderNewPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet(senderAddr, senderPriv, provider); // decoupled account
async function main() {
const senderNewPub = ethers.SigningKey.computePublicKey(senderNewPriv, true);
console.log("pub", senderNewPub);
const tx = {
type: TxType.AccountUpdate,
from: senderAddr,
key: {
type: AccountKeyType.Public,
key: senderNewPub,
}
};
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 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
}

讓這個頁面變得更好