Truffle is a world class development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier.
1.创建一个新项目
# 创建一个空白项目
truffle init
# 下载一个模板项目
truffle unbox pet-shop
2.编译智能合约
truffle compile
3.部署智能合约(需要先有一条现成的区块链才能把东西部署上去)
truffle migrate
更多
注意事项:
需要配置truffle的配置文件:truffle.js
配置方式:编辑truffle项目根目录下的truffle.js文件
module.exports = {
networks: {
development: {
// 在我的例子中是ganache-cli产生的私链的ip地址和端口
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
}
}
};
ganache-cli是使用JavaScript编写的,通过npm将其作为节点包分发。所以确保已经安装过NodeJS(>=v6.11.5).
安装命令:
npm install -g ganache-cli
使用ganache-cli命令:
ganache-cli <options>
注意:
1. npm ERR! code ELIFECYCLE
2. 要科学上网才能把示例项目跑起来