0

I have deployed my NFT and marketplace smart contracts on Mumbai Testnet chain. When I interact with the smart contract using my Mumbai testnet account everything works fine. But when I use any other network account like rinkeby to mint an NFT through the contract it gets reverted for public read-only functions.

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="tokenCount()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.2)

Here is my contract:

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract NFT is ERC721URIStorage {
    uint public tokenCount;
    constructor() ERC721("DApp NFT", "DAPP"){}
    function mint(string memory _tokenURI) external returns(uint) {
        tokenCount ++;
        _safeMint(msg.sender, tokenCount);
        _setTokenURI(tokenCount, _tokenURI);
        return(tokenCount);
    }
}

the mint() function works regardless of the network been connected while tokenCount() works only when I am connected to mumbai testnet

Should I deploy my contracts to rinkeby network chain as well and interact with that contract in case a user has connected his rinkeby network account for minting an NFT or there is any other way for doing so?

6
  • Any etherum like network should behave similarly. From the error message it seems the call failed the provider didn't return the expected output (perhaps an uint?). Without more details it could be that the address or the ABI are wrong, the provider is connected to the wrong network, the provider is out of sync with the blockchain, a network connectivity issue. You could try switching to another provider, checking the address and abi, use a different connection wifi/4g, etc.
    – Ismael
    Commented May 21, 2022 at 18:54
  • @Ismael I don't think if address or ABI are wrong since it is working fine when I do the transaction using mumbai testnet. Using different connection also doesn't help. "the provider is connected to the wrong network" - Can you explain what do you mean by that? Commented May 22, 2022 at 3:58
  • Can you share that tokenCount() function you are using too?
    – Sky
    Commented May 22, 2022 at 6:56
  • @Sky tokenCount is a member variable of the NFT contract. To access value of tokenCount, tokenCount() function is created by solidity compiler implicitly. Refer here : docs.soliditylang.org/en/v0.8.14/… Commented May 22, 2022 at 9:03
  • So you have this contract deployed on two different networks, and it works on one of them, but not on the other? Mint() function works in both cases, but tokenCount() works only on mumbai testNet?
    – Sky
    Commented May 22, 2022 at 12:21

1 Answer 1

0

It seems you have only deployed the contract on Polygon Mumbai and not on Rinkeby.

Error on calling read-only public functions

There's a weird thing that writes/sendTransaction do not fail if they're sent to an address that is not a contract. While the reads/eth_calls fails as you're experiencing.

Should I deploy my contracts to rinkeby network chain as well and interact with that contract in case a user has connected his rinkeby network account for minting an NFT or there is any other way for doing so?

If you wish to support rinkeby as well, you can just deploy contracts on that chain. However note that the addresses of deployed contracts can be different. Hence while creating the ethers.Contract object you'd have to see the chainId and use correct addresses for the network. Also there are so many networks: ropsten, goerli, kovan,... it doesn't mean you have to support every chain. If user connects to a different chain, you can simply show error to user to please switch to the network you support, i.e. Polygon Mumbai.

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.