Creating an NFT with custom attributes using Solana Web3 and SPL Token: How to set name, symbol, URI, and decimals?

I’m working on a Solana NFT project and need some help. I’ve been using the Solana Web3 docs and the splToken.Token.createMint function. I can successfully get a Transaction ID and signature, which I can view in the explorer.

But I’m stuck on how to add custom attributes to my NFT during the minting process. Specifically, I want to set the name, symbol, and image URI. I’ve looked into Metaplex and the token-metadata standard, but there’s not much info out there for Solana.

Has anyone figured this out? I’d really appreciate some guidance. Here’s a basic example of what I’ve got so far:

const connection = new web3.Connection(web3.clusterApiUrl('devnet'), 'confirmed');
const wallet = web3.Keypair.generate();

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

// How do I add name, symbol, and URI here?

Any tips or code snippets would be super helpful. Thanks!

hey there! i’m also pretty new to solana nft creation, but i’ve been playin around with it lately and might have some insights for you.

have you looked into the metaplex js sdk? it’s been super helpful for me in addin those custom attributes you’re talkin about. here’s a quick snippet of what i’ve been usin:

import { Metaplex } from '@metaplex-foundation/js';

// set up your connection and wallet first

const metaplex = Metaplex.make(connection).use(walletAdapterIdentity(wallet));

const { nft } = await metaplex.nfts().create({
  name: 'My Cool NFT',
  symbol: 'COOL',
  uri: 'https://example.com/my-nft-metadata.json',
  sellerFeeBasisPoints: 500,
});

this lets you set the name, symbol, and uri all in one go. the uri should point to a json file with more details about your nft, including the image url.

have you tried something like this? what kind of nft project are you working on? i’d love to hear more about it!

yo, i’ve been messin with solana nfts too! metaplex is the way to go for custom attributes. try this:

import { Metaplex } from '@metaplex-foundation/js';

const metaplex = Metaplex.make(connection).use(walletAdapterIdentity(wallet));

const { nft } = await metaplex.nfts().create({
  name: 'Cool NFT',
  symbol: 'COOL',
  uri: 'https://yoursite.com/nft-metadata.json',
});

this sets name, symbol, and uri in one go. the uri should point to a json with more details. good luck with ur project!

To set custom attributes for your Solana NFT, you’ll need to use the Metaplex protocol. It’s built on top of the SPL Token program and provides a standardized way to add metadata to your tokens.

First, install the Metaplex JS SDK: npm install @metaplex/js. Then, import the necessary functions and set up your connection:

import { Connection, Keypair } from '@solana/web3.js';
import { createMetadata } from '@metaplex/js';

const connection = new Connection(/* your connection details */);
const wallet = Keypair.generate();

After creating your mint, use the createMetadata function to add custom attributes:

await createMetadata({
  connection,
  metadataData: {
    name: 'My Awesome NFT',
    symbol: 'AWESOME',
    uri: 'https://example.com/my-nft-metadata.json',
    sellerFeeBasisPoints: 500,
    creators: [{ address: wallet.publicKey, share: 100 }],
  },
  mint: mint,
  mintAuthority: wallet.publicKey,
  updateAuthority: wallet.publicKey,
});

This sets the name, symbol, and URI for your NFT. The URI should point to a JSON file with additional metadata like the image URL.