Truffle 部署和测试
本文主要参考:here 和 here,因为参考的这篇文章版本有些旧了,所以是根据比较新的版本写的。
一、合约部署
1、 首先初始化环境
truffle init
2、开启testrpc
testrpc //另开窗口
3、部署合约
a. 编写合约代码,保存到contracts/YourContractName.sol文件
例如:Conference.sol
pragma solidity ^0.4.4;
contract Conference { // can be killed, so the owner gets sent the money in the end
address public organizer;
mapping (address => uint) public registrantsPaid;
uint public numRegistrants;
uint public quota;
event Deposit(address _from, uint _amount); // so you can log the event
event Refund(address _to, uint _amount); // so you can log the event
function Conference() {
organizer = msg.sender;
quota = 500;
numRegistrants = 0;
}
function buyTicket() payable public {
if (numRegistrants >= quota) {
throw; // throw ensures funds will be returned
}
registrantsPaid[msg.sender] = msg.value;
numRegistrants++;
Deposit(msg.sender, msg.value);
}
function changeQuota(uint newquota) public {