区块链 truffle 3.0
网上的教程大多是在2.0基础上的,按照网上文章学习过程中会有一些困惑,整个 demo 的过程基本上网上别人遇到的报错我也都踩了个遍,在这里面记录一下整个学习过程
配置环境
安装truffle 环境
npm install -g truffle
安装 ethereum 客户端
npm install -g ethereumjs-testrpc
开始项目
1.初始化项目
truffle init webpack
会提示
Using `truffle init` with a specific template is deprecated. Please use `truffle unbox` instead.
Downloading project...
Installing dependencies...
Project initialized.
Documentation: https://github.com/trufflesuite/truffle-init-webpack
Commands:
Compile: truffle compile
Migrate: truffle migrate
Test: truffle test
Build Frontend: npm run build
Run Linter: npm run lint
Run Dev Server: npm run dev
Hint: Run the dev server via `npm run dev` to have your changes rebuilt automatically.
Make sure you have an Ethereum client like the ethereumjs-testrpc running on http://localhost:8545.
2.编译项目
truffle compile
将会把 contracts 中的.sol
编译成.json
能够在build/contracts/*.json
看到
3.部署项目
新开一个终端,启动Ethereum客户端
testrpc
4.部署
truffle migrate
在 testrpc 中将会看到
net_version
eth_accounts
eth_accounts
net_version
net_version
eth_sendTransaction
Transaction: 0x74c7b56ab9f04b6cd30d729df956980f23fd9042ea6102e09c0d63954d694594
Contract created: 0xda53fa14d825f41f449cdb80c11791e8ad043670
Gas usage: 199673
Block Number: 1
Block Time: Wed Jan 10 2018 18:49:26 GMT+0800 (CST)
5.运行
truffle serve
根据上面的提示打开http://localhost:8080/
就能看到教程上面说的网页了额
这个是官方文档