Zihao

Make small but daily progress

0%

0x05--智能合约开发流程详解

编写sol

contracts 文件夹下放置*.sol 文件
引入其他文件,注意大小写

编译contracts下的sol

1
vim 2_deploy_contracts.js 

example:

1
2
3
4
5
6
7
8
9
10
11
12
var Ownable = artifacts.require("./Ownable.sol");
var SafeMath = artifacts.require("./SafeMath.sol");
var Payroll = artifacts.require("./Payroll.sol");

module.exports = function(deployer) {
deployer.deploy(Ownable);
deployer.deploy(SafeMath);

deployer.link(Ownable, Payroll);
deployer.link(SafeMath, Payroll);
deployer.deploy(Payroll);
};

执行编译

1
trffle migrate

打开测试客户端 testrpc

交互

1
2
3
4
5
6
7
8
truffle console 
# 调用web3 获取地址
web3.eth.accounts
# 执行添加方法
payroll.addRmployee('0xasdasdas2qwa0sd9uvnmaos',2)
# 查看信息
paroll.employees.call('0xasdasdas2qwa0sd9uvnmaos').then(result=>console.log)

欢迎关注我的其它发布渠道