UserClient

Test wallet helper for simulating user signing in Builder mode.

UserClient holds a private key and can sign EIP-712 typed data and order hashes. It is a testing utility -- in production, users sign with their own wallets (MetaMask, WalletConnect, etc.).

Create a Random Test Wallet

import { UserClient } from '@opinion-labs/opinion-clob-sdk';

const user = UserClient.createRandom();
console.log(user.address);  // Random EOA address

Create from Private Key

const user = new UserClient('0xYourPrivateKey...');
console.log(user.address);  // Derived EOA address

Sign Safe Transactions

Use signTypedData() for Safe transaction signing (enable trading, split, merge, redeem, withdraw):

const txResult = await builder.buildEnableTradingTx(safeAddress);
const signature = await user.signTypedData(txResult.eip712Data);
await builder.submitSafeTx(userAddress, txResult, signature);

Parameters

Parameter
Type
Description

typedData

TypedData

EIP-712 typed data with domain, types, primaryType, and message

Returns a hex signature string (0x-prefixed).

Sign Order Hashes

Use signHash() for order signing (place order):

Parameters

Parameter
Type
Description

hashToSign

string

Hash to sign (hex string, with or without 0x prefix)

Returns a hex signature string (0x-prefixed).

File Persistence

For demo scripts, UserClient supports saving and loading from JSON files:

Notes

  • Order signing uses signHash(structHash) -- signs the hash directly.

  • Safe TX signing uses signTypedData(eip712Data) -- signs EIP-712 typed data.

  • These are two distinct signing patterns. Do not mix them up.

  • In production, replace UserClient with wallet integration (MetaMask eth_signTypedData_v4 for Safe TXs, personal_sign for order hashes).