where from did you get that tokenURI function? from what standard is this particular function?
I found everything I needed to know here: https://docs.ethers.io/v5/single-page/#/v5/getting-started/ and then wrote the code.
it looks like there is an issue with what interfaces that contract implements
curl --request GET \
--url 'https://deep-index.moralis.io/api/v2/nft/0x95a11AaA0d61f5e390eFa5c0495B89816A2821b6/metadata?chain=goerli' \
--header 'X-API-Key: API_KEY_HERE' \
--header 'accept: application/json'
=>
{
"token_address": "0x95a11aaa0d61f5e390efa5c0495b89816a2821b6",
"name": null,
"symbol": null,
"contract_type": "ERC1155",
"synced_at": null
}
meaning that is detected as ERC1155 and not as ERC721, and that tokenURI function name is specific to ERC721 and not to ERC1155
Okay so I think I figured out what is wrong. In the ERC-1155 contract I deployed there was no โuriโ function implemented that would override the one in the imported ERC-1155.sol contract. So Iโm guessing when you query for token metadata and token URI, you use the โuriโ method to query which is built on the assumption that one uses id substitution. So in normal cases it shall return a base uri with the token ID such as โhttps://centralizedStorage.comโ + {id}. That base uri is passed in the constructor upon contract deployment and set in the method โsetUriโ in the ERC-1155 contract where it sets the private tokenUri variable. But I donโt used that since Iโm storing NFTs on IPFS, decentralized storage which does not work with id substitution. Therefore, when querying my contract for that variable, it is null, since i never define the variable. So what I did was writing a function that overrides the โuriโ function, and returns a unique IPFS uri as such:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract ST1155 is ERC1155 {
mapping(uint => string) public tokenURI;
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC1155("") {}
function mint(address to, uint id, uint amount) public {
_mint(to, id, amount, "");
}
function mintNew(address to, uint amount, string memory _uri, address) public {
uint256 id = _tokenIdCounter.current();
_tokenIdCounter.increment();
_mint(to,id,amount, "");
tokenURI[id] = _uri;
emit URI(_uri, id);
}
// The following functions are overrides.
function uri(uint256 id) public view virtual override returns (string memory) {
return tokenURI[id];
}
function supportsInterface(bytes4 interfaceId) public view override(ERC1155, AccessControl, ERC2981) returns (bool) {
return super.supportsInterface(interfaceId);
}
So now when I queried my contract through the function:
const result = await Moralis.Web3API.token.getAllTokenIds({chain: "mumbai", address: "myAddress"});
console.log(result);
I got the following response:
I can see that Moralis convert the uri there to go through your gateway also. Cause the uri I passed in did not contain โmoralis.io:2053/โ for example.
yes, it looks like you figured it out