3

Is posibble create spl-token not 2022, using @solana/spl-token-metadata? If possible please help me how to create that

1

1 Answer 1

2

With @solana/spl-token-metadata, you can only add metadata to the Token Extensions (previously token 2022) program using the metadata pointer extension.

For spl-token program, you can use a library like Metaplex to incorporate Token Metadata.

Here's how you can do it using umi and mpl-token-metadata

Install required dependencies

npm install \
  @metaplex-foundation/umi \
  @metaplex-foundation/umi-bundle-defaults \
  @solana/web3.js \
  @metaplex-foundation/mpl-token-metadata \

Use the CreateAndMint function to create your token.

import {
    generateSigner,
    keypairIdentity,
    percentAmount,
    publicKey,
} from "@metaplex-foundation/umi";
import {
    createAndMint,
    mplTokenMetadata,
    TokenStandard,
} from "@metaplex-foundation/mpl-token-metadata";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";


const umi = createUmi(clusterApiUrl("devnet"));

const keypair = umi.eddsa.createKeypairFromSecretKey("YOUR 8-BIT ARRAY SECRET KEY");

umi.use(keypairIdentity(keypair)).use(mplTokenMetadata());

async function createAndMintFungible() {
    const mint = generateSigner(umi);

    // mint token
    let umiTX = await createAndMint(umi, {
        mint,
        authority: umi.identity,
        name: "Solana Gold",
        symbol: "GOLDSOL",
        uri: "https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json",
        sellerFeeBasisPoints: percentAmount(0),
        decimals: 6,
        amount: 1_000_000,
        tokenOwner: umi.identity.publicKey,
        isMutable: false,
        tokenStandard: TokenStandard.Fungible,
    }).buildWithLatestBlockhash(umi);

    // sign with the mint address and provider
    let signedTX = await signTransaction(umiTX, [mint, umi.identity]);

    //convert to web3 js TX
    const web3TX = toWeb3JsTransaction(signedTX);
    let txHash = await conn.sendTransaction(web3TX);
    console.log(txHash);
}

createAndMintFungible().then().catch(console.error);

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.