Truffle是区块链智能合约开发框架的不二之选,隆重推荐一下。集合开发、编译、调试、部署一体,非常方便好用!
1、安装
- 首先要有node.js(而且版本不能太低,v14以上最好)
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt update
sudo apt install nodejs npm
- 接着安装Truffle
sudo npm install -g truffle
2、使用
创建项目
mkdir mydapp
cd mydapp
truffle init
然后,项目模板目录结构如下
contracts
|-Migrations.sol
migrations
|-1_initial_migration.js
test
truffle-config.js
constracts
中文件为智能合约Solidity代码;1_initial_migration.js
是智能和约代码编译的程序入口配置truffle-config.js
是truffle配置文件
编译项目
默认值编译有改动的代码脚本,如果需要编译全部加上参数 -all
truffle compile
部署项目
先配置truffle-config.js
对应的开发环境参数,主要留意host
port
network_id
。然后执行一下命令,进行智能合约的部署
truffle migrate