> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/developers/concepts/input-units.md).

# Input Units

The SDK accepts human-readable values for prices, order sizes, and transfer amounts. It validates and converts these values into protocol units before sending a request.

Blockchain integers are serialized as decimal strings in JSON.

### Value types

<table><thead><tr><th width="166.34368896484375">Value</th><th width="196.0728759765625">SDK input</th><th>Rules</th></tr></thead><tbody><tr><td><code>price</code></td><td>Human decimal string</td><td>Up to 1 decimal place</td></tr><tr><td><code>size</code></td><td>Human decimal string</td><td>Up to 2 decimal places</td></tr><tr><td><code>amount</code></td><td>Human decimal string</td><td>Up to 2 decimal places</td></tr><tr><td><code>nonce</code></td><td><code>bigint</code> or decimal string</td><td>Unsigned 64-bit integer</td></tr><tr><td><code>assetId</code></td><td><code>bigint</code> or decimal string</td><td>Canonical unsigned integer</td></tr><tr><td><code>epoch</code></td><td><code>bigint</code> or decimal string</td><td>Canonical unsigned integer</td></tr><tr><td><code>Balance values</code></td><td>Decimal string</td><td>Returned in protocol units</td></tr><tr><td><code>Address</code></td><td>EVM hexadecimal string</td><td>Valid 20-byte address</td></tr><tr><td><code>Order ID or hash</code></td><td>Hexadecimal string</td><td>Valid <code>bytes32</code> value</td></tr></tbody></table>

### Human decimal strings

Order and transfer inputs should be passed as strings rather than JavaScript numbers.

```ts
await exchange.placeOrder({
  assetId: "261336857817713630688382311349658711122006440411137",
  epoch: "12",
  side: false,
  price: "99.9",
  size: "10.25",
});
```

Use:

```ts
price: "99.9"
size: "10.25"
amount: "100.50"
```

Do not use:

```ts
price: 99.9
size: 10.25
amount: 100.5
```

Strings avoid floating-point rounding and allow the SDK to validate decimal precision exactly.

### Price conversion

Prices support one decimal place and are interpreted in cents before being converted into protocol units.

For example:

```
"99.9" → 999000n
```

Applications should pass the human-readable price to the SDK. Do not perform this conversion manually when using `ExchangeClient`.

### Size and amount conversion

Sizes and transfer amounts support up to two decimal places.

Examples of valid inputs:

```
"10"
"10.2"
"10.25"
```

Inputs with more than two decimal places are rejected:

```
"10.255"
```

Zero amounts, invalid precision, negative values, and out-of-range values are rejected before the SDK sends a request.

### ProtocolBigNumberish

Protocol integer fields accept `ProtocolBigNumberish`, which is:

* A `bigint`
* A canonical unsigned decimal string

Examples:

```ts
const assetId = 1n;
const epoch = "12";
const nonce = 113377280000000000n;
```

Avoid JavaScript numbers for protocol integers:

```ts
const assetId = 1; // Do not use for protocol integer inputs
```

JavaScript numbers cannot safely represent every protocol value.

### Addresses

Addresses must use standard EVM hexadecimal format:

```
0x1111111111111111111111111111111111111111
```

The SDK provides string utilities for:

* Address validation
* Non-zero address validation
* Hexadecimal-data validation
* `bytes32` validation
* Case-insensitive address comparison

```ts
import {
  parseAddress,
} from "@gammaswap/v2-exchange-sdk/string-inputs";

const account = parseAddress(
  "0x1111111111111111111111111111111111111111",
);
```

Relevant address fields are normalized before signed action hashes and signatures are validated.

### Integer utilities

Integer-input helpers are available from:

```ts
import {
  parseUnsignedInteger,
} from "@gammaswap/v2-exchange-sdk/integer-inputs";
```

These helpers accept canonical decimal strings and `bigint` values.

They intentionally reject JavaScript numbers unless a specific helper explicitly supports safe JSON or runtime integers.

### Direct API requests

The SDK accepts human decimal inputs and performs the required conversion.

Direct HTTP request bodies use converted protocol values represented as decimal strings.

For example, an SDK call may use:

```ts
{
  price: "99.9",
  size: "10.25"
}
```

The signed HTTP action contains the converted integer values:

```json
{
  "price": "999000",
  "size": "1025"
}
```

When constructing direct HTTP requests, conversion must happen before hashing and signing. Changing a value after signing invalidates the signature.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gammaswap.com/developers/concepts/input-units.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
