1

Is there a way for a user to mint SPL tokens into two accounts, such that the total supply is 1000, and during the minting process, 500 tokens are minted into one account and 500 into another?

I'm attempting to mint tokens in this manner, but it's not working.

//get ATA
    const tokenATA1 = await getAssociatedTokenAddress(mintKeypair.publicKey, destinationWallet);
    const tokenATA2 = await getAssociatedTokenAddress(mintKeypair.publicKey, secondWallet.publicKey);

txInstructions.push(
        SystemProgram.createAccount({ //createAccount
            fromPubkey: payer.publicKey,
            newAccountPubkey: mintKeypair.publicKey,
            space: MINT_SIZE,
            lamports: requiredBalance,
            programId: TOKEN_PROGRAM_ID,
        }),
        createInitializeMintInstruction( //Create min instruction
            mintKeypair.publicKey,
            mintDecimals,
            mintAuthority,
            null,
            TOKEN_PROGRAM_ID
        ),
        createAssociatedTokenAccountInstruction( //create ATA first account
            payer.publicKey,
            tokenATA1,
            payer.publicKey,
            mintKeypair.publicKey,
        ),
        createAssociatedTokenAccountInstruction( //create second one account
            payer.publicKey,
            tokenATA2,
            payer.publicKey,
            mintKeypair.publicKey,
        ),
        createMintToInstruction( //create min instruction first account
            mintKeypair.publicKey,
            tokenATA1,
            mintAuthority,
            mintAmount
        ),
        createMintToInstruction( //create min instruction second account
            mintKeypair.publicKey,
            tokenATA2,
            mintAuthority,
            mintAmountBuyer
        ),
        createCreateMetadataAccountV3Instruction({
            metadata: metadataPDA,
            mint: mintKeypair.publicKey,
            mintAuthority: mintAuthority,
            payer: payer.publicKey,
            updateAuthority: mintAuthority,
        }, {
            createMetadataAccountArgsV3: {
                data: mainTokenMetadata,
                isMutable: true,
                collectionDetails: null,
            }
        }),
    )

update error

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 3: Provided seeds do not result in a valid address
    at Connection.sendEncodedTransaction (/home/umaid/Blockchain/Blockchain/Solana/create-spl-token/node_modules/@solana/web3.js/src/connection.ts:5922:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/home/umaid/Blockchain/Blockchain/Solana/create-spl-token/node_modules/@solana/web3.js/src/connection.ts:5881:20)
    at async Connection.sendTransaction (/home/umaid/Blockchain/Blockchain/Solana/create-spl-token/node_modules/@solana/web3.js/src/connection.ts:5829:14) {
  logs: [
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
    'Program log: Instruction: InitializeMint',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2919 of 1399850 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]',
    'Program log: Create',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: GetAccountDataSize',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1595 of 1390068 compute units',
    'Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Initialize the associated token account',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeImmutableOwner',
    'Program log: Please upgrade to SPL Token 2022 for immutable owner support',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 1383455 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeAccount3',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4214 of 1379575 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 21853 of 1396931 compute units',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]',
    'Program log: Create',
    'Program log: Error: Associated address does not match seed derivation',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 4957 of 1375078 compute units',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Provided seeds do not result in a valid address'
  ]

3
  • Could you please add the error your are getting?
    – Jonas H.
    Jan 31 at 12:37
  • check-update plz
    – Maidi
    Jan 31 at 12:41
  • Yeah check my answer, looks like its the wrong deriviation of the second ATA
    – Jonas H.
    Jan 31 at 12:45

1 Answer 1

1

Looks like the owner of the ATA2 needs to ne another public key. The one that you derive the ATA of. You used payer for both.

It needs to be

createAssociatedTokenAccountInstruction( //create second one account
            payer.publicKey,
            tokenATA2,
            secondWallet.publicKey,
            mintKeypair.publicKey,
        ),
3
  • Error: Cannot sign with non signer key 2jE2bbdq555MXsqvgsQAXsRAVVJWWYn64m5C6GfKjiKH -> when I sign with ATA2 owner.
    – Maidi
    Jan 31 at 12:45
  • first parameter need to be payer and third the other wallet you want to send it to. Please add the code where you find the ATAs
    – Jonas H.
    Jan 31 at 12:47
  • HI, @jonas - kindly check I update the AtA's.
    – Maidi
    Jan 31 at 13: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.