1

I see an AccountKeys struct that is instantiated using a messages static and dynamic keys but don't see any examples of creating one lookup tables on the client side. Do I need to implement the code to populate the LoadedAddresses myself?

This is the corresponding method in the web3.js library:

https://github.com/solana-labs/solana-web3.js/blob/master/packages/library-legacy/src/message/v0.ts#L78

1 Answer 1

1

You can access the account_keys directly on the solana_program::message::v0::Message struct https://docs.rs/solana-program/latest/solana_program/message/v0/struct.Message.html

And if you want code to help with creating a versioned message, there's a great example at try_compile https://docs.rs/solana-program/latest/solana_program/message/v0/struct.Message.html#method.try_compile, which I'm pasting here:

use anyhow::Result;
use solana_rpc_client::rpc_client::RpcClient;
use solana_program::address_lookup_table::{self, state::{AddressLookupTable, LookupTableMeta}};
use solana_sdk::{
     address_lookup_table_account::AddressLookupTableAccount,
     instruction::{AccountMeta, Instruction},
     message::{VersionedMessage, v0},
     pubkey::Pubkey,
     signature::{Keypair, Signer},
     transaction::VersionedTransaction,
};

fn create_tx_with_address_table_lookup(
    client: &RpcClient,
    instruction: Instruction,
    address_lookup_table_key: Pubkey,
    payer: &Keypair,
) -> Result<VersionedTransaction> {
    let raw_account = client.get_account(&address_lookup_table_key)?;
    let address_lookup_table = AddressLookupTable::deserialize(&raw_account.data)?;
    let address_lookup_table_account = AddressLookupTableAccount {
        key: address_lookup_table_key,
        addresses: address_lookup_table.addresses.to_vec(),
    };

    let blockhash = client.get_latest_blockhash()?;
    let tx = VersionedTransaction::try_new(
        VersionedMessage::V0(v0::Message::try_compile(
            &payer.pubkey(),
            &[instruction],
            &[address_lookup_table_account],
            blockhash,
        )?),
        &[payer],
    )?;

    Ok(tx)
}

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.