TRUFFLE02:使用ganache搭建以太坊开发环境

2020-04-28  本文已影响0人  杨强AT南京

  使用geth作为开发测试环境,太纠结了,所以ganache就是一个较好的选项。代替geth环境,可以提供一键式开发环境搭建,ganache与geth遵循完全一样的协议与标准。其便捷性体现在:
  1. 账号与初始Token;
  2. 缺省的配置(比如不需要使用创世配置文件创建创世块);


准备

启动测试以太坊节点

快捷的初始账号创建

连接到以太坊

使用geth连接

使用geth也可以连接到ganache

使用truffle连接

在truffle中访问

使用默认项目测试

  1. 使用truffle init创建项目

    • 网络不稳定多试几次
  2. 使用vscode打开进行工作

  3. 配置以太坊网络

  4. 编译

  5. 部署

    • 可以强制部署:truffle deploy --reset
      • deploy比migrate更好记住,是别名,作用一样。

C:\01works\08eth\Tru\tru_3rd>truffle migrate

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\01works\08eth\Tru\tru_3rd\build\contracts
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang



Starting migrations...
======================
> Network name:    'development'
> Network id:      1585295887794
> Block gas limit: 0x6691b7     


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xf19ef28dfe5957891b7a8424e6ad1a3338f5bfa12650a7e14791fa166d55c1a5
   > Blocks: 0            Seconds: 0
   > contract address:    0xd14931ca02B1d4998F13ED57e6d94162982Ffe55
   > block number:        1
   > block timestamp:     1585296750
   > account:             0x9977bAea7Bc77E315EF36E6d1B9371CEAbF7949E
   > balance:             99.9967165
   > gas used:            164175
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0032835 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:           0.0032835 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.0032835 ETH



C:\01works\08eth\Tru\tru_3rd>
  1. 测试
C:\01works\08eth\Tru\tru_3rd>truffle test
Using network 'development'.


Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\Users\gaoke\AppData\Local\Temp\test-2020227-2140-25lc4x.eh0hl
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang



  0 passing (0ms)


C:\01works\08eth\Tru\tru_3rd>



上一篇 下一篇

猜你喜欢

热点阅读