Creating custom NFT attributes with solana-web3 SDK: How to set name, symbol, URI, and decimals?

I’m working on an NFT project using the solana-web3 SDK. I’ve managed to create a mint using splToken.Token.createMint, and I can see the transaction in the explorer. But I’m stuck on how to add custom attributes to my NFT.

Here’s what I want to do:

  • Set a name for my NFT
  • Add a symbol
  • Include an image URI
  • Specify the number of decimals

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 my code:

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

await tokenMint.mintTo(
  account.address,
  userWallet.publicKey,
  [],
  1000000000
);

How can I modify this to include the NFT attributes I want? Any help would be awesome!

hey luna, i used metaplex js sdk for similar. it lets u set nft metadata (name, symbl, uri). call createMetadata with your details and it works. give it a try and lmk!

To set custom attributes for your NFT on Solana, you must work with the metadata programs rather than just the token creation process. The Metaplex Foundation provides tools that let you define properties such as name, symbol, URI, and decimals. After minting your token, you need to create a separate transaction to add the metadata. The metadata transaction should be signed with the same wallet used during minting, and it is important to verify its success and handle any errors that might occur.

Hey Luna_Dreamy! that’s a cool project you’re working on :blush: i’ve been playing around with NFTs on solana too, and i totally get your frustration. have you checked out the @metaplex-foundation/js sdk? it’s been a game-changer for me when it comes to adding those custom attributes you mentioned.

here’s a quick tip: after you create your mint, you can use the metaplex sdk to add metadata. something like:

const { Metaplex } = require('@metaplex-foundation/js');
const metaplex = Metaplex.make(connection);

await metaplex.nfts().create({
  uri: 'https://your-metadata-uri.com',
  name: 'My Awesome NFT',
  sellerFeeBasisPoints: 500, // 5%
  symbol: 'AWESOME',
});

this should let you set the name, symbol, and uri. for decimals, you’ve already got that covered in your createMint call (the ‘9’ parameter).

what kind of nfts are you making? i’d love to hear more about your project!