# /v1/transactions/by_hash/{txn_hash}

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

GET https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/{txn_hash}

Retrieves a transaction from the Aptos blockchain by transaction hash.
If the transaction is not found or has been pruned, the API may return a 404 or 410 respectively.
This endpoint has a credit cost of 10.


Reference: https://www.alchemy.com/docs/chains/aptos/aptos-api-endpoints/aptos-api-endpoints/v-1-transactions-by-hash-txn-hash

## Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| txn_hash | string | Yes | The hash of the transaction to retrieve. |

## Code Examples

### cURL

```bash
curl --request GET \
  --url https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string
```

### JavaScript

```javascript
const options = {method: 'GET'};

fetch('https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string"

response = requests.get(url)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.get("https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://aptos-mainnet.g.alchemy.com/v2/docs-demo/v1/transactions/by_hash/string");
var client = new RestClient(options);
var request = new RestRequest("");
var response = await client.GetAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /v1/transactions/by_hash/{txn_hash}
method: GET
operation:
  summary: /v1/transactions/by_hash/{txn_hash}
  description: |
    Retrieves a transaction from the Aptos blockchain by transaction hash.
    If the transaction is not found or has been pruned, the API may return a 404 or 410 respectively.
    This endpoint has a credit cost of 10.
  tags:
    - Aptos API Endpoints
  security:
    - apiKey: []
  parameters:
    - name: txn_hash
      in: path
      required: true
      schema:
        type: string
      description: The hash of the transaction to retrieve.
  responses:
    '200':
      description: Transaction details for the given hash.
      content:
        application/json:
          schema:
            type: object
            properties:
              version:
                type: string
              hash:
                type: string
              state_change_hash:
                type: string
              event_root_hash:
                type: string
              state_checkpoint_hash:
                type:
                  - string
                  - 'null'
              gas_used:
                type: string
              success:
                type: boolean
              vm_status:
                type: string
              accumulator_root_hash:
                type: string
              changes:
                type: array
                items:
                  type: object
                  properties:
                    address:
                      type: string
                    state_key_hash:
                      type: string
                    data:
                      type: object
                      properties:
                        type:
                          type: string
                        data:
                          type: object
                          additionalProperties: true
                    type:
                      type: string
          examples:
            response:
              summary: Example transaction by hash
              value:
                version: '134911660'
                hash: '0xbe9e71660e128e0e3e1f082c394f7b1bd2f4cb9c52207fe63cf4c8e7eb080e9d'
                state_change_hash: '0x0b0ad696fe46c2ddf6a7acf4ba58a96f406da4fd19b28f562e351ee855eca0c2'
                event_root_hash: '0xb5731d0d85ce6296185ece141fa3c99e73c3a98af9796c1179134a332c2990eb'
                state_checkpoint_hash: null
                gas_used: '57'
                success: true
                vm_status: Executed successfully
                accumulator_root_hash: '0xa51fbb0b8959b229634eec711902063848aa1999869fd93dba72c551cef48b1e'
                changes:
                  - address: '0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1'
                    state_key_hash: '0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1'
                    data:
                      type: 0x190d44...::Storage<...>
                      data:
                        coin_x:
                          value: '13611165452'
                        coin_y:
                          value: '212766465934'
                    type: write_resource
```
