1

I'm trying to create a spl token on solana testnet using the following code.

export async function createToken(walletKeyPair: Keypair) {
    const umi = createUmi('https://api.testnet.solana.com');
    const myKeypair = umi.eddsa.createKeypairFromSecretKey(walletKeyPair.secretKey);
    const myKeypairSigner = createSignerFromKeypair(umi, myKeypair);
    umi.use(keypairIdentity(myKeypairSigner)).use(mplTokenMetadata());

    console.log('MPL_TOKEN_METADATA_PROGRAM_ID', MPL_TOKEN_METADATA_PROGRAM_ID);

    const mint = generateSigner(umi);
    await createAccountWithRent(umi, {
        newAccount: mint,
        space: 50,
        programId: MPL_TOKEN_METADATA_PROGRAM_ID,
    }).sendAndConfirm(umi);

    console.log('Account created: ', mint.publicKey);

    const mintAccount = await umi.rpc.getAccount(mint.publicKey);
    assertAccountExists(mintAccount);

    const builder = createAndMint(umi, {
        mint: mint.publicKey,
        creators: [{ address: myKeypair.publicKey, verified: false, share: 100 }],
        payer: umi.payer,
        updateAuthority: umi.identity,
        authority: umi.identity,
        name: 'tokenName',
        symbol: 'tokenSymbol',
        uri: 'https://www.google.com',
        sellerFeeBasisPoints: percentAmount(90),
        decimals: 9,
        amount: 10_000,
        tokenOwner: umi.identity.publicKey,
        tokenStandard: TokenStandard.Fungible,
    });

    const response = await builder.sendAndConfirm(umi);

    console.log(response);
}

I know this could be done manually by using other libraries but im curious if it could be done like this. The mint account gets created and the actual createAndMint fails with the following error:

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Failed to serialize or deserialize account data: Unknown
    at Connection.sendEncodedTransaction (/Users/user/Github/repo/node_modules/@solana/web3.js/src/connection.ts:5922:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/Users/user/Github/repo/node_modules/@solana/web3.js/src/connection.ts:5881:20)
    at async Object.sendTransaction (/Users/user/Github/repo/node_modules/@metaplex-foundation/umi-rpc-web3js/src/createWeb3JsRpc.ts:327:25)
    at async TransactionBuilder.sendAndConfirm (/Users/user/Github/repo/node_modules/@metaplex-foundation/umi/src/TransactionBuilder.ts:359:23)
    at async createToken (/Users/user/Github/repo/src/utils/create.token.ts:59:22)
    at async main (/Users/user/Github/repo/src/index.ts:6:5) {
  logs: [
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]',
    'Program log: Error: BorshIoError',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 3505 of 400000 compute units',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: Failed to serialize or deserialize account data: Unknown'
  ]
}

Udpate: just tried this implementation https://www.quicknode.com/guides/solana-development/spl-tokens/how-to-create-a-fungible-spl-token-with-the-new-metaplex-token-standard and I get the same error

1 Answer 1

2

I think the problem is that you're creating the mint account beforehand. The create_v1 instruction will create the mint account for you and if it does not exist, it will check if the account is of a certain structure by de-serializing -- this is where I think your code fails.

So try removing the createAccountWithRent call in your code.

2
  • should I use createMetadataAccountV3? I mean latest stuff from metaplex Commented Dec 13, 2023 at 18:44
  • I get the same error when removing createAccountWithRent Commented Dec 13, 2023 at 18:48

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.