Ethereum call contract method that emits an event, from another contract

0 votes

I have a contract, that calls a method on another contract, which causes it to emit an event - which I am listening for in a node process.

If I execute the method that fires the event directly (from the console) - it fires fine. But if I execute the method, by first calling the initial contract to in turn call the contract that fires the event, the event does not fire.

Is there a way of calling a follow on contract I am missing, or is this something I cannot do by design? The following code describes the problem:

contract EventEmitter{
    event Emit(address addr, string message);

    //this works when I call it directly from the console,ie:
    //emitter.doEmit("blah", {from: "[primary acc]", value: web3.toWei(100, "ether")});
    function doEmit(string message) returns (bool){
        Emit(msg.sender, message);
        return true;
    }
}

contract EventEmitterCaller{
    event TestEvent(string message);

    function callDoEmit(string message) returns (bool){
        EventEmitter emitter = new EventEmitter();
        //always returns false
        //emitterCaller.callDoEmit("blah", {from: "[primary acc]", value: web3.toWei(100, "ether")});
        return emitter.doEmit(message);
    }

}
Sep 25, 2018 in Blockchain by slayer
• 29,050 points
49 views

1 answer to this question.

0 votes

You need to refer to the EventEmitter by its address:

instead of

EventEmitter emitter = new EventEmitter();

do

EventEmitter emitter = EventEmitter(0xef833fea60388efd541b62737c7aa3b59a6d80ef);
answered Sep 25, 2018 by digger
• 27,630 points

Related Questions In Blockchain

0 votes
1 answer

How to get notified when an event triggers on ethereum smart contract?

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,340 points
363 views
0 votes
1 answer

Ethereum solidity: Unable to get value from another contract

I have faced similar issues when compiling ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,380 points
190 views
0 votes
1 answer

How can I call a contract from another contract?

There are two ways to solve this. ...READ MORE

answered Jan 23 in Blockchain by Omkar
• 67,380 points
51 views
0 votes
1 answer

How is a request sent from an app to a smart contract?

Yes, the contract is distributed by every node ...READ MORE

answered Jun 4, 2018 in Blockchain by Perry
• 17,020 points
50 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
138 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,380 points
75 views
0 votes
1 answer

How to call function in one contract from another contract in private blockchain?

Please check whether you have byzantiumBlock: 0 in your ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 27,630 points
47 views
0 votes
1 answer

Call contract methods with web3 from newly created account

In fact, we can't just send transactions ...READ MORE

answered Sep 25, 2018 in Blockchain by digger
• 27,630 points
793 views