1

Say I have given a versioned transaction and I want to get the accounts in the same format my smart contract will see it in. How do I do this?

Edit: I've tried the below, but this always gives me Error: Failed to get account keys because address table lookups were not resolved, which makes sense since this is a synchronous method and I didn't fetch the LUTs onchain anywhere else.

const allAccs = transaction.message.getAccountKeys().keySegments().reduce((acc, cur) => acc.concat(cur), []);

2 Answers 2

1

Figured it out. If our transaction is tx, we can just do:

const LUTs = (await Promise.all(transaction.message.addressTableLookups
    .map((acc) => conn.getAddressLookupTable(acc.accountKey))))
    .map((lut) => lut.value).filter((val) => val !== null) as AddressLookupTableAccount[];
const allAccs = transaction.message.getAccountKeys({ addressLookupTableAccounts: LUTs })
    .keySegments().reduce((acc, cur) => acc.concat(cur), []);
0
0

Code:

    const tx = await connection.getParsedTransaction(
    "3PF85bjev6h7ydKyKpwLyw9R7jq2A9PdzRjtuhbzjKXgLZgdFcXWKZK89KSdes2qu4kWsBXgk6srsHDFpnfEoCEH",
    {
        maxSupportedTransactionVersion: 0
    }
);
console.log(tx.transaction.message.accountKeys);
1
  • Thanks for this, but I already solved my issue in my answer below. Additionally, the tx hasn't been executed yet, so I can't use getParsedTransaction. I didn't say it had, but tbf I also didn't say it hadn't :)
    – McBain
    Commented Dec 29, 2023 at 22:55

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.