Troubleshooting: Getting Account Keys from GetTransaction
In Solana
As a development work In this article, we’ll provide into one common problem
The Issue
When you call gettransaction
on a solana website connection, However, sometimes this information is not visible to your code. Specifically
The Solution
To resolve this issue, let’s assume that the following
`JavaScript
Const ws_url = process.env.solana_ws_url || ‘
Const Connection = New Connection (ws_url, ‘confirmed’);
Const Raydium_amm_program_id = New Publickey (…); // Initialize a Public Key for the Amm Program
`
In this case, you’ll notice that staticaccountkeys
is set to an empty array. This means that any account keys
The API Endpoint to include account keys in the Response Data.
Option 1: Set Staticcountkeys
Correctly
If you don’t want to expose any account keys from your amm program, For example:
`JavaScript
Const ws_url = process.env.solana_ws_url || ‘
Const Connection = New Connection (ws_url, ‘confirmed’);
Const Raydium_amm_program_id = New Publickey (…); // Initialize a Public Key for the Amm Program
// API Endpoint Response Data
Const responsedata = {
Transactions: [
{ACCOUNT_KEYS: [New Publickey (‘Account-key-1’)], Type: ‘GetTransaction’},
{ACCOUNT_KEYS: [New Publickey (‘Another-Account-Key-2’)], Type: ‘GetTransaction’}
]
};
`
Option 2: Update API Endpoint to include Account Keys
Api Endpoint Data, You can modify it as follows:
`JavaScript
Const ws_url = process.env.solana_ws_url || ‘
Const Connection = New Connection (ws_url, ‘confirmed’);
Const Raydium_amm_program_id = New Publickey (…); // Initialize a Public Key for the Amm Program
// API Endpoint Response Data
Const responsedata = {
Transactions: [
{ACCOUNT_KEYS: [New Publickey (‘Account-Key-1’), New Publickey (‘Another-Account-Key-2’)], Type: ‘GetTransaction’}
]
};
`
Setting staticaccountkeys
correctly or updating the API Endpoint to include account keys, you should now be able to see the account key