3

I have a contract that has a fallback function to delegatecall all function calls to a different contract. I can't seem to use my typical API to interact with the contract it delegates a call to.

I have a contract called Box.sol with a retrieve function. My TransparentUpgradeableProxy proxy contract delegates all calls to that contract. However, if I call retrieve on the proxy contract, I get:

AttributeError: Contract 'TransparentUpgradeableProxy' object has no attribute 'retrieve'

Here is how the code should look

from brownie import Box, TransparentUpgradeableProxy

account = accounts[0]
print(f"Deploying to {network.show_active()}")
box = Box[len(Box) - 1]
proxy = TransparentUpgradeableProxy[len(TransparentUpgradeableProxy) - 1]
print(proxy.retrieve())

2 Answers 2

3

You need to use

  1. The actual ABI of the implementation instead of the ABI file of the proxy contract

  2. Address of the proxy contract

from brownie import Box, TransparentUpgradeableProxy, Contract

account = accounts[0]
proxy = TransparentUpgradeableProxy[-1]
proxy_box = Contract.from_abi("Box", proxy.address, Box.abi)
print(proxy_box.retrieve())
2

I found today another way to do it which is very convenient especially when fetching contracts from explorer and you don't want to bother importing its ABI.

In your case you could use:

proxy_box = Contract.from_explorer(TransparentUpgradeableProxy.address,
                                   as_proxy_for=Box.address)
print(proxy_box.retrieve())

Brownie doc about it: https://eth-brownie.readthedocs.io/en/stable/api-network.html?highlight=from_explorer#brownie.network.account.Account

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.