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

# Authorization

## Approve Agent

> Authorize an Agent wallet to trade on behalf of the Master wallet.\
> \
> \*\*Signature:\*\* Master · \*\*No protobuf\*\* — fields are signed directly via EIP-712.\
> \
> To revoke the current Agent wallet, submit the same \`approveAgent\` action with \`agentAddress\` set to \`0x0000000000000000000000000000000000000000\` and \`validitySeconds\` set to \`0\`. The Python SDK exposes this as \`client.exchange.revoke\_agent(...)\`.\
> \
> \*\*EIP-712 type:\*\*\
> \`\`\`json\
> {\
> &#x20; "ApproveAgent": \[\
> &#x20;   { "name": "dexChain",     "type": "string"  },\
> &#x20;   { "name": "agentAddress", "type": "address" },\
> &#x20;   { "name": "agentName",    "type": "string"  },\
> &#x20;   { "name": "validitySeconds", "type": "uint64" },\
> &#x20;   { "name": "nonce",        "type": "uint64"  },\
> &#x20;   { "name": "expiryAfter",  "type": "uint64"  }\
> &#x20; ]\
> }\
> \`\`\`\
> \`validitySeconds\` is the agent authorization duration. \`0\` means the authorization is valid for 7 days; maximum 365 days.\
> Domain name: \`"SignTransaction"\`<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"servers":[{"url":"https://api.afx.xyz","description":"Mainnet"},{"url":"https://api-testnet.afx.xyz","description":"Testnet"}],"paths":{"/exchange/approveAgent":{"post":{"operationId":"approveAgent","summary":"Approve Agent","tags":["Authorization"],"description":"Authorize an Agent wallet to trade on behalf of the Master wallet.\n\n**Signature:** Master · **No protobuf** — fields are signed directly via EIP-712.\n\nTo revoke the current Agent wallet, submit the same `approveAgent` action with `agentAddress` set to `0x0000000000000000000000000000000000000000` and `validitySeconds` set to `0`. The Python SDK exposes this as `client.exchange.revoke_agent(...)`.\n\n**EIP-712 type:**\n```json\n{\n  \"ApproveAgent\": [\n    { \"name\": \"dexChain\",     \"type\": \"string\"  },\n    { \"name\": \"agentAddress\", \"type\": \"address\" },\n    { \"name\": \"agentName\",    \"type\": \"string\"  },\n    { \"name\": \"validitySeconds\", \"type\": \"uint64\" },\n    { \"name\": \"nonce\",        \"type\": \"uint64\"  },\n    { \"name\": \"expiryAfter\",  \"type\": \"uint64\"  }\n  ]\n}\n```\n`validitySeconds` is the agent authorization duration. `0` means the authorization is valid for 7 days; maximum 365 days.\nDomain name: `\"SignTransaction\"`\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApproveAgentRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ExchangeOk"}}}}},"components":{"schemas":{"ApproveAgentRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","agentAddress","agentName","validitySeconds","dexChain"],"properties":{"type":{"type":"string","enum":["approveAgent"]},"agentAddress":{"type":"string","description":"Agent wallet address (0x hex)"},"agentName":{"type":"string","default":"app.afx.xyz","description":"Agent name. SDK default: app.afx.xyz"},"validitySeconds":{"type":"integer","format":"int64","description":"Agent authorization duration in seconds. 0 means the authorization is valid for 7 days; maximum 365 days."},"dexChain":{"type":"string","enum":["Mainnet","Testnet"]},"referralCode":{"type":"string","description":"Referral code (only effective on first approve)"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. null = no expiry; use 0 in the signature payload when this field is null."}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}},"ExchangeResponse":{"type":"object","properties":{"code":{"type":"integer","description":"`0` = success. See Error Codes section for non-zero values."},"message":{"type":"string"},"data":{"type":"object","nullable":true,"properties":{"txHash":{"type":"string"},"txCode":{"type":"integer"},"txMsg":{"type":"string"}}}}}},"responses":{"ExchangeOk":{"description":"Transaction submitted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExchangeResponse"}}}}}}}
````

## Withdraw

> Withdraw funds from DEX to an external address.\
> \
> \*\*Signature:\*\* Master · \*\*No protobuf\*\*\
> \
> \*\*EIP-712 type:\*\*\
> \`\`\`json\
> {\
> &#x20; "Withdraw": \[\
> &#x20;   { "name": "dexChain",    "type": "string"  },\
> &#x20;   { "name": "destination", "type": "address" },\
> &#x20;   { "name": "amount",      "type": "string"  },\
> &#x20;   { "name": "withdrawSequence", "type": "uint64" },\
> &#x20;   { "name": "nonce",       "type": "uint64"  },\
> &#x20;   { "name": "expiryAfter", "type": "uint64"  }\
> &#x20; ]\
> }\
> \`\`\`\
> Domain name: \`"SignTransaction"\`. \`dexChain\` is determined by the server environment. \`withdrawSequence\` is included in both the action body and the signed EIP-712 message. If omitted in the Python SDK, it defaults to the request \`nonce\`.\
> \
> For withdrawals, use a longer \`expiryAfter\` window, such as current Unix time in milliseconds + 3,600,000.\
> The minimum mainnet withdrawal amount is 2 USDC.<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"servers":[{"url":"https://api.afx.xyz","description":"Mainnet"},{"url":"https://api-testnet.afx.xyz","description":"Testnet"}],"paths":{"/exchange/withdraw":{"post":{"operationId":"withdraw","summary":"Withdraw","tags":["Authorization"],"description":"Withdraw funds from DEX to an external address.\n\n**Signature:** Master · **No protobuf**\n\n**EIP-712 type:**\n```json\n{\n  \"Withdraw\": [\n    { \"name\": \"dexChain\",    \"type\": \"string\"  },\n    { \"name\": \"destination\", \"type\": \"address\" },\n    { \"name\": \"amount\",      \"type\": \"string\"  },\n    { \"name\": \"withdrawSequence\", \"type\": \"uint64\" },\n    { \"name\": \"nonce\",       \"type\": \"uint64\"  },\n    { \"name\": \"expiryAfter\", \"type\": \"uint64\"  }\n  ]\n}\n```\nDomain name: `\"SignTransaction\"`. `dexChain` is determined by the server environment. `withdrawSequence` is included in both the action body and the signed EIP-712 message. If omitted in the Python SDK, it defaults to the request `nonce`.\n\nFor withdrawals, use a longer `expiryAfter` window, such as current Unix time in milliseconds + 3,600,000.\nThe minimum mainnet withdrawal amount is 2 USDC.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WithdrawRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ExchangeOk"}}}}},"components":{"schemas":{"WithdrawRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","destination","amount"],"properties":{"type":{"type":"string","enum":["withdraw"]},"destination":{"type":"string","description":"Recipient address (0x hex)"},"amount":{"type":"string","description":"Withdrawal amount. Minimum mainnet withdrawal: 2 USDC."}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. For withdrawals, use a longer window such as current time + 3,600,000 milliseconds. null = no expiry; use 0 in the signature payload when this field is null."}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}},"ExchangeResponse":{"type":"object","properties":{"code":{"type":"integer","description":"`0` = success. See Error Codes section for non-zero values."},"message":{"type":"string"},"data":{"type":"object","nullable":true,"properties":{"txHash":{"type":"string"},"txCode":{"type":"integer"},"txMsg":{"type":"string"}}}}}},"responses":{"ExchangeOk":{"description":"Transaction submitted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExchangeResponse"}}}}}}}
````


---

# 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:

```
GET https://docs.afx.xyz/api-reference/exchange/authorization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
