Get address in react from TransparentUpgradableProxy

Currently I am developing a small dapp which communicates with a smart contract. The frontend of the application is written with JavaScript (React) and I try to make my smart contract upgradable. So I have a version1 and a version2 of my contract.sol file. Whats hard for me is to get the actual implementation address of the smart contract in the react application (componentDidMount). I use the deployProxy and upgradeProxy function in the deployment scripts from Truffle.

      const networkId = await;
      const deployedNetwork = SlotMachineV2.networks[networkId];
      const instance = new web3.eth.Contract(
        deployedNetwork && deployedNetwork.address,

Above is the code which I have used before to get everything for web3.eth.Contract. SlotMachineV2 is the .json ABI of the contract. Now I want to get the current implementation address of the transparent upgradable proxy.

I have deploy my first version of the contract with:

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

const SlotMachine = artifacts.require("./SlotMachine.sol")

module.exports = async function (deployer) {
  const instance = await deployProxy(SlotMachine, { deployer });
  console.log('Deployed', instance.address);

And then I have created a new deployment script for the second version:

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

const SlotMachine = artifacts.require("./SlotMachine.sol")
const SlotMachineV2 = artifacts.require("./SlotMachineV2.sol")

module.exports = async function (deployer) {
    const existing = await SlotMachine.deployed();
    const instance = await upgradeProxy(existing.address, SlotMachineV2, { deployer });
    console.log("Upgraded", instance.address);

Hopefully someone can show me how to adjust my react code to use the proxy :slight_smile:

Hi @Patrick58, you can use the erc1967.getImplementationAddress function from the truffle-upgrades plugin to get the implementation address from the proxy.