Transaction Signing
signature is not a signature over the JSON text. The write path reconstructs the canonical unsigned transaction payload from action, nonce, agent_epoch, and expires_after_ms, then verifies the recoverable secp256k1 signature over that exact binary payload. For order and modify actions, public JSON price and quantity are display decimals; the signed binary action contains the raw atoms obtained from market price_decimals and base_quantity_decimals. The JSON action and signed binary action must describe the same action.
Canonical unsigned payload:
string("NATIVE_CORE_TX_SIGNING_V1")
u32(1) // tx codec version
u32(696969) // Native Core chain id (mainnet; testnet is 969696)
u64(nonce)
option<u64>(agent_epoch)
option<u64>(expires_after_ms)
action_bytesThe chain id is the target deployment's Native chain id (mainnet: 696969, testnet: 969696). It is folded into the signed bytes but is never sent on the wire, so it must equal the deployment you target — signing with the wrong chain id makes the API recover a different authority and reject the write.
Encoding rules:
Integers are unsigned big-endian.
stringand byte vectors encode asu32 byte_lengthfollowed by raw bytes.option<T>encodes asu8(0)fornull/omitted, oru8(1)followed byT.Hex values are raw bytes after removing the
0xprefix.The signing digest is
keccak256(unsigned_payload_bytes).signatureis0x+ 65 bytes encoded asr || s || v;vmay be0/1or27/28. High-s signatures are rejected.
The legacy scheme above applies to trading actions. Authorization-sensitive actions use EIP-712 (next section).
EIP-712 signing (auth_scheme: "eip712")
Public transfer, activateFor, withdraw, settle, repay, approveAgent, revokeAgent, and setAccountMultisig must be submitted with auth_scheme: "eip712". (The full cutover set also covers deposit and the operator admin* writes, which are not part of this public trading contract.) This is a direct cutover: the moment the new binary is live, legacy signatures over these actions are rejected (LegacySignatureNotAccepted), and there is no config switch, height activation, or grace window — clients must switch at deploy. Conversely, auth_scheme="eip712" on any non-target action (order/cancel/cancelAll/modify/batch) is rejected (Eip712NotAllowedForAction), and an EIP-712 request may not carry agent_epoch (Eip712AgentEpochNotAllowed).
The signature covers an EIP-712 typed-data digest, not a binary payload. Clients sign the v4 scheme, which is MetaMask-compatible: the domain is EIP712Domain{name:"Native Core", version:"1", verifyingContract:0x0000…0000} — no chainId — so a wallet can sign while connected to any EVM chain. The Native chain id is instead a signed message field, nativeChainId, so replay separation across environments is preserved. Each target action has its own primary type whose fields mirror the action, prefixed by the common fields uint256 nativeChainId, uint256 authKind, uint256 authScope, uint256 nonce, bool expiresAfterMsPresent, uint256 expiresAfterMs. nativeChainId is the Native Core chain id; under this v4 scheme authKind is 1 (single) and authScope is 0 for these public user actions (under v5 authKind is 2 and authScope is removed entirely, not given a different value). Amounts are signed as canonical atoms; addresses as address; an optional cloid as bool cloidPresent + bytes16 cloid. The presence flags keep an absent value distinct from an explicit 0. The transaction authority is the recovered signer, exactly as for legacy single-signature actions; under v5 it is the auth_account instead.
A superseded v3 EIP-712 scheme (domain included chainId; no nativeChainId field) is retained only for historical decode/replay and is not accepted at submit. Because /trade carries no codec-version field, a request whose signature was produced under the old v3 scheme is assembled as v4 and recovers a different address, so it fails with a signature/authority error — re-sign with the v4 scheme.
A v5 variant of the v4 scheme exists for accounts that have configured an account multisig: the domain version becomes "2", authScope is replaced by address authAccount, uint256 policyEpoch, and authKind is 2. It applies to the envelope's common fields only — every action tail below is unchanged under it. Which of the two you sign follows the envelope, not the action: a request carrying auth_account is v5, everything else is v4. One exception sits outside the envelope — the sponsor's AccountMultisigSponsor message is always signed under the v5 domain, even though the sponsored creation that carries it is owner-signed v4. See Account Multisig.
Per-action typed-data fields
Every primary type below is the six common fields verbatim, then the action's own tail. Field names are camelCase and are not the JSON field names — slot_id in the request body is slotId in the typed data, agent is agentAddress, and slotId is a uint256 even though the JSON carries it as a string.
Transfer
address to, uint256 assetId, uint256 amount, bool cloidPresent, bytes16 cloid
ActivateFor
uint256 assetId, address targetAddress, bytes16 cloid
Withdraw
uint256 assetId, uint256 amount, uint256 dstChainId, address dstAddress, uint256 withdrawNonce, bool cloidPresent, bytes16 cloid
Settle
uint256 assetId, uint256 amount, address cashAccount, bytes16 cloid
Repay
uint256 assetId, uint256 amount, address marginAccount, bytes16 cloid
ApproveAgent
uint256 slotId, address agentAddress
RevokeAgent
uint256 slotId
SetAccountMultisig
uint256 threshold, address[] signers, uint256 feeMode, uint256 feeAssetId, uint256 feeAmountAtoms, address feePayer, uint256 feePayerPolicyEpoch, bytes16 cloid — the creation fee is flattened, not nested; see Account Multisig
cloid is handled three different ways and the difference is load-bearing: Transfer and Withdraw carry it as optional (cloidPresent + cloid), ActivateFor, Settle, Repay and SetAccountMultisig carry it as a bare required bytes16 with no presence flag, and the two agent actions have no cloid field at all. Adding or dropping the flag changes the type string, which changes the digest, which recovers a different address. The JSON payload requires cloid on all six actions that have the field, so the presence flag is not a licence to omit it.
Written out, ApproveAgent is:
There is no way to detect a wrong type string from the response. A digest that differs by one field recovers an unrelated address, and the node answers OwnerDoesNotExist for that address — so the error names the symptom, never the mistake. Two attempts recovering to two different addresses is the signature of a digest mismatch rather than an unregistered account, since one key over one message always recovers the same address.
Public action tags:
order
0
Top-level order.
cancel with oid
2
If both oid and cloid are present, oid wins.
cancel with only cloid
4
Canonical cancel-by-cloid.
modify with oid
6
If both oid and cloid are present, oid wins.
modify with only cloid
8
Canonical modify-by-cloid.
cancelAll
26
Cancel every open order for the effective owner in one market. No cloid.
batch
18
Batch item tags are order=0, cancel by oid=1, modify by oid=2, modify by cloid=3, cancel by cloid=4, cancelAll=5.
These are the only top-level tags a client encodes; a batch additionally encodes one item tag per item, from the separate numbering in the batch row above. The tag space is not contiguous — some numbers in the same range are permanently retired and are never reassigned, so do not infer a tag by counting from a neighbouring one. A wrong tag is not reported as a bad tag: it changes the digest, so the request recovers an address you never used and comes back as OwnerDoesNotExist — the same symptom, and the same diagnosis, as the wrong type string described above. Owner-signed EIP-712 actions (transfer, withdraw, settle, repay, activateFor, approveAgent, revokeAgent) do not appear here because their clients sign typed data and never encode a tag at all.
Order action bytes:
Cancel action bytes:
Modify action bytes:
replacement_order uses the same fields as order after market_id:
CancelAll action bytes:
cancelAll carries no oid and no cloid. The signed payload is a single u32 market id; the JSON body must match ({ "type": "cancelAll", "market_id": "<id>" }).
Batch action bytes:
Each batch item starts with a u8 item tag followed by the item payload without the top-level u16 action tag:
TypeScript signing helper example for Node.js with ethers. The example uses Node's global Buffer; import it from node:buffer only if your TypeScript setup requires explicit Buffer types.
agent_epoch is mandatory for these API-wallet–signed trading actions: an API wallet is always an active agent, so a /trade write that omits agent_epoch is treated as direct-owner mode and rejected with DirectSignerIsActiveAgent. Read the current epoch from userAgents.
/trade is synchronous, so the response carries the outcome. submission_status is accepted (the transaction landed and executed), rejected (refused, or failed at execution), or timeout. accepted is a verdict on the transaction, not on your order — the order's own outcome is in the response envelope. See POST /trade and error responses for the full model.
Order outcome (the transaction landed; read response.status for what happened to the order):
response.status is one of open (rested), filled (with total_sz and avg_px), cancelled, or {"error": "<code>"}.
A failed order still reports accepted, so branching on submission_status alone reads it as a success. Most failures are never written to orderStatus either, which makes the leaf the only trace — see what a failed order leaves behind. The oid and the fill are here too, so there is no need to spend an /info read on them.
Rejected response (node-admission code, returned verbatim):
Request-shaping rejections usually have no tx_hash because canonical bytes were not assembled; admission and execution rejections include it. Rate-limit responses also include error.retry_after_ms. A submission_status: "timeout" means the outcome was not observed in time — either the wait budget elapsed (HTTP 200, no error) or the submission could not be routed (Unavailable at HTTP 503, or NodeUnreachable at HTTP 504). The two cases need opposite handling — see Handle outcomes & timeouts.
Malformed or non-decodable JSON is handled by the API and returns the TradeResponse shape with error.code = "InvalidJson". This includes invalid action type tags and invalid field types. Negative numeric strings and malformed decimal strings are also InvalidJson — they are rejected inside deserialization, before any field-specific check runs. Failures caught after decoding, such as a precision violation, return their specific code in the same response shape. All such responses include x-trace-id.
/trade error codes
Every /trade error.code — request-shaping, gateway, node-admission, and execution — is cataloged in Error responses. Node-admission codes are returned verbatim (CamelCase) in top-level error.code. A lowercase execution code such as tick never appears there — for an order-ish action it comes back inside the response envelope while submission_status stays accepted.
Supported public top-level action types:
ordercancelcancelAllmodifybatchtransfer(owner single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712"; see transfer)activateFor(owner single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712"; see activateFor)withdraw(user single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712"; see withdraw)settle(user single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712")repay(user single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712")approveAgent(owner single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712"; see approveAgent)revokeAgent(owner single-signature, or quorum-signed under an account multisig; EIP-712auth_scheme:"eip712")setAccountMultisig(owner single-signature for a first creation, quorum-signed for a replacement; EIP-712auth_scheme:"eip712"only — see Account Multisig)
Operator/accounting writes (deposit, adminSetAccountingWithdrawTokens, admin*, setMultisigPolicy, addAsset, openMarket, …) are also accepted by the API but require operator/admin authority and are not part of this public trading contract.
Last updated