truffle Dapp 搭建

安装truffle

$ npm install -g truffle

依赖环境 NodeJS 访问https://nodejs.org 官方网站下载安装

系统:Windows, Linux or Mac OS X,推荐Mac OS X,不建议使用Windows,会碰到各种各样的问题,导致放弃。

需要安装Ethereum客户端,来支持JSON RPC API调用 开发环境,推荐使用EthereumJS TestRPC: https://github.com/ethereumjs/testrpc

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

新建第一个项目

$ mkdir zhaoxi

$ cd zhaoxi

$ truffle init

默认会生成一个MetaCoin的demo,可以从这个demo中学习truffle的架构

项目目录结构如图:

项目所有文件目录如图:

编译项目

$ truffle compile 

部署项目

部署之前先启动TestRPC

$ testrpc

$ truffle deploy(在Truffle 2.0以上版本中,命令变成了:truffle migrate) $ truffle migrate 执行结果 

启动服务

$ truffle serve 

启动服务后,可以在浏览器访问项目: http://localhost:8080/ ,网页界面如下:


原文地址:https://www.cnblogs.com/dqh123/p/9600787.html