# getmempoolancestors

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

POST https://bitcoin-mainnet.g.alchemy.com/v2/{apiKey}

Returns the in-mempool ancestors of a given transaction.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/getmempoolancestors

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| txid | string | Yes | The transaction ID whose ancestors to retrieve. |
| verbose | boolean | No | Whether to return detailed info (true) or just txids (false). |

## Result

**result** (string[] or object): The mempool ancestors of the specified transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getmempoolancestors",
  "params": [
    "b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795",
    false
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": [
    "6f8c6e8d3021d8a1db71eae3cb8db00f1c99d0f94f3b5782e6cfc155b55f3c55",
    "a4d47b8bdee5f5b8c098c9ac9aa4e3ec113d9f305a4f723d617a92439ab244cb"
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getmempoolancestors",
  "params": [
    "b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795",
    false
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getmempoolancestors',
    params: ['b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795', false]
  })
};

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

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getmempoolancestors",
    "params": ["b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795", False]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

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

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getmempoolancestors\",\n  \"params\": [\n    \"b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795\",\n    false\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getmempoolancestors\",\n  \"params\": [\n    \"b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795\",\n    false\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getmempoolancestors\",\n  \"params\": [\n    \"b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795\",\n    false\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getmempoolancestors
summary: Get mempool ancestors of a transaction
description: |
  Returns the in-mempool ancestors of a given transaction.
params:
  - name: txid
    required: true
    description: The transaction ID whose ancestors to retrieve.
    schema:
      title: Bitcoin Transaction ID
      type: string
      pattern: ^[a-fA-F0-9]{64}$
      description: A 64-character hex string identifying a transaction.
  - name: verbose
    required: false
    description: Whether to return detailed info (true) or just txids (false).
    schema:
      type: boolean
      default: false
result:
  name: result
  description: The mempool ancestors of the specified transaction.
  schema:
    oneOf:
      - type: array
        description: A list of ancestor transaction IDs.
        items:
          title: Bitcoin Transaction ID
          type: string
          pattern: ^[a-fA-F0-9]{64}$
          description: A 64-character hex string identifying a transaction.
      - type: object
        additionalProperties:
          type: object
          properties:
            size:
              type: integer
            fee:
              type: number
            modifiedfee:
              type: number
            time:
              type: integer
            descendantcount:
              type: integer
            ancestorcount:
              type: integer
            depends:
              type: array
              items:
                type: string
            spentby:
              type: array
              items:
                type: string
examples:
  - name: Non-verbose example
    params:
      - name: txid
        value: b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795
      - name: verbose
        value: false
    result:
      name: result
      value:
        - 6f8c6e8d3021d8a1db71eae3cb8db00f1c99d0f94f3b5782e6cfc155b55f3c55
        - a4d47b8bdee5f5b8c098c9ac9aa4e3ec113d9f305a4f723d617a92439ab244cb
  - name: Verbose example
    params:
      - name: txid
        value: b86ae732473ff2c91c04073ec9cbef5e4ddaa701741e141e41345df72122b795
      - name: verbose
        value: true
    result:
      name: result
      value:
        6f8c6e8d3021d8a1db71eae3cb8db00f1c99d0f94f3b5782e6cfc155b55f3c55:
          size: 237
          fee: 0.00001
          modifiedfee: 0.000011
          time: 1714400000
          descendantcount: 2
          ancestorcount: 3
          depends:
            - abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234
          spentby:
            - fe5289e5f1f32f2a45c85b2e351c5edebf7f76aa86e31bb8a2983d4f8d95a63a
```
