How can I set custom attributes for my Solana NFT using the splToken.Token.createMint function?

I’m working on creating an NFT on Solana using the web3 SDK. I’ve managed to mint a token with splToken.Token.createMint, and I can see the transaction in the explorer. But I’m stuck on how to add custom attributes like name, symbol, and image URI to my NFT.

I’ve looked into metaplex and token-metadata standards, but there’s not much info out there for Solana. Can anyone point me in the right direction?

Here’s a simplified version of what I’ve done so far:

const mint = await splToken.Token.createMint(
  connection,
  wallet,
  wallet.publicKey,
  null,
  9,
  splToken.TOKEN_PROGRAM_ID
);

await mint.mintTo(
  tokenAccount.address,
  wallet.publicKey,
  [],
  1000000000
);

How do I add the custom attributes to make it a proper NFT? Any help would be awesome!

yo SophiaAtom88, i feel ya on the solana nft struggle! :sweat_smile: so here’s the deal: u need the metaplex sdk to add those cool attributes. it’s like the secret sauce for nfts on solana. install it with npm, then use createMetadata to link ur token with the attributes. don’t forget to host ur metadata json somewhere too! lmk if u need more help, nft fam :rocket:

hey there SophiaAtom88! :raised_hands: i’ve been messing around with solana nfts too and ran into the same issue. it’s a bit tricky at first, right? :sweat_smile:

so, the thing is, you can’t just use splToken.Token.createMint to set those custom attributes. what you need is the metaplex sdk - it’s like the secret sauce for solana nfts!

have you tried installing the metaplex sdk yet? if not, give it a shot:

npm install @metaplex-foundation/js

once you’ve got that, you can use it to add all those cool attributes to your nft. it’s kinda like adding frosting to a cake :cake:

btw, what kind of nft are you making? sounds interesting! maybe we could bounce some ideas off each other? i’m always looking for new inspiration for my nft projects :blush:

oh, and don’t forget to host your metadata json somewhere like arweave or ipfs. that’s where you’ll put all the juicy details about your nft!

let me know if you need any more help or just wanna chat about nft ideas. this stuff is so fun to explore!

Creating NFTs on Solana with custom attributes requires a bit more than just minting a token. You’ll need to use the Metaplex SDK alongside the web3.js and SPL Token libraries. Here’s a high-level overview of the process:

  1. Create the token as you’ve done.
  2. Generate metadata for your NFT, including name, symbol, and URI.
  3. Use Metaplex’s createMetadata function to associate the metadata with your token.

The URI should point to a JSON file hosted somewhere (like IPFS) that contains more detailed information about your NFT, including the image link.

Here’s a rough outline of the code:

const { Metadata } = require('@metaplex-foundation/mpl-token-metadata');
const { PublicKey } = require('@solana/web3.js');

// After minting your token
const metadata = {
  name: 'My NFT',
  symbol: 'MNFT',
  uri: 'https://arweave.net/xxx', // Link to your metadata JSON
};

await Metadata.create(
  connection,
  wallet,
  mint.publicKey,
  wallet.publicKey,
  wallet.publicKey,
  metadata
);

This should get you started. Remember to handle errors and check for successful transactions!