You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I was rewriting my contract and came across with this issue.
useNft seems to be requesting a uri method which isn't present in ERC721 storage and this results in an error.
Reproduction
Here's the contract code:
// SPDX-License-Identifier: MITpragma solidity^0.8.6;
import"@openzeppelin/contracts/token/ERC721/ERC721.sol";
import"@openzeppelin/contracts/access/Ownable.sol";
import"@openzeppelin/contracts/utils/Counters.sol";
import"@openzeppelin/contracts/utils/math/SafeMath.sol";
import"@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import"hardhat/console.sol";
contractMyNFTisERC721, Ownable, ERC721URIStorage {
event Mint(uint256id);
event Claim(uint256id);
uint256public constant MAX_TOKENS =50;
uint256private constant PRICE =50000000000000000;
using SafeMathforuint256;
using Countersfor Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("MyNFT", "MNFT") {}
function _burn(uint256tokenId)
internaloverride(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}
function tokenURI(uint256tokenId)
publicviewoverride(ERC721, ERC721URIStorage)
returns (stringmemory)
{
returnsuper.tokenURI(tokenId);
}
// Mint an NFT and add URI to itfunction mint(stringmemorytokenURI_) public onlyOwner returns (uint256) {
_tokenIds.increment();
uint256 tokenId = _tokenIds.current();
_safeMint(msg.sender, tokenId);
require(tokenId <= MAX_TOKENS, "Sold out!");
console.log(tokenId);
_setTokenURI(tokenId, tokenURI_);
return tokenId;
}
// Claim and mint NFTfunction claim(uint256id) externalpayable {
require(msg.value== PRICE, "Claiming an NFT costs 0.05 ETH");
require(id <= MAX_TOKENS, "Cannot claim non-existent token");
// Transfer to sellersafeTransferFrom(address(this), msg.sender, id);
emitClaim(id);
}
// withdraw bobuxfunction withdraw() public onlyOwner {
uint256 balance =address(this).balance;
payable(msg.sender).transfer(balance);
}
function transferTo(addressacc, uint256id) public onlyOwner {
safeTransferFrom(msg.sender, acc, id);
}
}
Dapp code:
importReact,{useEffect}from'react'import{Contract,utils}from'ethers'import{useOnboard}from'use-onboard'import{useNft,NftProvider}from'use-nft'constcontractAddress='COPY_ADDRESS_FROM_HARDHAT_DEPLOY_SCRIPT'functionNFT(){const{ loading, error, nft }=useNft(contractAddress,'1')console.log(nft)// nft.loading is true during load.if(loading)return<>Loading…</>// nft.error is an Error instance in case of error.if(error||!nft)return<>{error.message}</>// You can now display the NFT metadata.return(<section><h1>{nft.name}</h1><imgsrc={nft.image}alt=""/><p>{nft.description}</p><p>Owner: {nft.owner}</p><p>Metadata URL: {nft.metadataUrl}</p></section>)}constApp=()=>{const{ selectWallet, address, isWalletSelected, disconnectWallet, balance, provider }=useOnboard({options: {networkId: 1337,networkName: 'localhost'}})return(<div>{<buttononClick={async()=>{if(isWalletSelected)disconnectWallet()elseawaitselectWallet()}}>{isWalletSelected ? 'Disconnect' : 'Connect'}</button>}<p>Address: {address}</p><p>Balance: {balance} ETH</p>{isWalletSelected&&provider&&(<NftProviderfetcher={['ethers',{ethers: { Contract },
provider
}]}><NFT/></NftProvider>)}</div>)}exportdefaultApp
The error I see:
eth_call
Contract call: MyNFT#<unrecognized-selector>
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0x2e13f7644014f6e934e314f0371585845de7b986
Error: Transaction reverted: function selector was not recognized and there's no fallback function
I used to check with supportsInterface() before calling either tokenURI() or uri(), but it was having a few downsides, see #90. I changed the behavior so that both methods are now called in parallel, with the first successful one being accepted.
Hello, I was rewriting my contract and came across with this issue.
useNft
seems to be requesting auri
method which isn't present in ERC721 storage and this results in an error.Reproduction
Here's the contract code:
Dapp code:
The error I see:
Workaround
I came up with this function to fetch NFTs:
The text was updated successfully, but these errors were encountered: