Skip to main content

Class: ChainGateway

Thin client for backend-routed v2 writes: synchronous liquidity writes and queued RequestTrade.

Constructors​

Constructor​

new ChainGateway(options): ChainGateway

Create a chain gateway client.

Parameters​

ParameterType
optionsChainGatewayOptions

Returns​

ChainGateway

Properties​

PropertyModifierTypeDescription
dexBackendBaseUrlreadonlystringThe swap backend base URL every request is sent to, without a trailing slash.
requestTimeoutMsreadonlynumberThe request timeout in milliseconds (Infinity when no timer is armed).
wirereadonlyWireOptionsWire format shared by the read services built on this gateway.

Accessors​

httpRequestor​

Get Signature​

get httpRequestor(): HttpRequestor

Expose the requestor for sibling read services that share this gateway transport.

Returns​

HttpRequestor

Methods​

submit()​

Call Signature​

submit(method, signedBody, options?): Promise<SubmittedTransaction<AppliedTrade>>

Submit a signed v2 DTO through the chain gateway.

Parameters​
ParameterType
method"RequestTrade"
signedBodyRecord<string, unknown>
options?ChainSubmitOptions
Returns​

Promise<SubmittedTransaction<AppliedTrade>>

Throws​

GSwapSDKError SUBMISSION_OUTCOME_UNKNOWN when no answer was read: params.reason is 'timeout' (the POST exceeded chainCallTimeoutMs) or 'transport' (the connection failed or broke off). Either way the write MAY have been queued: keep error.uniqueKey and confirm it. Whether to offer the user a Retry (a NEW request under a fresh key) is the app's policy; the SDK states only that the outcome is unknown. Reads keep TRANSPORT_ERROR.

Call Signature​

submit(method, signedBody, options?): Promise<SubmittedTransaction<Position | null>>

Submit a signed v2 DTO through the chain gateway.

Parameters​
ParameterType
methodstring
signedBodyRecord<string, unknown>
options?ChainSubmitOptions
Returns​

Promise<SubmittedTransaction<Position | null>>

Throws​

GSwapSDKError SUBMISSION_OUTCOME_UNKNOWN when no answer was read: params.reason is 'timeout' (the POST exceeded chainCallTimeoutMs) or 'transport' (the connection failed or broke off). Either way the write MAY have been queued: keep error.uniqueKey and confirm it. Whether to offer the user a Retry (a NEW request under a fresh key) is the app's policy; the SDK states only that the outcome is unknown. Reads keep TRANSPORT_ERROR.


submitShadow()​

submitShadow(method, signedBody, options?): Promise<ShadowSubmitResult>

Submit a signed v2 DTO as a SHADOW (dark) write: the same route and body as submit, plus X-Wallet-Address and X-Shadow: true, so the swap backend marks the transaction private before it reaches the contract. The wallet address is required (the backend resolves the owner from it).

Unlike submit, EVERY HTTP status resolves: the result is the raw { httpStatus, body }, because shadow failures are classified from the status together with the body's code (SHADOW_UNAVAILABLE, SHADOW_UNSUPPORTED_TYPE, SHADOW_RELAY_REJECTED); see readShadowSubmitOutcome. Only a failure to get an answer rejects, and it rejects with SUBMISSION_OUTCOME_UNKNOWN (params.reason 'timeout' or 'transport'): the request may have been accepted. Every error it throws has error.shadow === true, and a non-SDK object that escapes (your requestor's own rejection) answers isShadowError(error).

Parameters​

ParameterType
methodstring
signedBodyRecord<string, unknown>
options?ChainSubmitOptions

Returns​

Promise<ShadowSubmitResult>

Example​

const result = await gateway.submitShadow('RequestTrade', signedDto, { walletAddress });
const outcome = readShadowSubmitOutcome('RequestTrade', signedDto, result);