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,040 points
23 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,620 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,320 points
210 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
• 65,850 points
77 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
• 65,850 points
37 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
• 16,450 points
29 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
63 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
• 65,850 points
28 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,620 points
31 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,620 points
365 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.