# Unable to deploy upgradable smart-contract tutorial on Polygon testnet using hardhat

**URL:** <https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888>\
**Category:** Upgrades\
**Created:** [August 12, 2021, 1:32pm UTC](https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888 "2021-08-12T13:32:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![metadata](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@metadata](https://forum.openzeppelin.com/u/metadata)\
**Post date:** [August 12, 2021, 1:32pm UTC](https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888/1 "2021-08-12T13:32:55Z")

</div>

Hello All, I'm following [this](https://docs.openzeppelin.com/learn/upgrading-smart-contracts) tutorial for learning about How to deploy upgradable SC. Everything went well till `upgrades.deployProxy` script. But when I'm trying to deploy `upgradeProxy` then I'm getting below error.

Please **note** that I'm using `polygon-testnet` instead of `localhost`.

**Error**

```auto
Upgrading Box...
HardhatError: HH110: Invalid JSON-RPC response received: {"error":{"details":"Internal RPC Error. Try again after some time..","code":-32005},"jsonrpc":"2.0","id":6}
    at Object.parseJsonResponse (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/hardhat/src/internal/util/jsonrpc.ts:47:11)
    at HttpProvider._fetchJsonRpcResponse (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/hardhat/src/internal/core/providers/http.ts:173:14)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at HttpProvider.request (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)
    at Object.getStorageAt (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/@openzeppelin/upgrades-core/src/provider.ts:47:19)
    at getEip1967Storage (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/@openzeppelin/upgrades-core/src/eip-1967.ts:32:17)
    at Object.getAdminAddress (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/@openzeppelin/upgrades-core/src/eip-1967.ts:9:19)
    at getUpgrader (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/@openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:50:26)
    at Proxy.upgradeProxy (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/node_modules/@openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:35:23)
    at main (/home/alpha/GoWorkspace/src/github.com/metadata/solidity/openzeppelin_upgrdabale_sc/scripts/upgrade_box.js:13:3)

```

**Hardhat-config.js**

```auto
require("@nomiclabs/hardhat-waffle");
require('@nomiclabs/hardhat-ethers');
require('@openzeppelin/hardhat-upgrades');

// for using .env file which contains private info. 
require('dotenv').config();
const POLYGON_TEST_PRIVATE_KEY = process.env.POLYGON_TEST_PRIVATE_KEY;
const POLYGON_TEST_API_KEY = process.env.POLYGON_TEST_API_KEY;

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
 
  defaultNetwork: "polygon_test",
  networks: {
    hardhat: {
    },
  
    polygon_test: {
      url: `https://rpc-mumbai.maticvigil.com/v1/${POLYGON_TEST_API_KEY}`,
      chainId: 80001,
      // If "auto" is used, the gas limit will be automatically estimated. Default value: "auto"
      gas: "auto",
      // Its value should be "auto" or a number. This parameter behaves like gas. Default value: "auto"
      gasPrice: "auto",
      accounts: [`0x${POLYGON_TEST_PRIVATE_KEY}`],
      // You can use this field to set extra HTTP Headers to be used when making JSON-RPC requests. It accepts a JavaScript
      // object which maps header names to their values. Default value: undefined
      //httpHeaders: '',
      timeout: 20000
    }
  },
  solidity: {
    version: "0.8.4",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts"
  },
  mocha: {
    timeout: 20000
  }
};

```

**Contracts**  
_ **Box.sol** _

```auto
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract Box {
    uint256 private _value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 value);

    // Stores a new value in the contract
    function store(uint256 value) public {
        _value = value;
        emit ValueChanged(value);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return _value;
    }
}

```

_ **deploy-box.js** _

```auto
const hre = require("hardhat");

async function main() {
  // We get the contract to deploy
  const Box = await hre.ethers.getContractFactory("Box");
  const box = await Box.deploy();

  await box.deployed();

  console.log('Box deployed to:', box.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

```

_ **deploy-proxy.js** _

```auto
// scripts/deploy_upgradeable_box.js
const { ethers, upgrades } = require('hardhat');

async function main () {
  const Box = await ethers.getContractFactory('Box');
  console.log('Deploying Box...');
  const box = await upgrades.deployProxy(Box, [42], { initializer: 'store' });
  await box.deployed();
  console.log('Box deployed to:', box.address);
}

main()
.then(() => process.exit(0))
.catch(error => {
  console.error(error);
  process.exit(1);
});

```

_ **BoxV2.sol** _

```auto
// contracts/BoxV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract BoxV2 {
    // ... code from Box.sol
    uint256 private _value;

    event ValueChanged(uint256 value);

    // The onlyOwner modifier restricts who can call the store function
    function store(uint256 value) public {
        _value = value;
        emit ValueChanged(value);
    }

    function retrieve() public view returns (uint256) {
        return _value;
    }
    // Increments the stored value by 1
    function increment() public {
        _value = _value + 1;
        emit ValueChanged(_value);
    }
}

```

_ **deploy-upgradeProxy-box.js** _

```auto
// scripts/upgrade_box.js
const { ethers, upgrades } = require('hardhat');

async function main () {
  
  // the address of our proxy contract from when we deployed our Box contract  
  const proxyAddress = '0x4e4660AAc4aC123d881B6DD6dF7Fb884c82264ED';

  const BoxV2 = await ethers.getContractFactory('BoxV2');
  console.log('Upgrading Box...');

  await upgrades.upgradeProxy(proxyAddress, BoxV2);
  console.log('Box upgraded');
}

main().then(() => process.exit(0)).catch(error => {
    console.error(error);
    process.exit(1);
});

```

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [August 12, 2021, 6:15pm UTC](https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888/2 "2021-08-12T18:15:24Z")

</div>

Have you confirmed that the RPC endpoint is working? Try some other operation like `await ethers.provider.getBlockNumber()`.

---

<div class="post-metadata">

**Author:** ![metadata](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@metadata](https://forum.openzeppelin.com/u/metadata)\
**Post date:** [August 13, 2021, 6:13am UTC](https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888/3 "2021-08-13T06:13:47Z")

</div>

Yes, RPC is working fine. Below is the snippet.

```auto
> await ethers.provider.getBlockNumber()
17575626

```

---

<div class="post-metadata">

**Author:** ![metadata](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@metadata](https://forum.openzeppelin.com/u/metadata)\
**Post date:** [August 13, 2021, 1:59pm UTC](https://forum.openzeppelin.com/t/unable-to-deploy-upgradable-smart-contract-tutorial-on-polygon-testnet-using-hardhat/13888/4 "2021-08-13T13:59:31Z")

</div>

@frangio found same [issue](https://forum.openzeppelin.com/t/hardhat-upgrade-failing-with-hh110-on-matic-testnet/12911) and after changing the rpc endpoint It worked.
