dApp 프레임워크인 truffle
을 사용해서 sepolia 네트워크에 배포하는 방법을 알아보자.
사전 준비
npm install -g truffle
NPM을 사용해서 truffle을 전역 설치 해준다.
전역 설치하지 않으면 실행이 되지 않는다.
metamask test net ehter ballance append 검색
npm install dotenv
truffle init
truffle-config.js
: Truffle 설정 파일입니다.hdwallet-package는 12단어 또는 24단어 니모닉에서 파생된 주소에 대한 트랜잭션을 서명할 수 있는 별도의 패키지이다. Metamask에 접근할 수 있게 해준다.
INFURA_API_KEY = "https://ropsten.infura.io/v3/<Your-API-Key>"
MNEMONIC = "<Your-MetaMask-Secret-Recovery-Phrase>"
Your-API-Key
: Infura의 이더리움 프로젝트 API key.
Your-MetaMask-Secret-Recovery-Phrase
: MetaMask 지갑의 니모닉. hdwallet-provider의 거래에 사용됩니다.
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.8;
contract Demo {
event Echo(string message);
function echo(string calldata message) external {
emit Echo(message);
}
}
require('dotenv').config();
const HDWalletProvider = require('@truffle/hdwallet-provider');
const { INFURA_API_KEY, MNEMONIC } = process.env;
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*"
},
sepolia: {
provider: () => new HDWalletProvider(MNEMONIC, INFURA_API_KEY),
network_id: <Sepolia Chain Id In Here>,
gas: 5500000
}
}
};
truffle compile
성공시
Compiling your contracts...
===========================
> Compiling ./contracts/Demo.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /Users/user/truffleProject/build/contracts
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
truffle migrate --network sepolia
성공시
Starting migrations...
======================
> Network name: 'ropsten'
> Network id: 3
> Block gas limit: 30000000 (0x1c9c380)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0xd437e9d1595e31228dcead9397caa1526ebe5ae8f7ec06a176b7aeed53916202
> Blocks: 4 Seconds: 53
> contract address: 0xBe72Ed0EB8Af6d52c0Be64Ca908f81E0100390C2
> block number: 12818214
> block timestamp: 1660875012
> account: 0x5A2609D698DE041B1Ba77139A4229c8a161dDd9e
> balance: 19.999374644998249006
> gas used: 250142 (0x3d11e)
> gas price: 2.500000007 gwei
> value sent: 0 ETH
> total cost: 0.000625355001750994 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.000625355001750994 ETH
2_deploy_contract.js
====================
Deploying 'Demo'
----------------
> transaction hash: 0xbed1f55b5be802ac40e408d3ac517de67795afc1762aaa7450dd652921a557bd
> Blocks: 2 Seconds: 29
> contract address: 0xD06F174f4A41884AAf0958C72EEc49Ec386e03b3
> block number: 12818218
> block timestamp: 1660875060
> account: 0x5A2609D698DE041B1Ba77139A4229c8a161dDd9e
> balance: 19.998852204996786174
> gas used: 163063 (0x27cf7)
> gas price: 2.500000007 gwei
> value sent: 0 ETH
> total cost: 0.000407657501141441 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.000407657501141441 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0.001033012502892435 ETH
transaction hash
을 통해 EtherScan에서 블록 정보를 확인할 수 있다.