安装框架
npm install –g truffle
初始化
truffle init
编译
truffle compile
网络配置
truffle-config 或 config 配置网络,例如(BSC测试网),mnemonic为助记词
gasPrice可调控
bsctest: {
provider: function() {
return new HDWalletProvider(mnemonic, "https://data-seed-prebsc-1-s1.binance.org:8545/") },
network_id: 97, gasPrice: 50000000000,
},
合约验证配置
api_keys: { etherscan: '区块浏览器API-KEY' },
plugins: [ 'truffle-plugin-verify' ]
部署
truffle migrate --network bsctest
合约验证
合约部署完成后,才可验证
truffle run verify ContractName --network bsctest
其中:ContractName 为部署的合约名。
注:可通过补充地址进行验证
truffle run verify ContractName@Address --network bsctest
Address :为合约地址
Truffle 命令概述
truffle <cmd> [options]
truffle不填命令 等价 truffle help ,显示所有命令
Truffle v5.4.6 - a development framework for Ethereum
Usage: truffle <command> [options]
Commands:
build 项目构建(已弃用)
compile 编译合约,加上 --all 强制编译所有合约文件
config Set user-level configuration options
console 进入truffle控制台
create 创建项目结构
db 数据库接口命令
debug debug,调试交易。 接<tx_hash> 交易hash参数
deploy 部署合约,migrate别名
develop 打开本地区块链控制台
exec 执行js脚本 参数 <script.js> [--network <name>] [--compile]
--compile 在执行脚本之前先编译合约
help 帮助
init 初始化一个空项目
--force 强制初始化
install 安装包 truffle install <package_name>[@<version>]
migrate 部署合约
--reset:从头开始运行所有的迁移脚本,而不是从最后完成的开始
--f :从number指定的迁移脚本开始运行。number指向迁移脚本文件的前缀
--to : 运行到number指定的迁移脚本
--network :指定要使用的网络,该网络名必须在配置文件中已经存在
--compile-all:编译全部合约,而不是智能选择需要编译的合约
--verbose-rpc:记录并显示Truffle和以太坊客户端之间的通信
--dry-run:分叉指定的网络,仅执行测试迁移
--interactive:在dry run之后,提醒用户确认是否继续
networks 展示每个部署的网络
--clean:移除所有不相关的网络构件
obtain Fetch and cache a specified compiler
opcode 显示合约操作码
preserve Save data to decentralized storage platforms like IPFS and Filecoin
publish 发布包
run 三方插件运行
test 测试
unbox 下载Truffle Box
version 版本
watch 已弃用
See more at http://trufflesuite.com/docs