1

For my particular use case i need to create an address lookup table for every user , I could not find any function that returns the address table created by an account(payer)

2 Answers 2

1

You need to store the slot number when you create an Address Lookup Table, later you can resolve the same address for the table to be able to fetch the Data

let [ix_table, table_address] = anchor.web3.AddressLookupTableProgram.createLookupTable({
            authority:  payer.publicKey,
            payer: payer.publicKey,
            recentSlot: slot
        });

if your table inited to fetch data use this :

let lookupTableAccount = (await anchor.getProvider().connection.getAddressLookupTable(table_address)).value!;
1

You can try with getProgramAccounts:

curl RPC_ENDPOINT -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getProgramAccounts",
    "params": [
      "AddressLookupTab1e1111111111111111111111111",
      {
        "encoding": "base64",
        "filters": [
          {
            "memcmp": {
              "offset": 22,
              "bytes": "AUTHORITY ADDRESS"
            }
          }
        ]
      }
    ]
  }
'

Or in web3.js:

connection.getProgramAccounts(AddressLookupTableProgram.programId, {
  filters: [
    {
      memcmp: {
        offset: 22,
        bytes: payer.publicKey,
      },
    },
  ],
});
7
  • How have u determined the offset for address lookup table program? Commented Sep 18 at 13:13
  • 1
    Yes I have inspected and calculated it from the lookup table program's source code. Commented Sep 18 at 13:28
  • Actually, I am new to solana. Can u please give me the link to the source code? I'd be thankful for a brief exlpanations too. @dev4all.sol Commented Sep 18 at 14:13
  • Here is what i've found out, but i still dont understand how u get offset 22. Slot takes 8 bytes, u8 takes 1 byte, and Option takes 8 byte. The offset should be 8 + 8 + 1 + 1 = 18 bytes. docs.rs/solana-address-lookup-table-program/1.14.17/… Commented Sep 18 at 14:16
  • 1
    @DenysRybkin it was kinda' nightmare to me. I just counted it from the last given LOOKUP_TABLE_META_SIZE=56. 56 - 2 (u16) - 32 (Pubkey) = 22. ;) I think account discriminator took 4 bytes and 1 byte is for Option if you counted it from the beginning. Option<T> sizes 1 + size_of (T) in bytes. Commented Sep 19 at 16:28

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.