20

So instead of doing something like:

contract Parent {
...
}

contract Child is Parent {
...
}

Can the Parent be declared referencing an already deployed contract?

contract Parent = 0x123123123...

contract Child is Parent {
...
}
eth
  • 85,679
  • 53
  • 285
  • 406
Fernando Tiberti
  • 2,299
  • 1
  • 15
  • 28

3 Answers3

13

No, the compiler cannot determine the ABI of the Parent contract from the bytecode on the blockchain, so this will not work.

Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118
  • Would it be even theoretically possible to make a compiler that could determine ABI from the parent or that ABI is passed to the compiler so it can reuse deployed bytecode. Thinking about millions of the same smart contracts deployed over and over, so same bytecode is used so many times and clogs up the blockchain. – Blissful Sep 05 '22 at 09:29
1

Given that you might be able to repurpose an existing contract as described here I guess this might work with some work-arounds. I think this would be very interesting to explore but cannot give details.

SCBuergel
  • 8,774
  • 7
  • 38
  • 69
0

https://docs.rulerprotocol.com/ This protocol continuously issues new tokens which have the same behavior (same functions), and only different names. In its implementation , it clones a parent token using library Clones, which interacts with the Ethereum Virtual Machine using inline assembly.

  • 1
    It just creates a proxy targeting the deployed contract, it doesn't add extra functionality to consider as inheritance. – Ismael May 19 '21 at 03:09
  • Like Ismael pointed out, this isn't a case of inheritance from a deployed contract – Linum Labs May 19 '21 at 10:04