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!

Masiar
  • 123
  • 5

1 Answers1

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

Jaime
  • 8,340
  • 1
  • 12
  • 20
  • 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 '19 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 '19 at 10:55
  • Thanks. I am afraid that asking for such a very simple example will result in many many downvotes... – Masiar Mar 11 '19 at 12:10
  • here there is an example of interaction between two contracts: https://ethereum.stackexchange.com/questions/1599/basic-example-of-interaction-between-2-contracts . Hope this helps. – Jaime Mar 11 '19 at 12:28
  • Thanks, this was very self-explanatory. I have one question though: do I have to define two contracts in the same file to be able to create an instance of the contract to be called? In the example you mentioned I see the person doing C1 c1 = C1(addrC1) but my contract won't probably know the constructor of the second contract (defined elsewhere)... – Masiar Mar 11 '19 at 12:49
  • 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 '19 at 13:08