4

I have two contracts :

// contract #1
contract eXample {
// intizializer 
  function eXample{
   .....
  }
//creating the Event
  event MyEvent(uint x,uint y,uint z);
  function doSomething{
    .....
// calling the event inside doSomething function
   MyEvent(x,y,z);
  }
}


contract contractCaller {
  ....
// creating an instance of contract #1
  eXample instance = eXample(address)
 // calling fonction from contract #1 inside contract #2 method.
  function exampleFunction{
    instance.doSomething
  }
  // everytjing inside eXamplefunction is working. Everything inside instance.doSomething IS working. Only issue is the Event not triggering.
  ....
}

I'm using function from "eXample" in "contractCaller" everything works fine but one thing. When calling instance.doSomething from the 2nd contract i'm not returned any Event from the 1st contract in either mix/ on the blockchain.Obviously i have watchers,etc.

Is it normal ? Should i make custom Events on my 2nd contract for functions on the first contract ?

How do you guys usually proceed ?

Edit better example since i messed up the first one :

contract metaCoin { 
  mapping (address => uint) public balances;
  function metaCoin() {
    balances[msg.sender] = 10000;
  }
  event ExampleEvent(uint x);
  function sendToken(address receiver, uint amount) returns(bool successful){
    if (balances[msg.sender] < amount) return false;
    balances[msg.sender] -= amount;
    balances[receiver] += amount;
    ExampleEvent(balances[receiver]);
    return false;
  }
}

contract coinCaller{
  function sendCoin(address coinContractAddress, address receiver, uint amount){
    metaCoin m = metaCoin(coinContractAddress);
    m.sendToken(receiver, amount);
  }
}

When calling CoinCaller.Sendcoin. ExampleEvent won't trigger even with a watcher on the MetaCoin Contract.

9
  • That doesn't look like valid Solidity code to me. What is MyCallback, and why do you expect it to be able to call the calling contract? Apr 13, 2016 at 15:24
  • Mycallback is a callback in contract #1 , it's wrapped in a function " doSomething" that get called in contract #2, inside "exampleFunction". When eXamplefunction get called by the user , it call the fonction from contract #1 (that do other things before the cb obv). It works. Only the callback doesn't get triggered when i have a watcher on contract #1 callbacks. I'm not sure what doesn't look valid to you as it's only basic solidity , i've just quickly retyped an example case so maybe there are typos, other than that i'm not sure what you mean.
    – user697
    Apr 13, 2016 at 19:58
  • as a general rule of thumb you'll get better answer by posting correct code as people might want to try it out. It's kind of difficult here
    – euri10
    Apr 14, 2016 at 4:41
  • Yes i know. I'm just wondering if people know if callback are getting triggered when called from another contract i wasn't really asking for a fix to my contract. The example was provided to illustrate my question.
    – user697
    Apr 14, 2016 at 4:42
  • @user697 But the example isn't complete - it doesn't work, so there's no way for us to tell whether the problem is your code or something else. Apr 14, 2016 at 8:47

2 Answers 2

2

Alright. Now. Your events should be logged in solidity but you have to call the event in JS to access the logged information. There's a whole section on these things in the web3 api. https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events

6
  • 1
    or you can pass the contract by address
    – Paul S
    Apr 13, 2016 at 22:37
  • Good point. You could do that too.
    – VoR0220
    Apr 13, 2016 at 22:50
  • I'm already using mix/christeh tool. It's mostly working , just the callback doesnt work. It's setup properly. The contract calling contract is in the same file under the #1 contract. I'm already refering to the contract by address. instance = eXample(address) . As i said already everything is working fine function wise. It's just the callback that doesn't trigger in JS. Everything else works perfectly fine.I'll add comment to the code so you can understand it better.
    – user697
    Apr 14, 2016 at 4:30
  • can you use a more specific example of your code with proper variables put in? Currently it's a bit of a mess and I'm having some difficulty helping you because I have to go and rewrite your code with some major assumptions along the way. Your callback should be a function no? Or did you mean to write it as an event? Just please...show us a little more code so we can help you.
    – VoR0220
    Apr 14, 2016 at 5:18
  • ohh i see now why you don't understand. Yes my callback is an Event. My bad. I don't know why i kept calling events callbacks. I meant events not callbacks. I'll clean everything up
    – user697
    Apr 14, 2016 at 5:52
1

msg.sender is the sender of current call.

tx.origin is the sender of the full call chain.

In the metaCoin example, you should use tx.origin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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