2

I want to mint an SPL fungible token, but when I tried to mint it, I encountered issues with my metadata. Should I upload separate metadata for this?

https://solscan.io/token/5vHo6Sh55T1iQsPGfNngHghpotuWVEkdzCmcCFbkQrbg?cluster=devnet#analysis

I followed the Quicknode Guide to mint the token.

https://www.quicknode.com/guides/solana-development/spl-tokens/token-2022/transfer-fees?_gl=1*sni6uq*_ga*MTQ4MzI1ODI5MS4xNjcyNjQyMTY1*_ga_DYE4XLEMH3*MTcwNjI1NDg2OS4xMDIuMS4xNzA2MjU1NjYxLjYwLjAuMA..

3 Answers 3

3

You need to create a metadata file and host your Token ICON.if you have created the token with token-22 then you need to follow the below code.

token_metadata.js

import { createV1, updateV1, Collection, Creator, Uses, CreateV1InstructionAccounts, CreateV1InstructionData, TokenStandard, CollectionDetails, PrintSupply, UpdateV1InstructionAccounts, Data } from "@metaplex-foundation/mpl-token-metadata";
import * as web3 from "@solana/web3.js";
import { PublicKey, createSignerFromKeypair, none, percentAmount, publicKey, signerIdentity, some } from "@metaplex-foundation/umi";
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { fromWeb3JsKeypair, fromWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters';
import * as bs58 from "bs58";

const SPL_TOKEN_2022_PROGRAM_ID: PublicKey = publicKey(
    'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'
);


export function loadWalletKey(keypairFile: string): web3.Keypair {
    const fs = require("fs");
    const loaded = web3.Keypair.fromSecretKey(
        new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
    );
    return loaded;
}

const INITIALIZE = false;
async function main() {
    console.log("Metadata Updation Started 🛠️ ");
    const myKeypair = loadWalletKey("authorityWallet.json");
    const mint = new web3.PublicKey("Token-Mint_address");

    const umi = createUmi("https://api.devnet.solana.com");
    const signer = createSignerFromKeypair(umi, fromWeb3JsKeypair(myKeypair))
    umi.use(signerIdentity(signer, true))

    const ourMetadata = { // TODO change those values!
        name: "Asvoria",
        symbol: "ASV",
        description: "Asvoria’s utility token is $ASV, which will be used as the default currency in Asvoria’s entire ecosystem consisting of the metaverse, NFT marketplace, and other upcoming ventures.",
        uri: "https://gist.githubusercontent.com/0xlazytron/a625b73ac8589cbe55da9c66a05c28b7/raw/521d2c0ee1045073495df784c0e552faecf9ad6b/metadata.json",
    }
    if (INITIALIZE) {
        const onChainData = {
            ...ourMetadata,
            // we don't need that
            sellerFeeBasisPoints: percentAmount(0, 2),
            creators: none<Creator[]>(),
            collection: none<Collection>(),
            uses: none<Uses>(),
        }
        const accounts: CreateV1InstructionAccounts = {
            mint: fromWeb3JsPublicKey(mint),
            splTokenProgram: SPL_TOKEN_2022_PROGRAM_ID
        }
        const data: CreateV1InstructionData = {
            ...onChainData,
            isMutable: true,
            discriminator: 0,
            tokenStandard: TokenStandard.Fungible,
            collectionDetails: none<CollectionDetails>(),
            ruleSet: none<PublicKey>(),
            createV1Discriminator: 0,
            primarySaleHappened: true,
            decimals: none<number>(),
            printSupply: none<PrintSupply>(),
        }
        const txid = await createV1(umi, { ...accounts, ...data }).sendAndConfirm(umi);
        console.log(bs58.encode(txid.signature))
    } else {
        const onChainData = {
            ...ourMetadata,
            sellerFeeBasisPoints: 0,
            creators: none<Creator[]>(),
            collection: none<Collection>(),
            uses: none<Uses>(),
        }
        const accounts: UpdateV1InstructionAccounts = {
            mint: fromWeb3JsPublicKey(mint),
        }
        const data = {
            discriminator: 0,
            data: some<Data>(onChainData),
            updateV1Discriminator: 0,
        }
        const txid = await updateV1(umi, { ...accounts, ...data }).sendAndConfirm(umi);
        console.log(bs58.encode(txid.signature))
    }


}

main();
0
2

Another option is to use the token metadata extension that's available directly inside of the token-2022 mint. When initializing your mint, you'll need to run:

$ spl-token create-token --enable-metadata --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb

And then to initialize the metadata, you can run:

$ spl-token initialize-metadata <MINT_ADDRESS> <NAME> <SYMBOL> <URI>

And from there, you can update your metadata:

$ spl-token update-metadata <MINT_ADDRESS> <KEY> <VALUE>
0

using createV1 function you can upload metadata for token 2022:

const { signature } = await createV1(umi, {
      mint: publicKey(mint.publicKey),
      authority: umi.identity,
      name: 'My Token',
      symbol: '$MTO',
      splTokenProgram: publicKey(TOKEN_2022_PROGRAM_ID.toBase58()),
      uri: '...',
      sellerFeeBasisPoints: percentAmount(5.5),
      tokenStandard: TokenStandard.Fungible,
    }).sendAndConfirm(umi);
2
  • Thanks,, but I want to upload from the frontend. I'm facing issue uploading from frontend
    – Bobz
    Commented Mar 23 at 16:38
  • this is code for front end, you can go to metaplex and check how to create Umi for wallet adapter for your react / netxt js app Commented Mar 25 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.