- 安装全局truffle
npm install -g truffle
- 新建一个文件夹用来初始化模板,如果缺少依赖全局安装下即可
truffle unbox webpack
- 找到truffle-config.js,修改相应代码的注释
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
// develop: {
// port: 8545
// },
- 运行开发控制台(development console)
truffle develop
- 编译并部署智能合约,不过命令前面不需要加truffle
compile
migrate
// 也可以不经过第4步,直接truffle compile / truffle migrate
- 先退出开发控制台,然后运行webpack本地服务,如果智能合约改变了就需要重新进入开发控制台手动编译和部署智能合约
// Serves the front-end on http://localhost:8080
npm run dev
- 测试
// If inside the development console.
test
// If outside the development console..
truffle test
Q.E.D.