How to interact with proxy and ProxyAdmin contracts using Truffle console?

Oleg K asked on Telegram

I want to interact with instances of deployed ProxyAdmin and AdminUpgradeability proxy, try to trigger some methods on them and just play around. The guide which you linked does not show how to do it. Ideally it should be something like: let instance = await ProxyAdmin.deployed(), but it does not work like this because those are not loaded into truffle console by default.


Using the following tutorial as a base: OpenZeppelin Truffle Upgrades: Step by Step Tutorial

Once the upgradeable contract has been deployed to the network e.g. to development network

$ npx truffle migrate --network development

Copy the artifacts from node_modules for the ProxyAdmin and the AdminUpgradeabilityProxy

$ cp node_modules/@openzeppelin/upgrades-core/artifacts/* build/contracts

Using the console and the addresses specified in .openzeppelin/\<network>.json

$ npx truffle console --network development
truffle(development)> box = await Box.deployed()
truffle(development)> (await box.retrieve()).toString()
truffle(development)> proxyAdmin = await"0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B")
truffle(development)> proxy = await

We can then interact with the ProxyAdmin

truffle(development)> await proxyAdmin.owner()

Whilst the admin for our proxy is the ProxyAdmin we can only interact with the proxy as a non-admin (via box).

There is an open issue to provide an instance of ProxyAdmin in the admin module

1 Like

From Telegram

Big thanks, @abcoathup, this is exactly what I’ve needed!

Thank you @abcoathup,
One thing is still a little confusing me, how to know which address in the .openzeppelin/\<network>.json will be the one put to ?

1 Like

Hi @ThomasEnder,

The admin address is in the network file:

  "admin": {
    "address": "0x...",
    "txHash": "0x..."

You can also use proxyAdmin = await admin.getInstance();

1 Like

A post was split to a new topic: Withdraw from upgradeable contract