0

I have the following module:

function createPoap(m: IgnitionModuleBuilder) {

  const proxyAdminOwner = m.getAccount(0);

  const name = m.getParameter('name');
  const symbol = m.getParameter('symbol');

  const poapContract = m.contract('Poap', [
    name,
    symbol,
    proxyAdminOwner
  ]);

  // Initialize
  const baseUri = m.getParameter('baseUri');
  m.call(poapContract, "initialize", [baseUri, []]);

  return { poapContract };
}

And I am getting this error:

Poap#Poap.initialize:
 - IGN710: Function 'initialize' is overloaded in contract Poap. Please use one of these names instead:

 - initialize()
 - initialize(string,address[])
 - initialize(address)

But when I changed it to the function I want to execute (initialize(string,address[])) I get:

IgnitionError: IGN702: Module validation failed with reason: The function name "initialize(string,address[])" is invalid, make sure you use a valid identifier.

How can I execute that function?

2 Answers 2

1

This seems to be an existing problem. I've reached out to their support team and they asked me to open this issue.

Meanwhile, I was able to find an alternative solution which is by using deploy and loadFixture using module.

Here's the JS code for the same:

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
const { loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { ignition } = require("hardhat");

const OverloadSumModule = buildModule("OverloadSumModule", (m) => {
  const overloadSum = m.contract("OverloadSum");
  return { overloadSum };
});

async function deployContractFixture() {

  const { overloadSum } = await ignition.deploy(OverloadSumModule);

  return { overloadSum };
}

async function interact() {

  const { overloadSum } = await loadFixture(deployContractFixture);

  let sum;

  sum = await overloadSum['sum(uint256,uint256)'](1, 2);

  console.log('Sum when calling sum(uint256,uint256):', sum);

  sum = await overloadSum['sum(uint256[])']([1, 2]);

  console.log('Sum when calling sum(uint256[]):', sum);

}

interact();

module.exports = OverloadSumModule;

In your case, the overloaded calls would be like:

await poapContract['initialize()']()

await poapContract['initialize(address)']('0x0000000000000000000000000000000000000000')

await poapContract['initialize(string,address[])']('stringArg', ['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000001'])

But now, instead of running it using:

npx hardhat ignition deploy ./ignition/modules/YourModuleFilename.js

You've to run it using:

node ignition/modules/YourModuleFilename.js

NOTE: As, @Falcon Stakepool has mentioned in the comments, this solution seems to be working only in case of Local Hardhat Network.

7
  • Thank you so much. I have mentioned your issue in this conversation for more visibility: github.com/NomicFoundation/hardhat-ignition/pull/31. In the meantime, I will try to implement your temporary solution. My experience with Ignition has not been the best lately: every time I have to use it is because somebody else decided to include it in their codebase and I keep finding bugs again and again. Commented May 21 at 4:41
  • 1
    Yeah, that’s mainly because it’s still in development phase. Commented May 21 at 5:18
  • You’re welcome, @FalconStakepool. Happy coding! Commented May 21 at 5:19
  • Hey @SYED ASAD KAZMI, I found an issue with your temporary solution: I think it doesn't work if you test outside a network that is not Hardhat Network. I am getting OnlyHardhatNetworkError: This helper can only be used with Hardhat Network. You are connected to 'localhost'. when I want to use loadFixture. More info here: github.com/NomicFoundation/hardhat/issues/3788 Commented May 23 at 9:27
  • 1
    Oh okay, thanks for pointing out. Let me add that info to the answer. Commented May 23 at 16:49
1

As @SYED-ASAD-KAZMI pointed out, there is a bug with overloaded function calls in Ignition. While he kindly suggested a temporary solution for this problem, the use of loadFixture function only works in Hardhat Network.

Looking for a more comprehensive solution that works in every network, I finally decided to completely remove Ignition modules for smart contract deployment from my project and replace it by Hardhat scripts.

This is what I ended up having:

const parameters = require("../parameters.json");
const { ethers } = require("hardhat");

async function main() {
  const accounts = await ethers.getSigners();

  // Deploy PaimaL2Contract
  const PaimaL2 = await ethers.getContractFactory("PaimaL2Contract");
  const paimaL2 = await PaimaL2.deploy(accounts[0], 1);

  await paimaL2.waitForDeployment();

  console.log("PaimaL2Contract deployed to: ", await paimaL2.getAddress());

  // Deploy Poap
  const Poap = await ethers.getContractFactory("Poap");
  const poap = await Poap.deploy(parameters.Poap.name, parameters.Poap.symbol, accounts[0].address);
  
  await poap.waitForDeployment();
  await poap["initialize(string,address[])"](parameters.Poap.baseUri, []);

  console.log("Poap deployed and initialized at: ", await poap.getAddress());
  
}

main();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.