I am following a tutorial to write a registrant contract and when I try to submit transactions to the contract I always get error :it seems this transaction will fail. If you submit it, it may consume all the gas upi provide.
I create run a private block chain on my laptop and I deployed the contract through Mist. The source code are shown below:

pragma solidity ^0.4.18;

contract EventRegistrant {

    //basic class of registrant
    struct Registrant {
        uint amount;
        uint numTickets;
        string email;

    //define variables
    address public owner;
    uint public numTicketsSold;
    uint public quota;
    uint public price;
    mapping (address => Registrant) registrantsPaid;
    event Deposit (address _from, uint _amount);
    event Refund (address _to, uint _amount);

    //Modifiers to define following functions
    //character "_" means this is a modifier
    modifier onlyOwner(){
        require(msg.sender != owner);
    modifier soldOut(){
        require(numTicketsSold >= quota);

    function EventRegistrant(uint _quota, uint _price) public {
        owner = msg.sender;
        numTicketsSold = 0;
        quota = _quota;
        price = _price;

    function buyTicket(string email, uint numTickets) soldOut public payable {
        uint totalAmount = price * numTickets;
        require(msg.value > totalAmount);
        if (registrantsPaid[msg.sender].amount > 0) {
            registrantsPaid[msg.sender].amount += msg.value;
            registrantsPaid[msg.sender].numTickets += numTickets;
            registrantsPaid[msg.sender].email = email;
        } else {
            registrantsPaid[msg.sender].amount = totalAmount;
            registrantsPaid[msg.sender].numTickets = numTickets;
            registrantsPaid[msg.sender].email = email;
        numTicketsSold += numTickets;
        if (msg.value > totalAmount) {
            uint refundAmount = msg.value - totalAmount;
        Deposit(msg.sender, msg.value);
    function refundTickets(address buyer) onlyOwner public {
        if (registrantsPaid[buyer].amount > 0) {
            if (this.balance >= registrantsPaid[buyer].amount) {
                registrantsPaid[buyer].amount = 0;
                numTicketsSold = numTicketsSold - registrantsPaid[buyer].numTickets;
                Refund(buyer, registrantsPaid[buyer].amount);
    function withdrawFunds() onlyOwner public {

    function getRegistrantsAmountPaid(address buyer) public view returns (uint) {
        return registrantsPaid[buyer].amount;

    //destructor, to delete the contract when there is no need
    function kill() onlyOwner public {

This is how my contract looks like in the Mist. enter image description here This is error when I submit the transaction. enter image description here

Anyone can help me? thank you in advance.

1 Answer 1


buyTickets seems to only allow someone to buy a ticket if all the tickets are already sold (soldOut). Even if this isn't the source of the problem, it's almost certainly a mistake.

  • yes, you are right. I changed modifier soldOut and it worked. Thank you
    – Frank Kong
    Commented Jan 21, 2018 at 22:52
  • but there is an another question: when i called the buyTickets, the balance of buyer and contract do not change. The transaction is already confirmed by miner(I run on my own laptop). Can you check if I wrote event Deposit correctly?
    – Frank Kong
    Commented Jan 21, 2018 at 22:55
  • Are you sure that the balances don't change? Note that you seem to have set the price to 1 wei. (0.000000000000000001 ether), so the change may have been miniscule.
    – user19510
    Commented Jan 21, 2018 at 22:57
  • Yes, I set it as 1 wei when I deploy contract. The balance actually changed but only 0.0000000000000001 ETHER. Thank you
    – Frank Kong
    Commented Jan 21, 2018 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.