4

I would like to ask you a question about the Proxy Patterns. Suppose I published an erc20 token contract(version1) and also I am using Proxy contract. If I change or add a new function the this logic contract (version2). will I change the ABI (version1's ABI)? I saw it didn't change in a few places when the upgrade process.. I'm confused...

Thank you,

2 Answers 2

2

Strictly speaking the ABI never changes for a contract. The ABI tells what the contract is capable of.

What is a proxy contract

What the ABI doesn't say is what the different functions actually do. And that's where the proxy contract comes in play: it uses its functions to delegate functionality to another contract. So a proxy contract is a middleman which forwards transactions to the right functional contract. You give everyone address to the proxy contract and they always use the same proxy contract.

Let's say we have a proxy contract at address A and another contract (with actual functionality) at address B. The proxy contract relays all transactions coming to address A to address B. So the proxy contract has functionality which basically just forwards transactions onwards.

If you want to change functionality in conctract B you deploy a new contract with new functionality. As it's a new contract its address has to change so let's call its address C. Then you tell the proxy contract at address A to change its foward address to address C. After that the contract at address B becomes useless as nobody uses it anymore.

ABI never changes for an address

So for one contract address the ABI always remains the same. But with a proxy contract it's possible to change the contract which actually performs all the functionality: you can deploy a completely new contract with a new address and its ABI may be completely different. Then you just change the address of the contract in the proxy contract so the proxy contract forwards the transactions to a new contract address.

So if you want to "add a function" to a contract it's technically impossible but what you need to do is deploy a new contract with the new function and point the proxy contract to use that.

In the case of a proxy contract the ABI is not very useful in describing functionality. But the good thing is that you never need to update the ABI as it always remains the same for the proxy contract.

3
  • This is technically not correct. Proxy is a just a transparent step that delegates the calls to an actual contract which ABI might change if the contract is upgraded. Commented Apr 24, 2020 at 20:59
  • Thank you Lauri, I have a question still and I would like to ask for understand better. My question is that; if I add a new function in version 2 (my second published logic contract) will I still not change? because ABI is not an interface? If I don't change the ABI from web3 client, can I use the new function? what will ABI do then?
    – sollover
    Commented Apr 24, 2020 at 21:06
  • Thanks @MikkoOhtamaa for the comment. I now updated my answer to try to make it more clear about which contract's ABI may change. Yasemin Please see my updated answer Commented Apr 25, 2020 at 12:15
0

ABI defines how your contract can be called. If you are, for example, using OpenZeppelin upgradable proxy, then you can add new methods in the contract v2. Because there are new methods, naturally the ABI needs to change, as those methods are not present in the ABI v1.

1
  • Hey Mikko, thank you for your response. @Lauri says the ABI will not change too. I m so confused
    – sollover
    Commented Apr 24, 2020 at 21:22

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.