脚本操作
1 | mkdir two |
truffle初始化目录1
truffle init
truffle编译默认的智能合约1
truffle compile
编写智能合约1
2cd contracts
vi Hello_yudao_me.sol
智能合约内容如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14pragma solidity ^0.4.17;
contract Hello_yudao_me {
//say hello yudao.me
function say() public pure returns (string) {
return "Hello yudao.me";
}
//print name
function print(string name) public pure returns (string) {
return name;
}
}
1 | cd .. |
编辑migrations/1_initial_migration.js部署脚本1
2
3
4
5
6
7var Migrations = artifacts.require("./Migrations.sol");
var Hello_yudao_me = artifacts.require("./Hello_yudao_me.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
deployer.deploy(Hello_yudao_me);
};
编译1
truffle compile --compile-all
另外终端,通过testrpc启动模拟以太坊1
testrpc --gasLimit 0x800000000)
回到刚才的第一个终端,部署智能合约1
truffle migrate --reset
通过truffle来测试智能合约,出现如下内容,恭喜成功1
2
3
4
5
6
7
8
9truffle console
var contract;
undefined
Hello_yudao_me.deployed().then(function(instance){contract= instance;});
undefined
contract.say()
'Hello yudao.me'
contract.print("https://yudao.me")
'https://yudao.me'