Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compressTransactionMessageUsingAddressLookupTables to transation-messages readme #3701

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/transaction-messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,35 @@ Given an instruction, this method will return a new transaction message with tha
If you'd like to prepend multiple instructions to a transaction message at once, you may use the `prependTransactionMessageInstructions` function instead which accepts an array of instructions.

See [`appendTransactionMessageInstruction()`](#appendtransactioninstruction) for an example of how to use this function.

## Compress transaction message using lookup tables

### Types

#### `AddressesByLookupTableAddress`

This type represents a mapping of lookup table addresses to the addresses of the accounts that are stored in them.

### Functions

#### `compressTransactionMessageUsingAddressLookupTables`

Given a transaction message and a mapping of lookup tables to the addresses stored in them, this function will return a new transaction message with the same instructions but with all non-signer accounts that are found in the given lookup tables represented by an `IAccountLookupMeta` instead of an `IAccountMeta`.

This means that these accounts will take up less space in the compiled transaction message. This size reduction is most significant when the transaction includes many accounts from the same lookup table.

```ts
import { address } from '@solana/addresses';
import { compressTransactionMessageUsingAddressLookupTables } from '@solana/transaction-messages';

const lookupTableAddress = address('4QwSwNriKPrz8DLW4ju5uxC2TN5cksJx6tPUPj7DGLAW');
const accountAddress = address('5n2ADjHPsqB4EVUNEX48xRqtnmuLu5XSHDwkJRR98qpM');
const lookupTableAddresses: AddressesByLookupTableAddress = {
[lookupTableAddress]: [accountAddress],
};

const compressedTransactionMessage = compressTransactionMessageUsingAddressLookupTables(
transactionMessage,
lookupTableAddresses,
);
```
Loading