0

I have a proxy contract ( Openzeppelin proxy ) and a custom Logic contract.

the logic contract has a method

function asd() public pure returns(uint256){
    return 5;
  }

since the proxy has a fallback that delegates the calls to the logic contract, I was expecting to be able to call something like

proxy.asd()

from truffle console, but that's not the case since I get an error proxy.asd is not a function

I think I am missing some beginner information here, thank you for your help

1 Answer 1

0

should someone have this problem, this was the solution.

Better understanding truffle contract abstraction is the key.

If you have something like this migration:


const Box = artifacts.require("Box");
const ERC1967Proxy = artifacts.require("ERC1967Proxy")


module.exports = async function(deployer) {
    await deployer.deploy(Box)
    const boxInstance = await Box.deployed()

    await deployer.deploy(ERC1967Proxy, boxInstance.address, "0x")
    proxyInstance = await ERC1967Proxy.deployed()

    console.log('BOX: ', boxInstance.address);
    console.log('Proxy: ', proxyInstance.address);
}

then from the console you'll have available Box and ERC1967Proxy

In order to properly access the Box methods via the proxy you need to use BOX abi, called on the proxy address, so:

let box_via_proxy = await Box.at("0xPROXY_ADDRESS")

this allows you to use Box method called on the proxy contract, which will use the original box code via the fallback function of ERC19267

2
  • Got an error saying Box.at is not a function.
    – Maxareo
    Jul 18, 2022 at 5:38
  • it's difficult to identify the issue without the code, try opening a new question , there is probably some small mistake somewhere
    – Stormsson
    Jul 19, 2022 at 12:01

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.