본문으로 건너뛰기

legacy

이 페이지는 영어로 된 기계 번역을 사용하므로 오류나 불명확한 언어가 포함될 수 있습니다. 가장 정확한 정보는 영어 원문을 참조하시기 바랍니다. 잦은 업데이트로 인해 일부 콘텐츠는 원래 영어로 되어 있을 수 있습니다. Crowdin에서 이 페이지의 번역을 개선하는 데 동참하여 도움을 주세요. (Crowdin translation page, Contributing guide)

TxTypeLegacyTransaction represents a type of transactions existed previously in kaia.

**This type of transaction can create an account, transfer tokens, deploy a smart contract, execute a smart contract, or perform a mix of aforementioned.

Import the ethers package that can interact with the Ethereum Blockchain and its ecosystem.

Import @kaiachain/ethers-ext packages to add kaia features on ethers.js

Define sender address, sender private key and reciever address

Set up the provider with the specified kairos testnet URL. A provider in ethers is a read-only abstraction to access the blockchain data.

Also, you can change the provider URL from kairos to quicknode

Init Wallet instance with the private key and provider.

Declare a transaction with the fields such as from, to, value.

Send the tx to the blockchain. Function sendTransaction internally signs with the private key of the account and then transmits it to the blockchain network.

The wait function returns the tx receipt if it is completed in the blockchain.

txTypeLegacyTransaction.js

const ethers = require("ethers");
const { Wallet, parseKlay } = require("@kaiachain/ethers-ext/v5");
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new ethers.providers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet(senderPriv, provider);
async function main() {
const tx = {
// when type is empty it will be automatically set to type 0 or 2
// depending on the gasPrice, maxFeePerGas, maxPriorityFeePerGas fields.
// here, type will be 2 because no gas-related fields are set.
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01"),
};
const sentTx = await wallet.sendTransaction(tx);
console.log("sentTx", sentTx.hash);
const receipt = await sentTx.wait();
console.log("receipt", receipt);
}
main();

output

❯ node txTypeLegacyTransaction.js
sentTx 0x0693a5398133e80ae462ed957c2f590d4643d8c5fadf3aa6bc4de33b0c3d0da8
receipt {
to: '0xC40B6909EB7085590E1c26Cb3beCC25368e249E9',
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
contractAddress: null,
transactionIndex: 2,
gasUsed: BigNumber { _hex: '0x5208', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0xceca715c25ad13f55c4cba62a1c758b2f6731187cbf61d691e84b615dad263ea',
transactionHash: '0x0693a5398133e80ae462ed957c2f590d4643d8c5fadf3aa6bc4de33b0c3d0da8',
logs: [],
blockNumber: 148720917,
confirmations: 1,
cumulativeGasUsed: BigNumber { _hex: '0x055f7b', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 2,
byzantium: true
}

페이지를 개선해 주세요