Issue with Ownable(initialOwner)

Hi all,

Running into an issue when trying to deploy an ERC-1155 token through a Factory contract. The logic of my contracts is as below.

I call this function below through my factory which in effect calls the ERC-1155 token constructor code below it.

function deployERC1155(address initialOwner, string memory _contractName, string memory _uri, string[] memory _names, uint[] memory _ids) public returns (address) {
    ERC1155Token t = new ERC1155Token(initialOwner, _contractName, _uri, _names, _ids);
    return address(t);
}

While the ERC-1155 constructor code looks like this:

constructor(address initialOwner, string memory _contractName, string memory _uri, string[] memory _names, uint[] memory _ids) Ownable(initialOwner) ERC1155(_uri) {
    setURI(_uri);
}   

Now, i've taken unrelated logic from both functions and only kept what's vital for explanation. I've found out that the setURI(_uri) function fails because it does not have the correct owner.

Now, I can get the code to work if i adjust the Ownable(initialOwner) to Ownable(msg.sender) but without it, when i try to set initialOwner during my function call to deployERC1155 it reverts.

From OP docs, I can see that im setting the access control correctly (link) via

constructor(address initialOwner) Ownable(initialOwner)

But i am unsure why it is not setting the address I set as the owner, as the setURI function fails.

Any insight is appreciated.

There is no such function in the ERC1155 contract.

There is function _setURI (which, BTW, doesn't have any restrictions whatsoever).

So please share the code of your setURI(_uri) function.

In my ERC1155 contract, the setURI code is as follows:

function setURI(string memory newuri) public onlyOwner {
    _setURI(newuri);
}

I did also see it in the OP 1155 Codebase here - https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol

Please provide the following details:

  1. The input values which you are passing to function deployERC1155
  2. The account with which you are executing function deployERC1155
  3. The account with which you are executing function setURI

I already investigated this to know that the input values being passed to 1. are valid.

  1. The account calling deployERC1155 is also the deployer of the Factory (also same address im setting as initialOwner in the deployERC1155 arguments.

  2. I'm not calling setURI individually, its being called in the constructor of the ERC1155 which is created through the factory contract when calling deployERC1155.

My realization is that when I call deployERC1155 and use the Factory contract address as initialOwner it works (txn mines succesffully), this tells me the owner of the ERC1155 is the contract owner, however im explicitly setting my wallet address as the initialOwner argument so IDK why its being overridden.

Your question is a mess.

As I have pointed out in my very first response:

  • There is no such function in the ERC1155 contract.
  • There is function _setURI, which, doesn't have any restrictions whatsoever.

So the problem most certainly doesn't come from the constructor of the ERC1155 contract.

Please post ALL the relevant details - and ONLY the relevant details - within a single coherent paragraph, which one can use in order to follow your steps EASILY and reproduce the problem.