区块链技术学习(0):搭建truffle开发环境

       对于区块链的学习,选择以太坊平台进行开发实践,truffle是以太坊平台上最流行的开发框架之一,所以我们就安装truffle,并运行第一个默认的demo区块链程序metacoin(DAPP )。

一、安装truffle 。可以参考官方文档:http://truffleframework.com/docs/getting_started/installation

系统要求:Windows, Linux or Mac OS X

安装node.js环境:

访问官方网站https://nodejs.org进行下载安装。

安装ethereum客户端

开发测试的时候推荐用EthereumJS TestRPC: https://github.com/ethereumjs/testrpc

安装命令 $ npm install -g ethereumjs-testrpc

部署到网络用Geth (go-ethereum): https://github.com/ethereum/go-ethereum

          安装truffle:

安装命令 $ npm install -g truffle

            现在不翻墙用npm安装下载速度非常慢,可以用淘宝镜像cnpm。

二、创建第一个区块链项目demo

$ mkdir test

$ cd test

$ truffle init

此时,truffle 3.0 以上会生成如下文件结构

  • contracts/ - directory where Truffle expects to find solidity contracts.
  • migrations/ - directory to place scriptable deployment files.
  • test/ - location of test files for testing your application and contracts.
  • truffle.js - your main Truffle configuration file.
接下来编译:$ truffle compile
再新建一个终端窗口,启动客户端testrpc:$ truffle testrpc

在原来终端窗口输入命令进行部署: $ truffle migrate
恭喜!第一个 智能合约部署完毕。   此时可运行    $ truffle test 进行测试,可以看到顺序编号的区块信息,如下图。                

注意:truffle3.0以上的目录结构与2.0初始化后不同,缺少了app目录,而且自带的测试metacoin也无法在localhost:8080打开。

         解决方法一:https://github.com/trufflesuite/truffle/issues/448

解决方法二:参照http://blog.csdn.net/qindong564950620/article/details/63686728

                    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值