PerpsClient trading and setup methods. Authorization follows each provider’s ProviderAction.signers and signingMethod: order-management methods normally use the plugin’s SDK-managed credential, while user-authorized operations such as Hyperliquid sendAsset can invoke the wallet.
setUserWallet
Set or update the end-user wallet. Call this when the user connects their wallet (for example, from wagmi’suseWalletClient()); pass undefined to clear it when the wallet disconnects.
The wallet is used for provider-declared
USER authorization, including setup signatures, SIWE, EVM deposit transactions, Lighter’s REGISTER_API_KEY countersignature, and user-signed transfers or withdrawals. Order-management actions use each plugin’s SDK-managed credential and do not reach this wallet.
setSwitchChain
Set or replace the chain-switching hook. Some setup and deposit actions must be signed on a specific chain; when the user’s wallet is on the wrong one, the SDK calls this hook with the targetchainId and expects it to return a wallet client on that chain (or undefined to abort). The hook can also be provided once at construction via the switchChain option on PerpsClientOptions.
getMarketSettings
Read the current venue-side margin mode and leverage that the next order on a market will use.
Returns:
MarketSettings | undefined — { marginMode, leverage }, or undefined when the provider exposes no readable market setting or does not implement the optional capability.
placeOrder
Place an order. Builds the action, auto-signs through the provider plugin, and submits in one call.
Returns:
ExecuteActionResponse with results[] array.
cancelOrders
Cancel one or more orders. Auto-signs through the provider plugin.
Returns:
ExecuteActionResponse with results[] array.
modifyOrders
Modify orders in place. Auto-signs through the provider plugin.
Returns:
ExecuteActionResponse with results[] array.
placeTriggerOrder
Place standalone trigger orders (TP/SL on existing positions). Auto-signs with the agent.
Returns:
ExecuteActionResponse with results[] array.
placeTwapOrder
Place a TWAP parent order that executes over a fixed duration. Auto-signs with the provider’s SDK-managed credential.
Returns:
ExecuteActionResponse with results[] array. A successful result carries twapId — the provider-native identifier for the placed TWAP parent.
A provider only honours the extras it declares via its
placeTwapOrder action’s params descriptors (GET /providers); other providers ignore them. See each provider’s trading page — Hyperliquid, Lighter, Ondo — for its extras and duration bounds.cancelTwapOrder
Cancel a running TWAP parent order. Auto-signs with the provider’s SDK-managed credential.
Returns:
ExecuteActionResponse with results[] array.
updatePositionMargin
Adjust position margin. Auto-signs with the agent.
Returns:
ExecuteActionResponse with results[] array.
sendAsset
Move collateral between a provider’s categories (e.g. between perps and spot). This is a convenience wrapper overexecute(SEND_ASSET) and follows the provider descriptor’s signer; Hyperliquid uses the user’s wallet.
Returns:
ExecuteActionResponse with results[] array.
Generic action helper
The high-level methods above (placeOrder, cancelOrders, modifyOrders, placeTriggerOrder, placeTwapOrder, cancelTwapOrder, updatePositionMargin) are convenience wrappers around a single generic helper. Use it directly when an action does not have a dedicated wrapper.
execute
Auto-sign-and-submit for any action type. MirrorsplaceOrder/modifyOrders/etc. but generic over ActionType. Internally builds the action, picks the correct signing pipeline (EIP-712, WASM blob, or EVM tx) from the provider’s descriptor, signs, and submits in a single create→sign→submit pass.
Returns:
ExecuteActionResponse with results[] array.
SignActionProgress is { index, total, action, functionName, chainId, status, txHash }, where status is 'submitted' (wallet broadcast, hash known) then 'confirmed' (receipt mined) — emitted twice per on-chain leg, so a consumer can render a live per-transaction stepper.Use
execute for action types without dedicated wrappers — for example UPDATE_LEVERAGE or provider-specific account-configuration actions. For trading actions with wrappers (placeOrder, cancelOrders, …), prefer the wrappers; they expose richer typed parameters.buildAction
Build the action payloads for an action without signing or submitting. Typed wrapper around thecreateAction service (see Actions / createAction) and the natural counterpart to execute — use it when you need to inspect the steps, sign them in a custom flow, or hand them off across a process boundary before calling executeAction yourself.
Returns:
CreateActionResponse — { actions: ActionStep[] }. The SDK resolves the correct signer address (agent or user) for the given action type before delegating to createAction.
Setup
Account-setup actions (e.g.APPROVE_AGENT, APPROVE_BUILDER_FEE on Hyperliquid; REGISTER_API_KEY on Lighter) are coordinated through the setup helpers. The high-level flow is described in Concepts / Action Pattern; the methods below are the lower-level building blocks.
checkSetup
Return the unsatisfied entries on the provider’ssetup descriptors for this account as a flat list. Each ActionStep is self-describing — its action keys back to the provider’s setup descriptor, which declares the step’s signer and signing scheme — so no signer-role partition is exposed here.
Returns:
ProviderSetup — { accountExists: boolean; setup: ActionStep[]; isReady: boolean; checklist: SetupChecklistItem[] }. accountExists reports whether the address already has account state with the provider. checklist is the renderable onboarding list: every USER-signed setup descriptor paired with its satisfied state ({ descriptor: ProviderAction; satisfied: boolean }), with not-yet-applicable conditional descriptors (e.g. Hyperliquid’s revokeAgent, see Providers / Hyperliquid — Setup) omitted rather than shown unsatisfied.
Provider.options descriptors are never returned here — options are post-setup tunables and never gate trading. Option state is surfaced separately via getAccount().settings.
buildProviderSetup
Build the unsigned setupActionSteps still outstanding for an account, ordered by descriptor sequence, without signing or submitting. The backend filters out already-satisfied setup — same filtering as checkSetup().setup — but the response carries only { actions }, without checkSetup’s surrounding accountExists, isReady, and checklist metadata.
Returns:
CreateActionResponse — { actions: ActionStep[] }.
executeProviderSetupAction
Sign and submit one pre-staged setupActionStep end-to-end. The caller is expected to have already obtained the step from a prior checkSetup call (no refetch). Run the outstanding steps in descriptor order:
Returns:
Promise<void>.
Requires the user wallet to be set via
setUserWallet (or passed at construction) for any step that requires the user’s L1 wallet — that includes EIP-712, EVM-tx, and Lighter’s REGISTER_API_KEY (which signs the EIP-191 message embedded in the WASM blob).executeProviderOption
Sign and submit a singleProvider.options change (a post-setup tunable such as Hyperliquid accountMode or Lighter accountType) end-to-end. Dispatches through the same pipeline as execute, but an option change is a single mandatory action: a per-action success: false throws a PerpsError, using that result’s errorCode when the backend classified the failure and falling back to PerpsErrorCode.ExchangeRejected otherwise, rather than being silently dropped.
Returns:
Promise<void> — resolves on success, throws PerpsError on venue rejection.
App-level meta actions
These three methods dispatch provider-independent app-level actions — LI.FI terms acceptance and the internal referral code — using theMETA_PROVIDER sentinel instead of a real provider key. They are always signed as EIP-712 typed data with the configured user wallet. See SDK / Actions — App-level onboarding for the full dispatch model.
submitOnboarding
Accept the current terms and, when a code is supplied and the backend accepts it, attach that internal referral code — in one signature.
Returns:
ExecuteActionResponse — resolves to { results: [] } when the backend requires no consent from this address.
createReferralCode
Reserve the shareable internal referral codeaddress owns.
Returns:
ExecuteActionResponse.
executeMetaAction
Low-level entry point bothsubmitOnboarding and createReferralCode call. Use it directly for META_ACCEPT_TERMS or any future meta action without a dedicated wrapper.
Returns:
ExecuteActionResponse. Throws PerpsError when no user wallet is configured, when the backend returns more than one step or a non-EIP-712 step, or when the submitted step reports a failed result. A wallet signature refusal propagates as the wallet’s own error.
API Reference: POST /createAction · /executeAction