# getLatestLedger

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

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

For finding out the current latest known ledger of this node. This is a subset of the ledger info from Horizon.

Reference: https://www.alchemy.com/docs/chains/stellar/stellar-api-endpoints/get-latest-ledger

## Result

**getLatestLedgerResponse** (object)

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://stellar-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLatestLedger"
}'
```

### JavaScript

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

fetch('https://stellar-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://stellar-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getLatestLedger"
}
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://stellar-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getLatestLedger\"\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://stellar-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getLatestLedger\"\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://stellar-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\": \"getLatestLedger\"\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getLatestLedger
summary: returns latest known ledger
description: For finding out the current latest known ledger of this node. This is a subset of the ledger info from Horizon.
externalDocs:
  url: https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLatestLedger
paramStructure: by-name
params: []
result:
  name: getLatestLedgerResponse
  schema:
    type: object
    properties:
      id:
        title: id
        type: string
        minLength: 64
        maxLength: 64
        pattern: ^[a-f\d]{64}$
        description: Hash identifier of the latest ledger (as a hex-encoded string) known to Stellar RPC at the time it handled the request.
      sequence:
        title: latestLedger
        description: The sequence number of the latest ledger known to Stellar RPC at the time it handled the request.
        type: number
      closeTime:
        title: closeTime
        description: The timestamp at which the latest ledger was closed.
        type: string
      headerXdr:
        title: headerXdr
        type: string
        description: The [LedgerHeader](https://github.com/stellar/stellar-xdr/blob/v22.0/Stellar-ledger.x#L74) structure for this ledger (base64-encoded string).
      metadataXdr:
        title: metadataXdr
        type: string
        description: The [LedgerCloseMeta](https://github.com/stellar/stellar-xdr/blob/v22.0/Stellar-ledger.x#L539) union for this ledger (base64-encoded string).
```
