Truffle实战指南

in #starnote5 years ago

从智能合约的编译、测试、布署到上线的完整流程。本地以ganache, geth进行开发测试,再由infura发布到ropsten测试网,实现一个Dapp开发的完整设计。
-> 前往星空笔记

Sort:  
Loading...

Hi! Did you know that steemit.com is now censoring users and posts based on their opinions?
All the posts of these users are gone!
https://github.com/steemit/condenser/commit/3394af78127bdd8d037c2d49983b7b9491397296

Here's a list of some banned users:
'roelandp', 'blocktrades', 'anyx', 'ausbitbank', 'gtg', 'themarkymark', 'lukestokes.mhth', 'netuoso', 'innerhive'
See anyone you recognize? There could be more, they also have a remote IP ban list.

Will you be censored next?

cnpm install -g truffle
truffle version
truffle --help

npm uninstall -g truffle //卸载

truffle init  初始化,生成以下文件
    contract migrations test turffle-config.js truffle.js
truffle develop  启动编译环境
    web3.eth.coinbase;   //第0个帐户
    web3.eth.account[1]; //第1个帐户
    web3.eth.getBalance("addr")   //查询余额
    //eth = 100*10**18 wei, 后面18个零
    //acount = web3.toWei(30, "ether");
    web3.eth.sendTransaction({from:"0x3a...c35c", to:"0x6f...04", value:20000}); //转帐
truffle console --network ganachenet  //交互
truffle compile  //编译
truffle migrate --network ganachenet  //布署到指定网络
   migrations -> 2_initial_helloworld.js

ganache本质是一个使用javascript实现的以太坊客户端。
缺点:只存在于内存,一重启数据全没!

cnpm install ganache-cli -g
ganache-cli

配置truffle:
module.exports = {
  networks: {
    ganachenet: {
      host:"127.0.0.1",
      port:8545,
      network_id:"*"
    }
  }
};

truffle compile
truffle migrate --network ganachenet  //布署到指定网络
Loading...
Loading...

在geth私有节点的基础上,另起一个节点,使用同样的创世区块设置。

  1. 新建目录:private2
  2. init.json //创世区块要一致
  3. geth init init.json --datadir .
  4. geth --datadir . --port 30302 --nodiscover --ipcdisable console
  5. net.peerCount //查看相连的节点
    admin.nodeInfo.enode //查看节点信息
    "enode://[email protected]:30302?discport=0"
Loading...