0

I have a clonable contract which I'm passing to the clone factory contract and I'm trying to access the functions inside it but for some reason only the view functions work.

 this.nft = await NFT.new(this.user.address,"Dudu","DUD","https://dudublog.com/images/",{from:creator});
   this.nftFactory = await NFTFactory.new(this.nft.address,{from:creator});

Passing the clonable contract address to the factory creates the clones, however when I call the mint function from the clone contract, it gives me a revert error. The function was tested on the initial contract with a constructor instead of the initialize() function. This is my code so far:

  it("should mint from clone contract",async function(){
    await  this.nftFactory.createNFTContract("0x1","Gaga","TCP","https://gaga.io/");
    const contractAddressess = await this.nftFactory.getNFTAddressess();
    const nftC1 = await NFT.at(contractAddressess[0]);
    await nftC1.mintToken("https://gaga.io/","12312",{from:creator});//doesn't work
    let tokensForOwner = await nftC1.getTokensForAddress(creator);//works
    console.log(tokensForOwner.toString());
})

As far as I saw from the examples, it should work and strangely the view functions work which makes me believe that I'm either missing something or my approach is wrong. Does someone know how can I achieve this?

2
  • Can you show the contract code?
    – Ismael
    Sep 28 '21 at 4:55
  • 1
    @Ismael I eventually found the solution. Thank you for your reply though! It's nice to know I can count on the community for help!
    – Icarus23
    Sep 29 '21 at 15:09
1

I found the answer to my problem. The clone factory was missing the transferOwnership of the token contract which prevented the caller to call the functions of the clonable contract.

 function createNFTContract(bytes32 salt,string calldata name, string calldata 
 symbol,string calldata _tokenURI)external isRegisteredUser returns(address){
 NFT contractAddress = NFT(ClonesUpgradeable.cloneDeterministic(nftAddress, salt));
 contractAddress.initialize(msg.sender,name,symbol,_tokenURI);
 contractAddress.transferOwnership(msg.sender);//this was the missing piece
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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