I would like to create NFTs of a particular symbol using ERC1155 and a distinct URI for each. Apparently I cant do that with ERC1155 because it does not support symbol on the block chain. I can do away with creating a symbol attribute in my JSON in the metadata and then set the json file as token URI. The problem is then I can no longer use Moralis function getTokenMetadataBySymbol which I think is much faster than searchNFTs because search is based on metadata whereas getTokenMetadataBySymbol can directly look at the data on the chain. Using search instead of getTokenMetadataBySymbol will slow me down. Any thoughts if there is a way around this ?? Is there a possible use of โdataโ variable in the mint function of ERC1155 that I can use to achieve what I need?
if you make your own nft, you could filter by that specific smart contract address
Thanks for your reply. The issue with that is, all the minted tokens will have the same smart contract address. I want my tokens to be of a certain type that I can identify using an attribute on the chain as I was able to do that with ERC721 using name or symbol.
Hey @farhan.qureshi, unfortunately name and symbol does not comes by default in the EIP1155 which define the ERC1155 standard if you want you can define name
and symbol
function by yourself, but it will not be in anyway something that is indexable because itโs not the standard. Otherwise you can put the name and symbol of the token into the metadata (IPFS), which Moralis should be able to help your user search it with searchNFT
Web3 API
Thanks for your reply. I have spoken to my team mates and we have agreed to do as you suggested. End of the day decentralisation is more important than the ease of searchability. Many thanks for your help.
Hey @YosephKS ,
Many Thanks for your help so far. I have implemented everything as per suggestions and also looked at the moralis youtube videos. I have been able to mint tokens and set token uri on them.
The following javascript code can be run in the browser console to prove that
const options =
{
// avalanche testnet
chain: '0xa869',
address: '0xf53775413a35738bcB820304E37Ec7AcbAE52D07'
};
await Moralis.getNFTs(options);
BUT the problem is, when I use either the searchNFT or getTokenIdMetadata, I get no results.
my search code is
const options = { q: "company", chain: "0xa869", filter: "description" };
await Moralis.Web3API.token.searchNFTs(options);
and my getTokenIdMetadata code is
const options = { address: "0xdcf1e35e5347f55b2b91450c5b121f086977dc63", token_id: "1", chain: "0xa869" };
await Moralis.Web3API.token.getTokenIdMetadata(options);
I am more keen to get the search to work because otherwise I can do almost nothing in my Dapp.
Specific Details
smart contract address: 0xdcf1e35e5347f55b2b91450c5b121f086977dc63
token owner wallet address: 0xf53775413a35738bcB820304E37Ec7AcbAE52D07
Alright let me have a quick check on your request and look into the docs again looks like your code are all fine by quick glance
Hey @farhan.qureshi, I just checked testnet.snowtrace.io https://testnet.snowtrace.io/address/0xdcf1e35e5347f55b2b91450c5b121f086977dc63 and seems like this is not detected as NFT, although I can see that you seems to minted 10 token based on the events, seems like you made some modification on the contract that might not comply with the EIP712/1155 standards, which might cause it impossible to index. Let me know more of the details though because this is just my pure guess maybe showing the contract will be helpful too~
Many Thanks @YosephKS,
here is my smart contract,
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/[email protected]/token/ERC1155/ERC1155.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";
import "@openzeppelin/[email protected]/token/ERC1155/extensions/ERC1155Burnable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/utils/Counters.sol";
contract MyToken is ERC1155, Ownable, ERC1155Burnable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping (uint256 => string) private _uris;
constructor() ERC1155("") {}
function mint(string memory tokenUri, address to) public // onlyOwner "only the owner can mint"
{
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(msg.sender, newTokenId, 1, "");
_uris[newTokenId] = tokenUri;
if(msg.sender != to)
{
safeTransferFrom(msg.sender, to, newTokenId, 1, "");
}
}
function uri(uint256 tokenId) override public view returns (string memory) {
return(_uris[tokenId]);
}
}
I will never have to mint more than one token and also I need to auto increment the token ids as I do not need to do any substitutions or sell them in the market. These token are purely for a network of documents that are used for internal publishing etc.
If we can figure out what could have caused it to no longer be indexed then I can try to work my code around it. Also, by not able to index, does it mean the token id is not on the block chain ?
Some more info, anyone can mint (in the future this will be a private network with role based authorisation) and I would like to transfer the token to an address that it should belong to once its minted. So those changes are done for that reason.
Hi @YosephKS,
The queries are working without me making any changes whatsoever except that I gave it a good 3 to 4 hours since my last message. Both searchNFT and getNFTbyTokenId are returning results exactly how it should be. This is not so good because if its going to take this long for Moralis server to sync then its way too much delay from Dappโs point of view. I can obviously sync live using events etc but I do not want to rely on a database and want to keep my Dapp as light weight as possible so that more and more people can adapt my network. Is there a settings on the Moralis server to do frequent syncs? It returns all the NFTs straightaway when I use getNFTs though. Any help would be great. Thanks
can you test again today/tomorrow to see if there is still that delay? we had some problems last 2-3 days with sync in general
Many Thanks for your reply and suggestion.
I have been using it since and it has always been in sync so far. I will do some more tests tomorrow.