Is it possible to create associated token account and transfer token to that token account at the same time in one transaction?
-
Does this answer your question? Is it possible to make an ATA in one instruction, then use that created ATA in the next instruction, in a single transaction?– mikemaccana ♦Commented Jan 31, 2023 at 22:40
-
Thanks @mikemaccana but this question has already been answered below!– Muhit RaihanCommented Feb 11, 2023 at 8:02
-
As you note in you comment, the answer below doesn't show where 'associatedDestinationTokenAddr' comes from, whereas the answers to the question above do.– mikemaccana ♦Commented Feb 11, 2023 at 13:40
-
1Gotcha. Well I was already familiar with the methods so I understood as soon as I saw the comment! But yes the other answer you mentioned is detailed. Thank you for that!– Muhit RaihanCommented Feb 12, 2023 at 15:27
Add a comment
|
1 Answer
Yes
In Solana, a transaction
is a list of instructions.
allocating data
is an instruction, token transfer
is an instruction etc...
In this case you need an
- associated token account instruction
- transfer token instruction
example with @solana/web3.js
let tx = new Transaction().add(
// create nonce account
Token.createAssociatedTokenAccountInstruction(
mintToken.associatedProgramId,
mintToken.programId,
mintPublicKey,
associatedDestinationTokenAddr,
destPublicKey,
wallet.publicKey
)
// init nonce account
Token.createTransferInstruction(
TOKEN_PROGRAM_ID,
fromTokenAccount.address,
associatedDestinationTokenAddr,
wallet.publicKey,
[],
amount
)
);
console.log(
`txhash: ${await connection.sendTransaction(tx, [feePayer,
nonceAccount])}`
);
You can find the example here
-
1