# getTransaction - Solana

> Example code for the getTransaction JSON-RPC method. Complete guide on how to use the getTransaction JSON-RPC method in the GetBlock Web3 documentation.

This method returns a confirmed transaction by signature, including its instructions, account keys, logs, and balance changes. Versioned transactions require `maxSupportedTransactionVersion`: set it to 1 to read legacy, v0 and v1 transactions. With `@solana/web3.js` use version 1.99.0 or later, as earlier versions fail to parse a v1 response.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| signature | string | Yes | Base58-encoded transaction signature |
| config | object | No | Configuration object controlling encoding and version support |

### Config Object

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| encoding | string | No | Transaction encoding: json, jsonParsed, base58, or base64 |
| commitment | string | No | Commitment level: processed, confirmed, or finalized. Defaults to finalized |
| maxSupportedTransactionVersion | number | No | Highest transaction version the client can decode. Set to 1: a request capped at 0 fails with -32015 on a v1 transaction |

## Request

#### cURL

```bash
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getTransaction",
    "params": ["5wHu1qwD4kLwYqPmy1uDCgpiJ1qGpVYU3n5aHT6bSWUE1JzcbQCPSDLDPGrFyqmLLzQjLNPTPtRZbNbUJQNMkaWq", {"encoding": "jsonParsed", "maxSupportedTransactionVersion": 1}],
    "id": "getblock.io"
}'
```

#### @solana/web3.js

#### example.js

```javascript
const { Connection } = require('@solana/web3.js');

const connection = new Connection('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', 'confirmed');

const transaction = await connection.getParsedTransaction(
  '5wHu1qwD4kLwYqPmy1uDCgpiJ1qGpVYU3n5aHT6bSWUE1JzcbQCPSDLDPGrFyqmLLzQjLNPTPtRZbNbUJQNMkaWq',
  { maxSupportedTransactionVersion: 1 }
);

console.log(transaction?.meta?.fee);
```

#### Request

#### example.py

```python
import requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getTransaction',
        'params': ["5wHu1qwD4kLwYqPmy1uDCgpiJ1qGpVYU3n5aHT6bSWUE1JzcbQCPSDLDPGrFyqmLLzQjLNPTPtRZbNbUJQNMkaWq", {"encoding": "jsonParsed", "maxSupportedTransactionVersion": 1}],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])
```

#### Rust

#### example.rs

```rust
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getTransaction",
            "params": ["5wHu1qwD4kLwYqPmy1uDCgpiJ1qGpVYU3n5aHT6bSWUE1JzcbQCPSDLDPGrFyqmLLzQjLNPTPtRZbNbUJQNMkaWq", {"encoding": "jsonParsed", "maxSupportedTransactionVersion": 1}],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}
```

## Response

```json
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "blockTime": 1774267845,
        "slot": 397234561,
        "meta": {
            "computeUnitsConsumed": 84213,
            "err": null,
            "fee": 5000,
            "innerInstructions": [],
            "logMessages": [
                "Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 invoke [1]"
            ],
            "postBalances": [
                12043900,
                2039280
            ],
            "preBalances": [
                12048900,
                2039280
            ],
            "status": {
                "Ok": null
            }
        },
        "transaction": {
            "message": {
                "accountKeys": [],
                "recentBlockhash": "9zJqLXK9pMhQZ4tGqVvUcxrKpKQ3pMSJ1nZmVeXtBqTd"
            },
            "signatures": [
                "5wHu1qwD4kLwYqPmy1uDCgpiJ1qGpVYU3n5aHT6bSWUE1JzcbQCPSDLDPGrFyqmLLzQjLNPTPtRZbNbUJQNMkaWq"
            ]
        },
        "version": 0
    }
}
```

## Response Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| jsonrpc | string | JSON-RPC protocol version ("2.0") |
| id | string | Request identifier matching the request |
| result | object | null |

### Result Object

| Field | Type | Description |
| --- | --- | --- |
| slot | number | Slot containing the transaction |
| blockTime | number | null |
| transaction | object | Transaction message and signatures in the requested encoding |
| meta | object | Execution metadata including fee, balances, logs, and compute units |
| version | number | string |

## Use Cases

* **Receipt Rendering**: Display instruction-level detail for a completed transfer
* **Log Inspection**: Read `logMessages` to debug a failing program invocation
* **Balance Deltas**: Compare `preBalances` and `postBalances` to compute net movement
* **Compute Budgeting**: Read `computeUnitsConsumed` to right-size a compute unit limit
* **Token Transfer Parsing**: Use `jsonParsed` encoding to extract SPL Token transfer amounts

## Error Handling

| Error Code | Message | Description |
| --- | --- | --- |
| -32602 | Invalid params | Signature is malformed or an unsupported encoding was requested |
| -32015 | Transaction version (1) is not supported by the requesting client | `maxSupportedTransactionVersion` was omitted or is lower than the version of the transaction |
| -32011 | Transaction history is not available from this node | The node does not retain the ledger range containing the signature |
| -32603 | Internal error | Node failed to read the transaction from blockstore |
