1

I have the following function, where I want to create a fungible token using UMI.

const metadata = {
    name: "Solana Gold",
    symbol: "GOLDSOL",
    uri: "https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json",
};

const mint = generateSigner(umi);

async function createMetadataDetails() {
    await createV1(umi, {
        mint,
        authority: umi.identity,
        name: metadata.name,
        symbol: metadata.symbol,
        uri: metadata.uri,
        sellerFeeBasisPoints: percentAmount(0),
        decimals: 9,
        tokenStandard: TokenStandard.Fungible,
    }).sendAndConfirm(umi)
}

async function mintToken() {
    await mintV1(umi, {
        mint: mint.publicKey,
        authority: umi.identity,
        amount: 10_000,
        tokenOwner: umi.identity.publicKey,
        tokenStandard: TokenStandard.Fungible,
    }).sendAndConfirm(umi)
}

Currently It fails when calling mintV1. Error logs below.

      at processTicksAndRejections (node:internal/process/task_queues:95:5) {
    logs: [
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]',
      'Program log: IX: Mint',
      'Program log: Incorrect account owner',
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 8790 of 200000 compute units',
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x39'
    ]
  },
  program: {
    name: 'mplTokenMetadata',
    publicKey: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s',
    getErrorFromCode: [Function: getErrorFromCode],
    getErrorFromName: [Function: getErrorFromName],
    isOnCluster: [Function: isOnCluster]
  },
  logs: [
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]',
    'Program log: IX: Mint',
    'Program log: Incorrect account owner',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 8790 of 200000 compute units',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x39'
  ],
  code: 57
}

developer docs link

I think the createV1 isn't creating the mint account as expected.

1
  • I used the createAndMint method and was able to create to create a token! Do you know if it's possible to use this method and initialize the token with the following definition: 1-revoke freeze authority 2-revoke mint authority
    – David
    Commented Jan 16 at 21:13

3 Answers 3

1

As I told you in my previous answer's comments, I found this function (createAndMint), on Metaplex GitHub repo, that might be what you were looking for... You can set the supply with it, and it happens that you don't need to use any of the other functions, just this one; you still need the metadata, of course.

The code would look like this:

const metadata = {
    name: "Solana Gold",
    symbol: "GOLDSOL",
    uri: "https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json",
};

const mint = generateSigner(umi);

createAndMint(umi, {
    mint,
    authority: umi.identity,
    name: metadata.name,
    symbol: metadata.symbol,
    uri: metadata.uri,
    sellerFeeBasisPoints: percentAmount(0),
    decimals: 9,
    amount: 10_000,
    tokenOwner: umi.identity.publicKey,
    tokenStandard: TokenStandard.Fungible,
    }).sendAndConfirm(umi).then(() => {
    console.log("Some success message like: 0.00001 GOLDSOL (", mint.publicKey, ") minted");
});

I hope this helps

1
  • Did you tested this ?
    – benek
    Commented Dec 17, 2023 at 11:24
0

I managed to make it work using this createFungible function:

createMetadataDetails().then(() => {
  createFungible(umi, {
    mint,
    authority: umi.identity,
    name: metadata.name,
    symbol: metadata.symbol,
    uri: metadata.uri,
    sellerFeeBasisPoints: percentAmount(0),
    decimals: 9,
  }).sendAndConfirm(umi).then(() => {
      mintToken();
});

});

9
  • Can you try setting the supply using the method you used.
    – Jimii
    Commented Oct 16, 2023 at 7:09
  • @Jimii, the supply is set in the mintToken() function. You can mint whatever amount you need.
    – jmontes
    Commented Oct 17, 2023 at 8:18
  • @Jimii, kindly notice that I'm reusing the functions you already defined. I'm not replacing them
    – jmontes
    Commented Oct 17, 2023 at 9:34
  • notice that I also included that using the mintToken() and createMetadataDetails() functions are giving me an error. while using createFungible does work, it does not allow me to set the supply for my token.
    – Jimii
    Commented Oct 17, 2023 at 9:40
  • Yes, I get the same error if I just use those two functions mintToken() and createMetadataDetails(). But if I combine them with createFungible (as shown in my sniped) it works fine. You can still use mintV1 (inside mintToken()) to set the amount of tokens to mint
    – jmontes
    Commented Oct 17, 2023 at 10:20
0

The answer by jmontes is correct.

The function overload createAndMint() takes arguments to create and mint the token.

import { percentAmount, generateSigner, publicKey, PublicKey } from '@metaplex-foundation/umi';
import {  TokenStandard,  createAndMint, } from '@metaplex-foundation/mpl-token-metadata';



const mint = generateSigner(umi);



const tx = await createAndMint(umi, {
    mint,
    name,
    symbol,
    isMutable,
    decimals,
    uri,
    sellerFeeBasisPoints: percentAmount(5.5),
    authority: umi.identity,
    amount,
    tokenOwner: umi.identity.publicKey,
    tokenStandard: TokenStandard.Fungible,
  }).sendAndConfirm(umi);

Screenshot of method signature

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.