Events not firing

EamorrEamorr Member Posts: 19
edited September 2015 in Solidity
I'm totally stuck with my simple Solidity contract...
contract Chance{
  address minter;

  event PrintStrEvt(string out);

  function Chance(string init) public{
    minter = msg.sender;
  }

  function hello() public{
    PrintStrEvt("How are you?");
  }


  //Function to recover the funds on the contract
  function kill() {
    if (msg.sender == minter){
      suicide(minter);
    }
  }
}
I deploy with:
var source = '...'
var compiled = web3.eth.compile.solidity(source);


var chanceContract = web3.eth.contract(compiled.Chance.info.abiDefinition);
var chance = chanceContract.new(
  null,
  {
    from:web3.eth.accounts[1],
    data:compiled.Chance.code,
    gas: 3000000
  }, function(e, contract){
    if(!e) {
      if(!contract.address) {
        console.log("Waiting to be mined...");
        inspect(contract);
      } else {
        console.log("Contract mined!");
        inspect(contract);
      }
    }else{
      console.log("Error");
      inspect(e);
    }
});
And it gets mined successfully.

Then I set up the event listener:

var printStrEvt = chance.PrintStrEvt({}, '', function(error, result){
  if (!error){
    inspect(result);
  }
});
It gets fired after I call:

chance.hello.sendTransaction([1,2,3,4,5,6],{from:eth.accounts[1]})
Great.

I can see "How are you?"

Then I call "hello" again:

chance.hello.sendTransaction([1,2,3,4,5,6],{from:eth.accounts[1]})
Nothing happens!!!

The eth.blockNumber is incrementing away. The event never gets fired. What am I doing wrong???

Comments

  • MetalMetal Member Posts: 17
    I'm not sure. Events are still a little bit mysterious to me as well.

    The first thing to try would to be make each event unique, in case there's something between the contract code and your web3.js callback that "helpfully" eliminates duplicate log events.
    import "mortal";
    
    contract c is mortal {
      event PrintStrEvt(string out, int counter);
      int counter;
    
      function c(string init) {
      }
    
      function hello() {
        PrintStrEvt("How are you?", ++counter);
      }
    }
    
    Try it out, and see if that makes any difference.
Sign In or Register to comment.