0

This may sound like a very naïve question. It's the first time I'm making interact two smart contracts (in general, I'm not very proficient with blockchain development). I have these two smart contracts, one should call the other, and the second one should first check that the call received is from the first smart contract in order to execute what it is supposed to do.

My questions are: 1) can this be done? In the constructor of both smart contracts I have to include both the addresses, but each time I truffle migrate the addresses change... 2) is this scalable? Does it make sense to model my application in a way that all the contracts are kept in mind by one single smart contract that, once it receives updates from an oracle, it updates in cascade all the contracts he is storing the addresses?

Thanks!

1

This can be done. The only thing to take in mind is to build a function in the contract that stores the address (let's call it registry) such that you can submit the addresses of the other contracts to the registry. In this way, if you have new contracts you can always update the registry.

Hope this helps

  • Oh right. So basically you are suggesting to have a function inside the "main" smart contract that is called from the outside (i.e., oracle/dapp/...) which allows the caller to store one address. That makes much more sense than my approach. Would the approach be scalable? Are there examples of this working? Thanks! – Masiar Mar 11 at 10:38
  • 1
    There should be examples. In this forum, you will find a lot of examples of communications between two smart contracts. You can also post a question asking for a script that does something basic so that you can start from there. – Jaime Mar 11 at 10:55
  • Thanks. I am afraid that asking for such a very simple example will result in many many downvotes... – Masiar Mar 11 at 12:10
  • here there is an example of interaction between two contracts: ethereum.stackexchange.com/questions/1599/… . Hope this helps. – Jaime Mar 11 at 12:28
  • 1
    you either need to have the contract, or an interface of it, In the example you could do for C1: contract C1 { function f1() public returns(uint) } As you can see only the definition of the function will be needed not the internal code. – Jaime Mar 11 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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