Unable to migrate UUPS upgradeable contract using truffle - The requested contract was not found

Hi everyone,

I'm an aspiring solidity dev who is mostly just starting out. I'm having trouble migrating a UUPS upgradeable contract using truffle and have run out of ideas to try.

The provided code is a minimalistic example of the issue I am having. The issue arises as soon as Box inherits from Initializable and I add the initializer modifier. Before that I can deploy Box without changing the migration code, but as soon as I inherit from other contracts I start getting this error.

I've tried deleting the existing compile contracts and recompiling, using a different computer (windows 7) and this is a fresh, newly initiated truffle project - all with the same effect. Any clue what I could be doing wrong?

:computer: Environment

Ubuntu 20.04
Truffle v5.4.7 (core: 5.4.7)
Solidity - ^0.8.2 (solc-js)
Node v14.13.0

:memo: Details

When trying to migrate using truffle migrate --reset --network ganache I am getting the following:

Compiling your contracts...
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/main/side/mycontract/build/contracts
> Compiled successfully using:
- solc: 0.8.9+commit.e5eed63a.Emscripten.clang

Starting migrations...
> Network name:    'ganache'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)

-----some irrelevant migration here -----

Warning: A proxy admin was previously deployed on this network

 This is not natively used with the current kind of proxy ('uups').
 Changes to the admin will have no effect on this new proxy.

Error: The requested contract was not found. Make sure the source code is available for compilation
 at getContractNameAndRunValidation (/home/main/side/mycontract/node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:46:11)
 at Object.getStorageLayout (/home/main/side/mycontract/node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:54:41)
 at Object.deployImpl (/home/main/side/mycontract/node_modules/@openzeppelin/truffle-upgrades/src/utils/deploy-impl.ts:32:18)
 at processTicksAndRejections (internal/process/task_queues.js:93:5)
 at deployProxy (/home/main/side/mycontract/node_modules/@openzeppelin/truffle-upgrades/src/deploy-proxy.ts:46:16)
 at module.exports (/home/main/side/mycontract/migrations/2_deploy_box.js:8:4)
 at Migration._deploy (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:75:1)
 at Migration._load (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
 at Migration.run (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
 at Object.runMigrations (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
 at Object.runFrom (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
 at Object.runAll (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
 at Object.run (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
 at runMigrations (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
 at Object.run (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
 at Command.run (/home/.nvm/versions/node/v14.13.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)

:1234: Code to reproduce


// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract Box is Initializable {
 uint256 public x;

 function initialize(uint256 _x) public initializer {
     x = _x;

 function upgradeTo(address add) public {}


const Box = artifacts.require('Box');

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

module.exports = async function (deployer) {
await deployProxy(Box, [42], { deployer, kind:'uups'});



module.exports = {
networks: {
 ganache: {
   host: "",     // Localhost (default: none)
   port: 7545,            // Standard Ethereum port (default: none)
   network_id: "*",       // Any network (default: none)
   gas: 6721975,           // Gas sent with each transaction (default: ~6700000)
   // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)

mocha: {
 // timeout: 100000

// Configure your compilers
compilers: {
 solc: {
   version: "^0.8.2",    // Fetch exact version from solc-bin (default: truffle's version)

Edit: Maybe someone can point me to a repo where an upgradeable contract is deployed with UUPS? I would gladly clone and test it out locally to compare.

Managed to get it working after migrating to hardhat. No changes to my contracts were made so maybe my configuration was messed up.

1 Like