0
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract newToken is ERC1155{
    using Counters for Counters.Counter;
    Counters.Counter private _nftIds;
    constructor(string memory _uri)ERC1155(_uri){

    }
    function mint(uint _amount,string memory  _uri)public returns(uint){
       _nftIds.increment();
       uint currentId=_nftIds.current();
       _mint(msg.sender,currentId,_amount,"");
       _setURI(_uri);
        return currentId;
    }
    function transfer(address _to,uint _id, uint _amount)public returns(bool success){
        safeTransferFrom(
         msg.sender,
         _to,
         _id,
         _amount,
        ""
    ) ;
    return true;

    }
    

}


contract createContract{
    newToken[] contractAddress;
    mapping(address=>newToken) public contracts;

    function create(string memory _uri) public {
        newToken addr=new newToken(_uri);
        contractAddress.push(addr);
        contracts[msg.sender]=addr;
    }
    function mint(string memory _uri)public  returns(newToken)  {
        if (address(contracts[msg.sender])==address(0)){
            create(_uri);
            contracts[msg.sender].mint(1,_uri);
            return contracts[msg.sender];

        }
        else{
            contracts[msg.sender].mint(1,_uri);
            return contracts[msg.sender];
        }
        
    }

}

When I try to deploy createContract and mint I am getting an error ERC1155: transfer to non erc1155 receiver implementer means .

1

When your createContract calls the mint function on one of your newToken contracts it will become the msg.sender. Therefore it will mint a newToken to your createContract.

By definition ERC-1155 contract will check if the receiver of a token transfer is a contract and if this is the case call onERC1155Received (see ERC-1155 Token Receiver). This also applies when you mint a new token (as it is transferred). Therefore your newToken tries to call this method on your createContract contract, but this one does not implement it.

There are some ways around this. For example adding the receiver to the mint function and specify it to be the account that calls the createContract.

Currently your newToken can also be minted by anyone, so it might also make sense to make it ownable and make the createContract that is the only account that can mint the token ... but this is more a design decision on your side ;)

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.