---
title: sto_validate
description: Validate an STObject
---
import { Tabs, TabItem, LinkButton } from '@astrojs/starlight/components';

### Concepts

<LinkButton href="/docs/hooks/concepts/serialized-objects">Serialized Objects</LinkButton>

### Behaviour

<Tabs>
<TabItem label="C">
* Parse an STObject pointed to by `read_ptr`
* Return 1 if the serialization is valid, 0 otherwise.
</TabItem>

<TabItem label="JavaScript">
* The `blob` (e.g. serialized transaction) is provided to be validated.
* Returns number 1 if the STObject is valid, 0 if it isn't, or an error code if validation fails.
</TabItem>
</Tabs>



### Definition

<Tabs>
<TabItem label="C">
```c
int64_t sto_validate (
    uint32_t read_ptr,
    uint32_t read_len
);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
function sto_validate(blob: ByteArray | HexString): ErrorCode | number
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
int64_t result = 
  sto_validate(tx_out, sizeof(tx_out));

if (tx_len <= 0)
    rollback("Invalid STO.", 12, 1);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
const result = sto_validate(tx_out)

if (result <= 0)
    rollback("Invalid STO.", 1)
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name      | Type      | Description                                 |
| --------- | --------- | ------------------------------------------- |
| read_ptr | uint32_t | The buffer to read the source STObject from |
| read_len | uint32_t | The Length of the source object             |


</TabItem>

<TabItem label="JavaScript">


| Name | Type                   | Description                                             |
| ---- | ---------------------- | ------------------------------------------------------- |
| blob | ByteArray \| HexString | The blob (e.g. serialized transaction) to be validated. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                                                                                       |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <p><code>1</code> if the STObject pointed to by <code>read_ptr</code> is a valid STObject.<br /><code>0</code> if it isn't.<br /><br />If negative, an error:<br /><code>OUT_OF_BOUNDS</code><br />- pointers/lengths specified outside of hook memory.</p> |


</TabItem>

<TabItem label="JavaScript">
| Type                | Description                                                                                     |
| ------------------- | ----------------------------------------------------------------------------------------------- |
| ErrorCode \| number | Returns number 1 if the STObject is valid, 0 if it isn't, or an error code if validation fails. |
</TabItem>
</Tabs>

