0

I have a contract A that inherits the following contracts:

contract NftTemplate is
    Initializable,
    ERC721Upgradeable,
    ERC721URIStorageUpgradeable,
    AccessControlUpgradeable,
    INftTemplate

I want to call the "safeTransferFrom" of this contract from another one. In the other contract called "B" I'm importing the interface INftTemplate. This is the interface:

//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;

interface INftTemplate {
    function safeMint(
        address to,
        string memory _uri,
        bool _isTransferable //onlyRole(MINTER_ROLE)
    ) external;

    function getNextTokenIdCounter() external view returns (uint256);

    function isNftTransferable(uint256 _tokenId) external view returns (bool);

    function contractURI() external view returns (string memory);

    function contractOwner() external view returns (address);

    function safeTransferFromWrapper(
        address _from,
        address _to,
        uint256 _tokenId
    ) external;

    function safeTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId
    ) external;

    function getType() external view returns (string memory);
}

This is the safeTransferFrom function of contract A:

    function safeTransferFrom(address _from, address _to, uint256 _tokenId) public override (ERC721Upgradeable, INftTemplate, IERC721Upgradeable) {
        safeTransferFrom(_from, _to, _tokenId);
    }

This causes errors when safeTransferFrom is called:

     Error: Transaction reverted and Hardhat couldn't infer the reason.
    at NftTemplate.safeTransferFrom (contracts/NftTemplate.sol:179)

I'm trying to call the function like so:

INftTemplate(collectionAddress).safeTransferFrom(
            msg.sender,
            address(this),
            _itemInfo.idInCollection
        );

1 Answer 1

2

I think you have created an infinite loop in contract A, since safeTransferFrom is calling itself. If you wanted to call safeTransferFrom of the inherited contract, you should use the super keyword like:

function safeTransferFrom(address _from, address _to, uint256 _tokenId) public 
  override (ERC721Upgradeable, INftTemplate, IERC721Upgradeable) {
        super.safeTransferFrom(_from, _to, _tokenId);
}

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.