> For the complete documentation index, see [llms.txt](https://docs.ticko.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ticko.xyz/api-documentation/authentication/examples.md).

# Examples

### Placing Order Signing Example

This example signs `POST /v1/trade/orders` with Signing Type A. It uses Ticko Mainnet `domain.chainId = 84256` and omits `target_address`.

{% stepper %}
{% step %}

### Prepare the unsigned request body

```json
{
  "symbol_id": 100001,
  "is_buy": true,
  "order_type": "limit",
  "time_in_force": "gtc",
  "quantity": "1.0",
  "price": "67500.00",
  "position_side": "both",
  "margin_mode": "cross",
  "signer_address": "0xabc000000000000000000000000000000000def0",
  "nonce": 1719500000000,
  "expires_after": 1719500600000
}
```

{% endstep %}

{% step %}

### Build `business_fields` and `canonical_json`

For this endpoint, `business_fields` are the documented order fields:

```json
{
  "symbol_id": 100001,
  "is_buy": true,
  "order_type": "limit",
  "time_in_force": "gtc",
  "quantity": "1.0",
  "price": "67500.00",
  "position_side": "both",
  "margin_mode": "cross"
}
```

Sort keys alphabetically and serialize as compact JSON:

```json
{"is_buy":true,"margin_mode":"cross","order_type":"limit","position_side":"both","price":"67500.00","quantity":"1.0","symbol_id":100001,"time_in_force":"gtc"}
```

This string is `canonical_json`.
{% endstep %}

{% step %}

### Compute `actionHash`

`POST /v1/trade/orders` uses action tag `7`:

```
actionHash = keccak256(concat(uint8(7), utf8_bytes(canonical_json)))
```

{% endstep %}

{% step %}

### Build the Type A EIP-712 inputs

Because this request omits `target_address`, the `Agent` message does not include `targetAddress`.

```
domain = {
  name: "Ticko",
  version: "1",
  chainId: 84256,
  verifyingContract: "0x0000000000000000000000000000000000000000"
}

encodeType = "Agent(address signerAddress,bytes32 actionHash,uint64 nonce,uint64 expiresAfter)"

messageFields = [
  signerAddress = "0xabc000000000000000000000000000000000def0",
  actionHash = actionHash,
  nonce = 1719500000000,
  expiresAfter = 1719500600000
]
```

{% endstep %}

{% step %}

### Compute `signing_hash`

Apply the EIP-712 hashing rules to the Type A inputs:

```
domainType = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"

domainSeparator = keccak256(concat(
  keccak256(utf8_bytes(domainType)),
  keccak256(utf8_bytes("Ticko")),
  keccak256(utf8_bytes("1")),
  pad32(84256),
  pad32(0x0000000000000000000000000000000000000000)
))

typeHash = keccak256(utf8_bytes(encodeType))

structHash = keccak256(concat(
  typeHash,
  pad32(0xabc000000000000000000000000000000000def0),
  actionHash,
  pad32(1719500000000),
  pad32(1719500600000)
))

signing_hash = keccak256(concat(
  "\x19\x01",
  domainSeparator,
  structHash
))
```

{% endstep %}

{% step %}

### Sign `signing_hash`

```
(v, r, s) = ecdsaSign(signing_hash, privateKey)
```

Use the private key for `signer_address`. Add the resulting values as `signature: { r, s, v }`.
{% endstep %}

{% step %}

### Submit the signed request

```json
{
  "symbol_id": 100001,
  "is_buy": true,
  "order_type": "limit",
  "time_in_force": "gtc",
  "quantity": "1.0",
  "price": "67500.00",
  "position_side": "both",
  "margin_mode": "cross",
  "signer_address": "0xabc000000000000000000000000000000000def0",
  "nonce": 1719500000000,
  "expires_after": 1719500600000,
  "signature": { "r": "0x...", "s": "0x...", "v": 28 }
}
```

{% endstep %}
{% endstepper %}

### Create Agent Key Signing Example

This example signs `POST /v1/account/approve-agent` with Signing Type B. Type B uses the wallet private key for `signer_address`; Agent keys cannot sign this request. `signature_chain_id` is `1`, so the EIP-712 domain uses `chainId = 1`.

{% stepper %}
{% step %}

### Prepare the unsigned request body

```json
{
  "ticko_chain": "Mainnet",
  "signature_chain_id": 1,
  "agent_address": "0x1111111111111111111111111111111111111111",
  "authorized_address": "0xabc000000000000000000000000000000000def0",
  "valid_days": 30,
  "label": "mm-bot-prod",
  "signer_address": "0xabc000000000000000000000000000000000def0",
  "nonce": 1719500000000,
  "expires_after": 1719500600000
}
```

{% endstep %}

{% step %}

### Build the Type B EIP-712 inputs

Use the `approve-agent` row in the Type B operation structs table:

```
domain = {
  name: "Ticko",
  version: "1",
  chainId: 1,
  verifyingContract: "0x0000000000000000000000000000000000000000"
}

encodeType = "ApproveAgent(address signerAddress,string tickoChain,address agentAddress,address authorizedAddress,uint32 validDays,string label,uint64 nonce,uint64 expiresAfter)"

messageFields = [
  signerAddress = "0xabc000000000000000000000000000000000def0",
  tickoChain = "Mainnet",
  agentAddress = "0x1111111111111111111111111111111111111111",
  authorizedAddress = "0xabc000000000000000000000000000000000def0",
  validDays = 30,
  label = "mm-bot-prod",
  nonce = 1719500000000,
  expiresAfter = 1719500600000
]
```

{% endstep %}

{% step %}

### Compute `signing_hash`

Apply the EIP-712 hashing rules to the Type B inputs:

```
domainType = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"

domainSeparator = keccak256(concat(
  keccak256(utf8_bytes(domainType)),
  keccak256(utf8_bytes("Ticko")),
  keccak256(utf8_bytes("1")),
  pad32(1),
  pad32(0x0000000000000000000000000000000000000000)
))

typeHash = keccak256(utf8_bytes(encodeType))

structHash = keccak256(concat(
  typeHash,
  pad32(0xabc000000000000000000000000000000000def0),
  keccak256(utf8_bytes("Mainnet")),
  pad32(0x1111111111111111111111111111111111111111),
  pad32(0xabc000000000000000000000000000000000def0),
  pad32(30),
  keccak256(utf8_bytes("mm-bot-prod")),
  pad32(1719500000000),
  pad32(1719500600000)
))

signing_hash = keccak256(concat(
  "\x19\x01",
  domainSeparator,
  structHash
))
```

{% endstep %}

{% step %}

### Sign `signing_hash`

```
(v, r, s) = ecdsaSign(signing_hash, privateKey)
```

Use the wallet private key for `signer_address`. Add the resulting values as `signature: { r, s, v }`.
{% endstep %}

{% step %}

### Submit the signed request

```json
{
  "ticko_chain": "Mainnet",
  "signature_chain_id": 1,
  "agent_address": "0x1111111111111111111111111111111111111111",
  "authorized_address": "0xabc000000000000000000000000000000000def0",
  "valid_days": 30,
  "label": "mm-bot-prod",
  "signer_address": "0xabc000000000000000000000000000000000def0",
  "nonce": 1719500000000,
  "expires_after": 1719500600000,
  "signature": { "r": "0x...", "s": "0x...", "v": 28 }
}
```

{% endstep %}
{% endstepper %}


---

# 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.ticko.xyz/api-documentation/authentication/examples.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.
