ABI
만들기chai
랑 Mocha
도 지원)├── contracts
├── Migrations.sol
├── migrations
├── 1_initial_migration.js
└── test
truffle-config.js
truffle.js
truffle init
명령어를 실행하면 위와 같은 기본 구조가 설치된다.contracts
: 트러플이 내가 만든 컨트랙트를 찾는 곳. 보통 contracts/tokens
처럼 nested
로 정리한다.migrations
: 트러플에게 어떻게 스마트 컨트랙트를 배포할지 말하는 자바스크립트 파일이 위치test
: 유닛 테스트 파일을 넣는 곳truffle.js
: 네트워크 세팅을 저장하는 곳truffle.config.js
: 윈도우 쓰면 truffle.js
지우고 이걸 config
파일로 사용해야 한다.트랜잭션 sign을 하기 위해 설치하는 프로바이더!
보통truffle init
하고 바로 설치함!
Infura
를 사용해서 이더리움에 코드를 배포할 것이다.Infura
를 쓰면 이더리움 노드나 지갑을 직접 run
할 필요가 없다.truffle-hdwallet-provider
를 따로 설치해서 이용한다.├── contracts
├── Migrations.sol
├── CryptoZombies.sol
├── erc721.sol
├── ownable.sol
├── safemath.sol
├── zombieattack.sol
├── zombiefactory.sol
├── zombiefeeding.sol
├── zombiehelper.sol
├── zombieownership.sol
├── migrations
└── test
contracts
안에 넣고 컴파일 진행var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
migration
컨트랙트와 통신하기를 원한다는 것을 알려준다deployer
라는 객체를 받는 함수를 export
한다deployer
라는 객체는 개발자와 프러플의 개발 엔진 간의 인터렉션을 담당한다.var CryptoZombies = artifacts.require("./CryptoZombies.sol");
module.exports = function(deployer) {
deployer.deploy(CryptoZombies);
};
아래 코드는 메인넷과 rinkeby 의 config 객체 두개에 대한 설정을 담고있다.
networks: {
// Configuration for mainnet
mainnet: {
provider: function () {
// Setting the provider with the Infura Rinkeby address and Token
return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/YOUR_TOKEN")
},
network_id: "1"
},
// Configuration for rinkeby network
rinkeby: {
// Special function to setup the provider
provider: function () {
// Setting the provider with the Infura Rinkeby address and Token
return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/YOUR_TOKEN")
},
// Network id is 4 for Rinkeby
network_id: 4
}
rinkeby
를 사용할거라고 알려준다.// Initialize HDWalletProvider
const HDWalletProvider = require("truffle-hdwallet-provider");
// Set your own mnemonic here
const mnemonic = "YOUR_MNEMONIC";
// Module exports to make this configuration available to Truffle itself
module.exports = {
// Object with configuration for each network
networks: {
// Configuration for mainnet
mainnet: {
provider: function () {
// Setting the provider with the Infura Rinkeby address and Token
return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/YOUR_TOKEN")
},
network_id: "1"
},
// Configuration for rinkeby network
rinkeby: {
// Special function to setup the provider
provider: function () {
// Setting the provider with the Infura Rinkeby address and Token
return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/YOUR_TOKEN")
},
// Network id is 4 for Rinkeby
network_id: 4
}
}
};
truffle migrate --network rinkeby
명령어로 실행