---
title: ledger_keylet
description: Search for a keylet within a specified range on the current ledger
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

### Behaviour

<Tabs>
<TabItem label="C">
* Read a 34 byte Keylet from the `lread_ptr`
* Read a 32 byte Keylet from the `hread_ptr`
* Search the ledger for the first (lowest) Keylet of this type in this range.
* If any matching Keylet is found, write it to `write_ptr`.
</TabItem>

<TabItem label="JavaScript">
* This function searches the ledger for the first (`lowest`) Keylet of this type in the given range.
* Returns the number of bytes written (34 bytes) on success, or an error code if an error occurs.
</TabItem>
</Tabs>



### Definition

C

<Tabs>
<TabItem label="C">
```c
int64_t ledger_keylet (
    uint32_t write_ptr,
    uint32_t write_len,
    uint32_t lread_ptr,
    uint32_t lread_len,
    uint32_t hread_ptr,
    uint32_t hread_len
);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
function ledger_keylet(
    low: ByteArray | HexString,
    high: ByteArray | HexString
  ): ErrorCode | ByteArray
```
</TabItem>
</Tabs>



### Example

C

<Tabs>
<TabItem label="C">
```c
//TODO
```


</TabItem>

<TabItem label="JavaScript">
```javascript
ledger_keylet(low, high)
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name       | Type      | Description                                                                                                |
| ---------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| write_ptr | uint32_t | Pointer to a buffer to store the output serialised Keylet. .                                               |
| write_len | uint32_t | Length of the output buffer. Must be 34 bytes                                                              |
| lread_ptr | uint32_t | Pointer to the 34 byte serialised Keylet that represents the lower boundary of the Keylet range to search. |
| lread_len | uint32_t | Always 34 bytes                                                                                            |
| hread_ptr | uint32_t | Pointer to the 34 byte serialised Keylet that represents the upper boundary of the Keylet range to search. |
| hread_len | uint32_t | Always 34 bytes                                                                                            |


</TabItem>

<TabItem label="JavaScript">


| Name | Type                   | Description                                                                                                |
| ---- | ---------------------- | ---------------------------------------------------------------------------------------------------------- |
| low  | ByteArray \| HexString | Pointer to the 34-byte serialized Keylet that represents the lower boundary of the Keylet range to search. |
| high | ByteArray \| HexString | Pointer to the 34-byte serialized Keylet that represents the upper boundary of the Keylet range to search. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -------- |   |
| int64_t | <p>The number of bytes written (34 bytes) on success.<br /><br />If negative, an error:<br /><code>OUT_OF_BOUNDS</code><br />- pointers/lengths specified outside of hook memory.<br /><br /><code>TOO_SMALL</code> / <code>TOO_BIG</code><br />- <code>write_len</code>, <code>lread_len</code> or <code>hread_len</code> was not 34 bytes<br /><br /><code>INVALID_ARGUMENT</code><br />- One or more of the provided Keylets was not a valid serialised Keylet<br /><br /><code>DOES_NOT_MATCH</code><br />- The two provided Keylets were not of the same Keylet Type.<br /><br /><code>DOESNT_EXIST</code><br />- No matching Keylet was found in the specified range.</p> |
</TabItem>

<TabItem label="JavaScript">


| Type                   | Description                                                                                     |
| ---------------------- | ----------------------------------------------------------------------------------------------- |
| ErrorCode \| ByteArray | Returns the number of bytes written (34 bytes) on success, or an error code if an error occurs. |
</TabItem>
</Tabs>

