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

来源:互联网 发布:mac和nars口红哪个滋润 编辑:程序博客网 时间:2024/06/09 19:56

       对于区块链的学习,选择以太坊平台进行开发实践,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

                    

原创粉丝点击