7

I am looking to create a bulk spl-token airdrop script using nodeJS and Solana npm packages.

I know that we can add multiple instructions to a transaction but I suppose, each instruction would have a different size.

How to calculate how many (X type of) instructions can be added to a transaction?

4 Answers 4

5

I don't think there is a limit, but every transaction must stay below 1232 bytes. So you can calculate it when you know the size of your instructions. (1232 bytes - (signers, feepayer, account keys etc) / instruction size) should give you a good idea.

3
  • That seems to be right. It throws an error when I try to send a transaction larger than 1232 bytes. However, I don't see how to get the size of a transaction before it is sent. After it is sent, I can just getTransaction, serialize it and see byteLength but the raw transaction requires to be signed...
    – Oguzhan
    Commented Sep 13, 2022 at 23:27
  • 1
    Depending on what frame work you use you should be able to call .serialize on the transaction before you send it. Then you can check the size and add either 64 or 96 bytes on top for a signature. Can read up on transaction format here: docs.solana.com/developing/programming-model/transactions
    – Jonas H.
    Commented Sep 14, 2022 at 9:12
  • Is there a page in the docs with all these limits?
    – mikemaccana
    Commented Jan 29 at 21:42
3

At a practical level, you’re limited by the total transaction size of roughly 1kb. Also, different instructions have different data dependencies so it’s impossible to give a concrete number.

I believe there is a internal instruction index that is set as a byte, so I think you’re limited to at most 256 instructions per transaction but you’ll have a hard time reaching that number due to the 1kb limit.

1

I recently solved this problem by creating 2 transactions. Let's call it tx 1 and 2.

If I added an instruction to tx 2 and serialize it successfully without an exception, I add it to tx 1.

I ran this over a loop, and found 55 instructions to be the limit for a transaction for my particular use case.

I then sign and transmit tx 1.

1
  • Yeah, got the answer in the above comment. And to find out about size, I just tried to see the size off transactions and increased number of instructions until I hit the limit. But It seems like it is also possible to get the size without sending the transaction. Didn't really look into details.
    – Oguzhan
    Commented Sep 17, 2022 at 15:56
0

A Solana transaction may have one or more instructions that each list the inputs and addresses of an on-chain application. There is no stated restriction on the size of instruction, although it should be noted that a transaction's total serialized size cannot be greater than 1232 bytes.

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.