区块链技术学习(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.
注意:truffle3.0以上的目录结构与2.0初始化后不同,缺少了app目录,而且自带的测试metacoin也无法在localhost:8080打开。
解决方法一:https://github.com/trufflesuite/truffle/issues/448
解决方法二:参照http://blog.****.net/qindong564950620/article/details/63686728