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

Smart Contract Deploy

TxTypeSmartContractDeploy deploys a smart contract to the given address. 이 트랜잭션 유형에 따라 다음과 같은 변경 사항이 적용됩니다.

Import the ethers and @kaiachain/ethers-ext modules to add kaia features on ethers.js.

Define sender address and sender private key

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

Create a sender's wallet using the sender's private key and the provider

Declare a transaction object

Specify the transaction type as SmartContractDeploy

Set the compiled bytecode from the solidity code you want to deploy to the blockchain network

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.

TxTypeSmartContractDeploy.js

const ethers = require("ethers");
const { Wallet, TxType } = require("@kaiachain/ethers-ext/v6");
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet(senderPriv, provider);
async function main() {
const tx = {
type: TxType.SmartContractDeploy,
from: senderAddr,
value: 0,
gasLimit: 1_000_000,
input: "0x608060405234801561001057600080fd5b5060f78061001f6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60006001820160ba57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220e0f4e7861cb6d7acf0f61d34896310975b57b5bc109681dbbfb2e548ef7546b364736f6c63430008120033",
humanReadable: false, // must be false
codeFormat: 0, // must be 0
};
const sentTx = await wallet.sendTransaction(tx);
console.log("sentTx", sentTx.hash);
const receipt = await sentTx.wait();
console.log("receipt", receipt);
}
main();

output

❯ node TxTypeSmartContractDeploy.js
sentTx 0xeff15464362194155acfb4e0eb0cedc470320d3d12fc504dbab9f918cf57452d
receipt {
to: null,
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
contractAddress: '0x028016AE0996097bB329a91f3D0C44C0Ee700f34',
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0x01fd0d', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x07a0f27ebddc4c4633c5ea70125e6e09ecc460b19f0e83ff8b271ad34aa868ec',
transactionHash: '0xeff15464362194155acfb4e0eb0cedc470320d3d12fc504dbab9f918cf57452d',
logs: [],
blockNumber: 148720946,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x04387b', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

페이지를 개선해 주세요