truffle unbox name
truffle compile
truffle migrate
truffle test
truffle develop/truffle console // develop是命令行下的操作,console是基于ganache的操作
truffle入门
第一步:
mkdir MetaCoin
cd MetaCoin
truffle unbox metacoin // 下载metacoin合约
(如果要创建没有合约的空工程,可以使用 truffle init.)
执行 truffle unbox **** 报错,因为无法连接raw.githubusercontent.com,需要翻墙或者配置本地host文件
1、通过 https://www.ipaddress.com 查询 raw.githubusercontent.com 的 地址。
2、配置host文件 C:\Windows\System32\drivers\etc\host 增加以下内容
185.199.108.133 raw.githubusercontent.com
第二步:
truffle compile //编译
第三步:
打开ganache或者在truffle.config.js中配置测试网络,然后运行:
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// for more about customizing your Truffle configuration!
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
}
},
// Configure your compilers
compilers: {
solc: {
version: "0.4.24", // Fetch exact version from solc-bin (default: truffle's version)
}
}
};
truffle migrate // 部署
truffle migrate --reset原因。由于合约移植是懒编译的,如果发现已经发布过,且发布的版本号没有变化就不会再发布,所以使用–reset。使用truffle migrate –reset来强制重编译并发布所有合约
第四步:
truffle console //得到下面界面,可以和合约交互
truffle(development)>
宠物商店Dapp
https://segmentfault.com/a/1190000014891234
truffle文档
https://www.qikegu.com/docs/4807