What makes the v2 transactions of Solana better than the original? How can we use these transactions using solana/web3.js lib?
1 Answer
Before we get started, I must note that the distinction you're asking about is that between ‘legacy’ transactions (ie. those that have no version) and v0 transactions (ie. the first version number in the line of versioned transactions).
v0 Solana transactions introduced a feature called address lookup tables, designed to save space in transactions that could be better put to use holding signatures and/or instructions.
In a legacy transaction, you must include the 32-byte address of all referenced accounts. v0 transactions let you evict non-signer addresses into the data of a separate account owned by the Address Lookup Table Program.
Given the existence of such an address lookup table account, transactions that wish to reference the addresses contained within need only include the 32-byte address of the lookup table account, and the 1-byte indices of the addresses within.
All in all, this increases the number of accounts you can reference in an given transaction from 32 to 256.
Read much more about the origin of v0 transactions here. Read more about the implementation of lookup tables here.