Order Signing

GRVT orders must be signed using EIP-712 typed data signing. The SDK provides utilities for signing orders with various wallet types.

PrivateKeySigner

A built-in signer that doesn't require viem or ethers.

import { PrivateKeySigner } from "@wezzcoetzee/grvt";

const signer = new PrivateKeySigner("0xabc123...");
console.log(signer.address); // 0x...

Constructor

Parameter
Type
Description

privateKey

string

Hex string (with or without 0x prefix)

Methods

signTypedData

Signs EIP-712 typed data.

const signature = await signer.signTypedData({
  domain: { ... },
  types: { ... },
  primaryType: "Order",
  message: { ... },
});

Wallet Compatibility

The SDK supports multiple wallet types through the AbstractWallet interface:

signOrder

Signs an order and returns a payload ready for submission.

Parameters

Parameter
Type
Required
Description

wallet

AbstractWallet

Yes

Wallet for signing

env

GrvtEnv

Yes

GRVT environment (determines chain ID)

order

OrderParams

Yes

Order parameters

instruments

Record<string, InstrumentInfo>

Yes

Instrument metadata

clientOrderId

string

No

Client-specified order ID

OrderParams

Field
Type
Required
Description

subAccountId

string

Yes

Sub-account ID

isMarket

boolean

Yes

Market order flag

timeInForce

TimeInForce

Yes

Time in force

postOnly

boolean

No

Post-only flag

reduceOnly

boolean

No

Reduce-only flag

legs

OrderLeg[]

Yes

Order legs

nonce

number

Yes

Unique nonce

expiration

string

Yes

Expiration timestamp (nanoseconds)

OrderLeg

Field
Type
Required
Description

instrument

string

Yes

Instrument symbol

size

string

Yes

Order size

isBuyingAsset

boolean

Yes

True for buy, false for sell

limitPrice

string

Yes

Limit price (0 for market orders)

InstrumentInfo

Field
Type
Description

instrumentHash

string

Instrument hash from API

baseDecimals

number

Base currency decimals

Returns: SignedOrder

buildCreateOrderPayload

Converts a signed order into the format expected by the API.

Helper Functions

generateNonce

Generates a unique nonce for order signing.

generateExpiration

Generates an expiration timestamp.

Parameter
Type
Default
Description

durationMs

number

86400000

Duration until expiry in milliseconds

generateClientOrderId

Generates a unique client order ID.

EIP-712 Types

The SDK exports EIP-712 types for advanced use cases:

signTypedData

Low-level function for signing EIP-712 typed data with any supported wallet type.

getWalletAddress

Extract address from any supported wallet type.

Complete Example

circle-info

For most use cases, prefer `GrvtClient` which handles signing automatically. Use these low-level utilities only when you need custom signing logic.

Last updated