티스토리 뷰

truffle로 Solidity개발 시작하기

코인쪽 일을 하다보니 솔리디티 정도는 알아두는게 좋을 것 같아서 세미나도 듣고 해커톤도 해서 시작을 할 수 있게 되어서 이 포스트를 쓴다.


repo

https://github.com/Kyeongrok/truffle_hello


필요한 것 

node.js, npm

npm install -g truffle

ganache(mac), ganache-cli


디렉토리 만들기 truffle init 하기

mkdir truffle_01

cd truffle_01

truffle init


프로젝트 구조


migrations/2_second.js

1
2
3
4
5
6
const HelloToken = artifacts.require("./HelloToken.sol");
 
module.exports = function(deployer) {
    deployer.deploy(HelloToken)
}
 
cs


contracts/HelloToken.sol

1
2
3
4
5
6
7
8
9
10
11
12
pragma solidity ^0.4.24;
 
contract HelloToken {
    function hello() public pure{
 
    }
 
    function hello2() public view returns(string){
        return "hello";
    }
}
 
cs

truffle.js
1
2
3
4
5
6
7
8
9
10
11
12
module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  networks: {
    development: {
      host: "localhost",
      port: 7545,
      network_id: "*" // Match any network id
    }
  }
};
 
cs

test/hello_token.js

1
2
3
4
5
6
7
8
9
10
11
const HelloToken = artifacts.require("./HelloToken.sol");
 
contract('HelloToken', (accounts) => {
    it("hello2", () => {
  return HelloToken.deployed().then(instance => {
    instance.hello2().then(result => console.log(result))
  
    });
  });
 
});
cs


ganache로 개발용 네트웍 띄우기

https://truffleframework.com/ganache

위 링크에서 gui버젼 받거나



npm i -g ganache-cli 로 cli버젼 설치

ganache-cli -u 0으로 실행


배포하기

truffle migrate

또는

truffle migrate --network development

또는 

truffle migrate --network development --compile-all --reset


배포 되었는지 확인하기

로그에 뭔가 올라오면 잘 배포 된것


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함