---
title: slot
description: Serialize and output a slotted object
---
import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';

### Behaviour

<Tabs>
<TabItem label="C">
* Serialize the object currently occupying the specified slot
* Write the serialized version of the object to the output buffer

<Aside type="tip" title="Alternative use">
For small objects you may avoid using a buffer. Specify `0, 0` for `write_ptr, write_len` to attempt to return the slotted object as big endian packed data in the `int64_t` return code. Up to 63 bits of data may be returned this way.
</Aside>
</TabItem>

<TabItem label="JavaScript">
* Retrieves the JSON Retrieves the data associated with the specified slot. of the specified slot.
* Returns an error code or the slot's data.
</TabItem>
</Tabs>

### Definition

<Tabs>
<TabItem label="C">
```c
int64_t slot (
    uint32_t write_ptr,
    uint32_t write_len,
    uint32_t slot_no
);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
function slot(slotno: number): ErrorCode | ByteArray
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
uint8_t txn[512];
int64_t bytes_written = 
    slot(txn, 512, 1); // assumes a transaction is slotted into slot=1
```
</TabItem>

<TabItem label="JavaScript">
```javascript
const txn = slot(1) // assumes a transaction is slotted into slot=1
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name       | Type      | Description                                                 |
| ---------- | --------- | ----------------------------------------------------------- |
| write_ptr | uint32_t | Pointer to a buffer of a suitable size to store the output. |
| write_len | uint32_t | Length of the output buffer.                                |
| slot_no   | uint32_t | The slot number                                             |
</TabItem>

<TabItem label="JavaScript">
| Name   | Type   | Description     |
| ------ | ------ | --------------- |
| slotno | number | The slot number |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                                                                                                |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <p>The number of bytes written<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><br />- output buffer was not large enough to hold the serialized object</p> |
</TabItem>

<TabItem label="JavaScript">
| Type                   | Description                               |
| ---------------------- | ----------------------------------------- |
| ErrorCode \| ByteArray | Returns an error code or the slot's data. |
</TabItem>
</Tabs>

