Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Getting an error while getting transaction info using getParsedTransactions method #3721

Closed
VladLypovyi opened this issue Jan 8, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@VladLypovyi
Copy link

VladLypovyi commented Jan 8, 2025

NOTE: This bug tracker is for the v1.98.0 version of @solana/web3.js.

Overview

Got an error while getting transaction info using getParsedTransactions method

Steps to reproduce

Try to get transaction using getParsedTransactions method

import { Connection } from '@solana/web3.js'; 
const connection = new Connection('rpc_url', { commitment: 'finalized' });
const transaction = await connection.getParsedTransactions(['some_tx_hash'], { maxSupportedTransactionVersion: 0 });

Description of bug

Some nodes return the 'error' property for the successful response ("error":null)

{"jsonrpc":"2.0","result":{"blockTime":1735951045,"meta":{"computeUnitsConsumed":3300,"err":null,"fee":5825,"innerInstructions":[],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":2,"numRequiredSignatures":1},"instructions":[],"recentBlockhash":"buuHGVjZVpkSWXkKtveHrTJHQtthUwiWquU3giFm5Fp"},"signatures":["Tj2KrbbudZX2nM5JkdW4ManovBcDw6h7zPnnW4zMtKFnYzSgmd8AmZjeifmdXEJC1QGyHSkiVz8rg1fcLj3m2Qk"]}},"error":null,"id":1}

But the method getParsedTransactions has a check for existing 'error', and throws error that 'failed to get transactions' even for successful responses

/**
   * Fetch parsed transaction details for a batch of confirmed transactions
   */
  async getParsedTransactions(signatures, commitmentOrConfig) {
    const {
      commitment,
      config
    } = extractCommitmentFromConfig(commitmentOrConfig);
    const batch = signatures.map(signature => {
      const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
      return {
        methodName: 'getTransaction',
        args
      };
    });
    const unsafeRes = await this._rpcBatchRequest(batch);
    const res = unsafeRes.map(unsafeRes => {
      const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
      if ('error' in res) {
        throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
      }
      return res.result;
    });
    return res;
  }
@VladLypovyi VladLypovyi added the bug Something isn't working label Jan 8, 2025
@DmytroShalaiev
Copy link

+1

I encountered the same error while using the ChainStack node provider. I have already pinged them, but I still suspect that the error might be related to changes in the Solana client.

@buffalojoec
Copy link
Contributor

buffalojoec commented Jan 10, 2025

Hey @VladLypovyi , are you sure you're looking at the right payload?

Some nodes return the 'error' property for the successful response ("error":null)

The Solana RPC is built to the JSON-RPC 2.0 specification, which states the following about the presence of error and result:

Either the result member or error member MUST be included, but both members MUST NOT be included.

On the Web3.js side, response types are coerced by superstruct, keying on this principle.

function jsonRpcResult<T, U>(schema: Struct<T, U>) {
return coerce(createRpcResult(schema), UnknownRpcResult, value => {
if ('error' in value) {
return value;
} else {
return {
...value,
result: create(value.result, schema),
};
}
});
}

{"jsonrpc":"2.0","result":{"blockTime":1735951045,"meta":{"computeUnitsConsumed":3300,"err":null,"fee":5825,"innerInstructions":[],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":2,"numRequiredSignatures":1},"instructions":[],"recentBlockhash":"buuHGVjZVpkSWXkKtveHrTJHQtthUwiWquU3giFm5Fp"},"signatures":["Tj2KrbbudZX2nM5JkdW4ManovBcDw6h7zPnnW4zMtKFnYzSgmd8AmZjeifmdXEJC1QGyHSkiVz8rg1fcLj3m2Qk"]}},"error":null,"id":1}

This payload you shared is actually from a JSON-parsed transaction payload. The err field is part of the parsed transaction metadata, and it's null if the transaction was successful.

https://solana.com/docs/rpc/http/gettransaction#result


Seems to work okay on my end.

import { Connection } from './lib/index.cjs.js';

const connection = new Connection('http://127.0.0.1:8899', { commitment: 'finalized' });
const response = await connection.getParsedTransactions(
    ['39vTsbCWCopEYA9AQRcgD3YNwjQ24dGes4SWJc5m1KA4kMdQdEBGBwrQNrXgCNwRVXGjMiyGSa3ZAxH69VeCvpi5'],
    { maxSupportedTransactionVersion: 0 },
);
console.log(response);
$ node joec.mjs
[
  {
    blockTime: 1736500860,
    meta: {
      computeUnitsConsumed: 150,
      err: null,
      fee: 5000,
      innerInstructions: [],
      logMessages: [Array],
      postBalances: [Array],
      postTokenBalances: [],
      preBalances: [Array],
      preTokenBalances: [],
      rewards: [],
      status: [Object]
    },
    slot: 9,
    transaction: { message: [Object], signatures: [Array] },
    version: 'legacy'
  }
]

Maybe share something that can specifically reproduce the "failed to get transactions" error you mentioned? You could include a snippet of the console too if you want. This would make it easier to bug hunt.

Thanks!

@VladLypovyi
Copy link
Author

VladLypovyi commented Jan 13, 2025

Hi @buffalojoec!

Thank you for your participation.
Yes, the problem was a certain provider that responded in the parsed data with the presence of the error property in the result.

I think the issue can be closed.

@VladLypovyi VladLypovyi closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants