以太坊智能合约开发框架truffle学习

1. 安装

npm install -g truffle
2.    建立MetaCoin工程

mkdir MetaCoin
cd MetaCoin
truffle unbox metacoin
3. 启动私链(https://github.com/luoiefly/ethfun)

./geth  --rpc  --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console



4. 测试
    cd  MetaCoin
    truffle compile
    truffle  migrate
    报错:  Error: No network specified. Cannot determine current network.
5. 要修改truffle.js配置
   

      networks: {

        development1 : {

            host: "localhost",

            port: 8545,

            network_id: "*", // 匹配任何network id

            gas: 3000000,

            gasPrice: 0x1

         }

    }

6. truffle migrate

   报错:Error: authentication needed: password or unlock


7. 要unlock account

  

WiRoams-MacBook-Air:bin luoie$ ./geth account list

Account #0: {15ed970cc673c6a8912c42663104c25e9d25698a} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-14.944479172Z--15ed970cc673c6a8912c42663104c25e9d25698a

Account #1: {aaba4749df21949095ff9445449ded85347f7154} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-24.027018315Z--aaba4749df21949095ff9445449ded85347f7154

Account #2: {b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T00-42-07.946381709Z--b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75

Account #3: {e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T14-26-23.123370914Z--e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb

WiRoams-MacBook-Air:bin luoie$ 


要使用第一个。

改变私链启动命令。

./geth --rpc --unlock 15ed970cc673c6a8912c42663104c25e9d25698a --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console


8. truffle migrate
  报错: Error: unknown transaction
  可能是版本问题。  Migration合约会出错, 但是直接用钱包部署合约会成功。
  所以暂且不部署Migration。
  cd migrations
  vim  1_initial_migration.js 
修改:

module.exports = function(deployer) {

  //deployer.deploy(Migrations);

};


 9.  truffle migrate

WiRoams-MacBook-Air:MetaCoin luoie$ truffle migrate

Using network 'development'.


Running migration: 1_initial_migration.js

Saving artifacts...

Running migration: 2_deploy_contracts.js

  Replacing ConvertLib...

  ... 0x1fd4a181f09d3df25c1c18109c9e305f5ee670e81f450872778219c03d1b7ec4

  ConvertLib: 0xc7b9a4302748ba75da0c6a39a2c12ba2b1fb98bc

  Linking ConvertLib to MetaCoin

  Replacing MetaCoin...

  ... 0xcc67bd245f1260d27db72b250913c308e2c3245d0ff5c4aea4f90688232cf0dd

  MetaCoin: 0x8ce003908df3075307c22a18d6a8951dccdb24e7

Saving artifacts...

WiRoams-MacBook-Air:MetaCoin luoie$

成功啦
10. 查看合约
   cd build/contracts
   vim  MetaCoin.json
   拷贝abi
   打开以太坊钱包, 查找合约
   



  


猜你喜欢

转载自blog.csdn.net/luoie/article/details/79224708