0

I have 2 ERC1155 contracts, and am looking to transfer nft2 into nft1's wallet upon checking wallet holds nft1, but not sure what I'm doing wrong.

This is my nft1 contract:

import "./NFT2.sol";

contract NFT1 is ERC1155, Ownable, ERC1155Burnable {
    string private _name;
    string private _symbol;
    address public otherContractAddress; // contract for nft2

    constructor(
        string memory uri_,
        string memory name_,
        string memory symbol_,
        address initialOwner,
        address _otherContractAddress
    ) ERC1155(uri_) Ownable(initialOwner) {
        _name = name_;
        _symbol = symbol_;
        otherContractAddress = _otherContractAddress;
    }

// setURI, mint, mintBatch functions omitted

    function openPack() public {
        uint256 tokenId = 1; 
        uint256 amount = 1; 

        require(
            balanceOf(_msgSender(), tokenId) >= amount,
            "Insufficient NFT balance"
        );

        _burn(_msgSender(), tokenId, amount);

        MyCards cardsContract = MyCards(otherContractAddress);
        cardsContract.transferCard(_msgSender());
    }

This is my NFT2 contract:

contract NFT2 is ERC1155 {
    using Strings for uint256;

    address private _owner;
    uint256 public constant CARD = 0;

    constructor()
        ERC1155(
            "https://ipfs.io/ipfs/.../{id}.json"
        )
    {
        _owner = msg.sender;
        _mint(_owner, 10, 10, "");
    }

    // URI, mint, mintBatch functions omitted

    function transferCard(address to) public {
        uint256 cardTokenId = 10;
        uint256 cardAmount = 1;

        safeTransferFrom(_owner, to, cardTokenId, cardAmount, "");
    }
}

I cannot call the openPack() function from nft1, can someone help me fix this?

1 Answer 1

0

Maybe there is no prior authorization. In the nft2 contract, the owner needs to execute setApprovalForAll(nft1, true) first. Please be specific in describing the problem you are encountering and the error you are reporting.

1
  • thank you so much! I agree the issue is most likely from approval - wondering how would you add the setApprovalForAll() portion in nft2? and do you need to authorize every user/address to run this? in the future I will try to be more specific. this time, I tested in remix and it just shows transaction failed when I try to run openPack(), so I donot know how to debug further
    – katslair
    Nov 21 at 2:50

Your Answer

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

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