10

I am trying to create an NFT using web3.js and spl-token.js.

However, i need to add meta data (like the name of the token or other attributes), otherwise it just shows up as "Unknown Token" in my wallet.

This is the relevant part of the code where I am minting the token:

let mint = await splToken.Token.createMint(
    connection,
    fromWallet,
    fromWallet.publicKey,
    null,
    0,
    splToken.TOKEN_PROGRAM_ID
);

Otherwise the code is similar to the answers on this question: I would like to mint a new token on solana. How can I do this using solana-web3.js?

There does not seem to be any documentation whatsoever, except for the structure of the meta data (which I found here: https://docs.phantom.app/integrating/tokens/on-chain-metadata).

If anyone could point me in the right direction with an example or documentation it would be really much appreciated. Thank you!

Ood
  • 1,445
  • 4
  • 23
  • 43
  • 1
    Hey @Ood, did you manage to find out how? I'm trying to figure out the same thing as you, and I couldn't find any info on the internet. It would be great to let me know how you solve it! appreciate it, thanks :) – John Lim Jan 15 '22 at 00:31
  • 1
    @JohnLim Unfortunately not. We switched our project to Ethereum because of it. – Ood Jan 17 '22 at 00:08
  • I was able to somewhat get it, still don't understand why I don't see the creators in the metadata. token: [https://solscan.io/token/EsEeQE2wet3bgX6Wi6q7dwNExbYNkHV2j9ZT9wiV5r5U?cluster=devnet#metadata] – Ankit Wadhwana May 31 '22 at 10:35
  • 1
    I've asked on the Solana Stack Exchange: https://solana.stackexchange.com/questions/5524/how-do-i-mint-an-spl-token-with-custom-metadata-using-solana-web3-js-and-solan – mikemaccana Jan 28 '23 at 22:21

2 Answers2

4

In order to add metadata to NFT you need to invoke this program spl_token_metadata::instruction::create_metadata_accounts. You can find the documentation here.


PS: The example above is in Rust. To do it in JavaScript is like that:

import { Metaplex, keypairIdentity } from "@metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.use(keypairIdentity(keypair));
const mintNFTResponse = await metaplex.nfts().create({
  uri: "https://ffaaqinzhkt4ukhbohixfliubnvpjgyedi3f2iccrq4efh3s.arweave.net/KUAIIbk6p8oo4XHRcq0U__C2r0mwQaNl0gQow4Qp9yk",
  maxSupply: 1,
});

Like described here is another exemple.

olllejik
  • 1,404
  • 1
  • 10
  • 13
  • 2
    Fairly new to Solana. Is there an example of how to do this in JS? – Jareth Apr 14 '22 at 06:25
  • I voted this up, but realised after clicking the link it doesn't actually answer the question - it's in Rust rather than JS. – mikemaccana Jan 28 '23 at 21:24
  • @olllejik your example is using metaplex, the question is asking about using web3.js and spl-token.js. – mikemaccana Jan 28 '23 at 22:36
  • @mikemaccana without metaplex you can't do it on javascript. For that you need to write your own contract on rust or use another existing contract other than metaplex – olllejik Jan 29 '23 at 01:28
  • @olllejik this isn't true, see the answers at https://solana.stackexchange.com/questions/5524/how-do-i-mint-an-spl-token-with-custom-metadata-using-solana-web3-js-and-solan – mikemaccana Jan 29 '23 at 23:04
  • @mikemaccana the link that you sent me explains exactry that I told. In js they use metaplex library to add metatada to the nft. The spl-token library is used only for the mint – olllejik Jan 29 '23 at 23:55
  • @olllejik I mean without the `@metaplex-foundation/js`, I believe the question asker does too. The answer doesn't use the `@metaplex-foundation/js` (it does use one function from `"@metaplex-foundation/mpl-token-metadata"` though). `@metaplex-foundation/js` can be unstable, which I why I (and probably the the asker of this question) wish to avoid it. – mikemaccana Jan 30 '23 at 00:09
0

Create a metadata for an NFT token in Solana is quite complicated. It is because in Solana SPL-token account would not carry the Metadata. Instead, you have to create another account to carry such data. So, I suggest you to use Metaplex's Candy Machine to make your own NFT with Metadata. You may get more information from their github: https://github.com/metaplex-foundation/metaplex/

CK Chan
  • 39
  • 1
  • Thanks for the answer. I know about candy machine, but for this project it is not sufficient since we want to be able to update the meta data. – Ood Feb 04 '22 at 15:16
  • If you would like to share more, I would see if I can help. Do you mean you want to update the metadata after the NFT is minted? – CK Chan Feb 05 '22 at 07:19