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,370 points
2,191 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
• 26,740 points

Related Questions In Blockchain

0 votes
2 answers

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

Muchas gracias. ?Como puedo iniciar sesion? READ MORE

answered May 2, 2020 in Blockchain by aqowcmbevs
2,392 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
• 69,220 points
1,663 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, 2019 in Blockchain by Omkar
• 69,220 points
1,771 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,100 points
713 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
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
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
• 69,220 points
1,464 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
• 26,740 points
862 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
• 26,740 points
6,294 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP