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.

Hi,

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()
undefined
truffle(development)> (await box.retrieve()).toString()
'42'
truffle(development)> proxyAdmin = await ProxyAdmin.at("0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B")
undefined
truffle(development)> proxy = await AdminUpgradeabilityProxy.at(box.address)
undefined

We can then interact with the ProxyAdmin

truffle(development)> await proxyAdmin.owner()
'0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'

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 https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/173

2 Likes

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 ProxyAdmin.at() ?

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

i need your help, i lost the original files from my token. and its admin by proxy, and i having problems transfer_ownership, how i can recreate project from 0