본문으로 건너뛰기
이 페이지는 영문에서 기계 번역되었으므로 오역이나 어색한 표현이 있을 수 있습니다. 따라서 정확한 정보는 영어 원문을 참조하시기 바랍니다. 또한 잦은 업데이트로 인해 일부 콘텐츠는 영문이 그대로 남아있을 수 있습니다. Crowdin에서 이 페이지의 번역을 개선하는 데 동참하여 도움을 주세요. (Crowdin translation page, Contributing guide)

Account Update

Import the ethers and @kaiachain/viem-ext packages to add kaia features on web3

Specify the kairos chain configuration to connect to the Kaia Kairos testnet.

Set up a wallet client using createWalletClient, configured with the Kairos chain, an HTTP transport, and the sender’s private key converted to an account.

Generate the public key from the sender’s private key using ethers.SigningKey.computePublicKey. The true parameter ensures the key is compressed.

Create a transaction request for the account update using prepareTransactionRequest, specifying the transaction type, sender account, recipient address, and the new public key.

Sign the prepared transaction using the wallet client’s signTransaction method.

Send the signed transaction to the Kaia blockchain using the kaia_sendRawTransaction method and log the transaction hash.

TxTypeAccountUpdate.js

import { AccountKeyType, createWalletClient, http, privateKeyToAccount, TxType } from "@kaiachain/viem-ext";
import { ethers } from "ethers";
import { kairos } from "viem/chains";
const senderWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8")
});
async function main() {
const pub = ethers.SigningKey.computePublicKey("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8", true);
const txRequest = await senderWallet.prepareTransactionRequest({
account: senderWallet.account,
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
type: TxType.AccountUpdate,
key: {
type: AccountKeyType.Public,
key: pub,
},
});
console.log("populated tx request", txRequest);
const signedTx = await senderWallet.signTransaction(txRequest);
const sentTx = await senderWallet.request({
method: "kaia_sendRawTransaction",
params: [signedTx],
});
console.log("account update tx", sentTx);
};
main();

output

❯ js TxTypeAccountUpdate.js
populated tx request {
account: {
address: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonceManager: undefined,
sign: [AsyncFunction: sign],
signAuthorization: [AsyncFunction: signAuthorization],
signMessage: [AsyncFunction: signMessage],
signTransaction: [AsyncFunction: signTransaction],
signTypedData: [AsyncFunction: signTypedData],
source: 'privateKey',
type: 'local',
publicKey: '0x04dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cdaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79'
},
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
type: 32,
key: {
type: 2,
key: '0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd'
},
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonce: 2373,
chainId: 1001,
gas: 21000n,
gasPrice: '0x66720b300',
gasLimit: 52500
}
account update tx 0x169287cafab3bfdf9ed513f0a872517f338a796725df16e7e758bb17149f4127

페이지를 개선해 주세요