0

I'm coding a contract factory that will generates a lot of contracts and each contract will receive the constructor below:

 constructor(
    string memory _name,
    string memory _symbol,
    string memory docHash
) ERC20(_name, _symbol) {
    name = _name;
    addHashes(docHash);
}

I will pass an parameter in constructor called "docHash" and it should be added in an array using a function that I already coded as "addHashes". However, each contract will receive a different quantity of hashes, It can be 1 hash, 2 hashes, 3 hashes or more and all hashes must be added in the array.

How can I code to constructor receive variable quantities of hashes?

1
  • 1
    You could accept an array of string as input paramter.
    – Ismael
    Commented Nov 8, 2022 at 22:13

1 Answer 1

0

You could do a constructor that checks each hash and if the hash length is > 0 then call the addHashes function.

That way, if you pass a hash that's not null, the function is called, and if the hash is null, it is not called.

You can't pass a variable amount of parameter but you can pass '0x' as a null byte

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.