1

I've got one Ethereum smart contract which calls functions of the other one. How could I track these calls using web3js or some other tool if it is possible at all? I need it because I want to execute some JavaScript (or other non-solidity language) code after receiving such call and then call other function of first smart contract so the sequence of calls should be following:

  1. Smart contract N1 calls N2 smart contract function.
  2. JavaScript (or other non-solidity language) code catches this call and execute some code.
  3. Smart contract N2 calls back N1 using data from previous step.

Could anybody help with it?

1
  • I think you can use javascript as the bridge. You use javascript to calll a function in contract N1 to call N2, then listen by the call. When it receives the confirmation and execute the code, javascript call contract N2 to call N1. Both contracts needs to have a function to call the other contract, otherwise I think it is not possible. Commented Feb 16, 2022 at 12:19

2 Answers 2

0

What you are trying to archive is contrary to the design principles of Solidity and the blockchain. The answer to the question Why can't contracts make API calls? will pretty much explain why.

In short words: If you would open up Solidity to call arbritrary non Solidity code it would become non-deterministic as that non Solidity code would not exist outside of the blockchain and could be modified independently.

3
  • I understand it, but solution like oraclize.it exists and is successful. I need something like this. Commented May 27, 2018 at 7:14
  • An oracle and what you are asking for isn't exactly the same. Basically, what an Oracle does it to send certain data from the outside world onto the blockchain, while making an API call would be just the other way round. Notice the difference? Maybe you have to re-think what you are trying to achieve or at least explain a bit more details.
    – TorstenS
    Commented May 27, 2018 at 10:11
  • Also possibly check the code samples at docs.oraclize.it/#ethereum-quick-start. Or you should ask a different question probably which would be: How to write my own oracle on the blockchain?
    – TorstenS
    Commented May 27, 2018 at 10:13
0

Contract N1 interfaces method A in contract N2.

Once method A in contract N2 successfully executes, it logs an event on the blockchain and it passes as argument the output of the method.

You then use a service which monitors your contracts events (such as Openzeppelin Defender Sentinels) to catch the events of your contract, send you a webhook, parse the json of the webhook extract the parameter that was passed with the event that you want to pass to N1 and use the output of method N2 to then call using web3.py contract N1.

Alternatively, you can simply interface method 1 N2 in method 1 N1, and return the value as a normal return variable without any inbetween off chain stuff happening and this would all be on chain which is better and cheaper.

Your Answer

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

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