Can't initialize state variable in proxy contract on deployment in UUPS pattern

I wrote the following proxy contract:

contract ExampleContract is Initializable, UUPSUpgradeable, OwnableUpgradeable {
  uint public counter;

  function initialize(uint _counter) public initializer {
    counter = _counter;

  function _authorizeUpgrade(address) internal override onlyOwner {

Then deployed it with Truffle migration script on Ganache:

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const ExampleContract = artifacts.require('ExampleContract');

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

When I look at 'counter' variable in the deployed contract on Ganache, its value is 0, while it's supposed to get to 100. Does this mean initialize() function is not running during deployment?

Hi, welcome to the community! :wave:

I think if you want to use the UUPS pattern, you should specify it, cause there are two patterns: Transparent Proxy and UUPS. And maybe you can have a look at this tutorial:

You must be looking at the wrong address. Try printing the counter variable directly inside the migration. You should see the value is 100.

In the migrations output you will see the address for a contract called "ExampleContract". This is not the address that you should be using. You should look for the "Proxy" contract and use its address. You can also use ExampleContract.deployed(), which should return an instance connected to the proxy.