【区块链】Truffle 部署和测试

Truffle 部署和测试


本文主要参考:herehere,因为参考的这篇文章版本有些旧了,所以是根据比较新的版本写的。

一、合约部署

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 {
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值