1

I am new to ethereum and am using truffle and mocha for development. I am writing an app that is sending ethereum to a contract. The ether stored in the contract is then used later.

I have a function that creates a ticket by calling to a seperate contract: TicketAccount (which holds all the tickets in an account).

function createTicket(bytes32 _name, uint _cost) public payable returns(address ticket) {
    var setBalance = _cost * 2;
    var ticketAddress = accounts[msg.sender].createTicket.value(setBalance)(_name, _cost);
    return ticketAddress;
  }

I am referring to the docs here This is the function it is calling to. A user must have registered an account to be considered an owner.

function createTicket(bytes32 _name, uint _cost) public payable isOwner() returns (address ticketTransaction) {
    // ... code here
  }

I am writing a mocha test where service is my original contract where the createTicket can be called from.

it("should create ticket", function() {

    var newTicket = service.createTicket.value(20)("Ticket Name", 20);
    return newTicket.then(function(newTicket) {
      assert.isOk(newTicket);
    });
  });

This is the error that the test is giving

TypeError: service.createTicket.value is not a function

UPDATE: I have also tried this method to no avail. This gives me the dreaded invalid opcode

var newTicket = service.createTicket.sendTransaction("Ticket Name", 20, {from: accountOne, value: 40});
1

I think the format your looking for is:

service.createTicket(arg1, arg2, {value: 30, from: accounts[3]}, function(err, result) {
   console.log(result)
}

At least, that works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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