Keiz_
Keiz_

Reputation: 1

Send multiple instructions with one transaction @solana/spl-token

I have a question how can i send multiple instruction with only one transaction with @solana/spl-token ?

Because i have see with @solana/web3.js i can do transaction().add(...) but not with spl-token im block with the "connection" argument

Upvotes: 0

Views: 1581

Answers (1)

psyfi-eth
psyfi-eth

Reputation: 51

You can do something like this

manualTransaction
.add(
  SystemProgram.transfer({
    fromPubkey: fromKeypair.publicKey,
    toPubkey: toKeypair.publicKey,
    lamports: 0.1 * LAMPORTS_PER_SOL,
  })
)
.add(
  SystemProgram.transfer({
    fromPubkey: fromKeypair.publicKey,
    toPubkey: toKeypair.publicKey,
    lamports: 1 * LAMPORTS_PER_SOL,
  })
);

This will allow you to send multiple instructions at once which will give you an output like in the below image

output

alternatively, you can do it by creating messages which also acts as a transaction instruction and later populate with

    Transaction.populate(messages, [
     fromPublicKey.publicKey.toString(),
   ])

Upvotes: 1

Related Questions