Unable to call new methods on upgraded proxy contract

I am attempting to call a function that only exists on an upgraded contract by executing the following in Truffle Develop:

migrate
foo = await FooV1.deployed()
await foo.Bar()

I get the error foo.Bar is not a function. The code to reproduce is of course highly simplified. I understand that upgradeProxy returns a proxy that I can call on. But I wish to call methods later in Truffle Develop. How can I do this?

:1234: Code to reproduce

FooV1

contract FooV1 {}

FooV2

contract FooV2 {
    function Bar() public {}
}

Migrations

const FooV1 = artifacts.require("FooV1");
const FooV2 = artifacts.require("FooV1");

const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');

module.exports = async function (deployer) {
  const proxy = await deployProxy(FooV1, [], { deployer });
  await upgradeProxy(proxy.address, FooV2, { deployer });
};

:computer: Environment

Truffle v5.4.15 (core: 5.4.15)
Solidity - ^0.8.0 (solc-js)
Node v14.18.0
Web3.js v1.5.3

If Bar is a function on "V2" you should get the contract using FooV2.deployed().

I already tried that, but I get the error FooV2 has not been deployed to detected network (network/artifact mismatch).

In that case new FooV2(foo.address) should give you access to FooV2 functions.

1 Like

Thanks, that works! :rocket: