Error: Contract TruffleContract does not have a function Initialize

I CREATED a simple new smart contract to deploy proxies

but proxies not deploying

ERROR Error: Contract TruffleContract does not have a function Initialize

:computer: Environment
truffle5, truffle-upgrades plugin
:memo:Details
when i made “npxtruffle deploy” it show this error
ERROR Error: Contract TruffleContract does not have a function Initialize

:1234: Code to reproduce
solidity simple code
// SPDX-License-Identifier: UNLICENSE
pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "./utils/ContextUpgradeable.sol";
import "./proxy/utils/Initializable.sol";
import "./OwnableUpgradeable.sol";
import "./ERC20Upgradeable.sol";
import "./utils/math/SafeMathUpgradeable.sol";


contract Zoe_cash_v1 is Initializable, OwnableUpgradeable,ERC20Upgradeable {
   
    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;   

    function Initialize(uint256 _minsupply)  internal initializer {
        __ERC20_init("ZOE CASH", "ZOE");
        _minsupply = 100000000 ether;
    }
}

migration code

const Zoe_cash_v1 = artifacts.require('Zoe_cash_v1');
 
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
 
module.exports = async function (deployer) {
  await deployProxy(Zoe_cash_v1, [""], { deployer, initializer: 'Initialize' });
};
2 Likes

Hey!
Although you have a function named Initialize, but it is an internal function, as for what is a internal function, I think you can look at the documentation:

Internal functions can only be called inside the current contract (more specifically, 
inside the current code unit, which also includes internal library functions and
inherited functions) because they cannot be executed outside of the 
context of the current contract.

so if you want to call it, you should use public or external like this:

function Initialize(uint256 _minsupply)  public initializer {
        __ERC20_init("ZOE CASH", "ZOE");
        _minsupply = 100000000 ether;
    }
2 Likes

Hi @Guard_Colombia,

As an aside, please see the documentation on installing and usage OpenZeppelin Contracts upgradeable, as you appear to have copied the contracts locally:

https://docs.openzeppelin.com/contracts/4.x/upgradeable

Hi, I have the same error: "Error: Contract TruffleContract does not have a function initialize.

I am following step-by-step the Learn section on OpenZeppelin docs.

I have installed all packages and libraries as per the tutorial, including pointing to OwnableUpgradeable.sol.

UPDATE:----

Seems I fixed it now by updating the Box.sol contract by adding the initializer:

Not sure if this is really clear from the learning material…unless I have missed something.

Hi, welcome! :wave:

I think just like the error message, you should have a function named initialize, as for the modifier initializer, maybe it is not necessary.

ok brother if need i can send my migrations and truffle contig but the problem is when you are using upgradeable token info,

you need set all the information in your deploy.js like “name,symbol,addres,supply” in the same order if the order are incorrect, then js will not work

Sorry, I am not sure what do you mean, or could you please share your scripts?

// scripts/deploy.js
async function main() {
const [deployer] = await ethers.getSigners();
console.log(
"Deploying contracts with the account:",
deployer.address
);
console.log("Account balance:", (await deployer.getBalance()).toString());
const NATURALCOIN = await ethers.getContractFactory("NATURALCOIN");
const Zoe = await NATURALCOIN.deploy();
console.log("Token address:", Zoe.address);
const name = "NATURAL COIN";
const symbol = 'NCS';

//SUPPLY INICIAL // WALLET EQUIPO //WALLET ECOSISTEMA // WALLET ECOSISTEMA //WALLET AIRDROP // STAKING // error initialize contract
const proxy = await upgrades.deployProxy(NATURALCOIN, [name,symbol,"13000000000000000000000000","0xF1413338f7522488110371305EeC34595E8F2C24","0x1b559a8a5a4D7CdD3Ee75D20f96cf0D6Eb163332","0xd25dC82Cd5Ee99152f56594049Ee0f70E63D8553","0x244bB738651cd830237d2dD1FE65e63F9A6a289A","0x7e336610458528792D4a1CdC671C1E5D7664bB17"], { initializer: 'initialize' });
console.log("proxy deployed to:", proxy.address);
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
const MINTER_ROLE = web3.utils.soliditySha3('MINTER_ROLE');
const PAUSER_ROLE = web3.utils.soliditySha3('PAUSER_ROLE');
}

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

Yeah, you are right, we should keep the order of the parameters right.