1.安装node.js
官网下载并安装
2.安装truffle
npm install -g truffle
3.启动testrpc
以太坊环境
testrpc
4.另开终端窗口新建项目
mkdir Demo
cd Demo
5.初始化项目目录
truffle init
6.创建合约文件
truffle create contract HelloWorld
7.编译合约文件
truffle compile
8.部署合约脚本
打开部署文件
vi
migrations/2_deploy_contracts.js
编写部署合约
var HelloWorld = artifacts.require("
HelloWorld
");
module.exports = function(deployer){
deployer.deploy(
HelloWorld
);
}
执行部署
truffle migrate
9.
合约互动
truffle console
HelloWorld.deployed().then(instance => contract = instance)
10.新增或修改合约后,重新部署
truffle migrate --reset
注:如部署合约失败,修改truffle.js文件
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*"
},
staging: {
host: "localhost",
port: 8546,
network_id: 1337
},
ropsten: {
host: "*.*.*.*(本地IP地址)",
port: 8545,
network_id: 3
}
}
};