Solana: I try getTransaction and save to DB, I can’t find accountKeys in message, only staticAccountKeys

Troubleshooting: Getting Account Keys from Solana’s getTransaction

As a developer working on the Solana blockchain, it’s not uncommon to encounter issues when trying to interact with the Solana network. In this article, we’ll explore one common issue that can occur when using the “getTransaction” method in a Solana WebSocket connection: finding account keys in a message.

Problem

Solana: I try getTransaction and save to DB, I can't find accountKeys in message, only staticAccountKeys

When you call “getTransaction” in a Solana WebSocket connection, it returns a transaction object with several properties, including “accountKeys”. However, sometimes this information doesn’t appear in your code. Specifically, if your application doesn’t set the “staticAccountKeys” setting correctly, you won’t see account keys in the message.

Solution

To resolve this issue, assume that the following lines of code are part of your Solana WebSocket connection:

const WS_URL = process.env.SOLANA_WS_URL || '

const connection = new Connection(WS_URL, 'confirmed');

const RAYDIUM_AMM_PROGRAM_ID = new public key(...); // Initialize the AMM program public key

In this case, you will notice that `staticAccountKeys'' is an empty array. This means that any account keys passed from the client to your Solana WebSocket connection will be ignored.

To fix this issue, set staticAccountKeys correctly in your code or update your API endpoint to include the account keys in the response data.

Option 1: SetstaticAccountKeys` correctly

If you do not want to expose your AMM program account keys, you can modify your API endpoint to omit them. For example:

const WS_URL = process.env.SOLANA_WS_URL || '

const connection = new Connection(WS_URL, 'confirmed');

const RAYDIUM_AMM_PROGRAM_ID = new publickey(...); // Initialize the AMM program public key

// API endpoint response data

const responseData = {

transactions: [

{ account_keys: [new PublicKey('account-key-1')], type: 'getTransaction' },

{ account_keys: [new PublicKey('other-account-key-2')], type: 'getTransaction' }

]

};

Option 2: Update the API endpoint to include account keys

If you want to include account keys in your API endpoint response data, you can modify it as follows:

const WS_URL = process.env.SOLANA_WS_URL || '

const connection = new Connection(WS_URL, 'confirmed');

const RAYDIUM_AMM_PROGRAM_ID = new publickey(...); // Initialize the AMM program public key

// API endpoint response data

const responseData = {

transactions: [

{ account_keys: [new PublicKey('account-key-1'), new PublicKey('other-account-key-2')], type: 'getTransaction' }

]

};

By setting “staticAccountKeys” correctly or updating the API endpoint to include the account keys, you should now see the account keys in your message when you use the “getTransaction” method on a Solana WebSocket connection.

دیدگاه‌ها

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *