Skip to main content

Class: ChainGateway

gSwap SDK 2.0.0-rc.4


gSwap SDK 2.0.0-rc.4 / ChainGateway

Class: ChainGateway

Defined in: packages/gswap-sdk/dist/index.d.ts:1590

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

Constructors​

Constructor​

new ChainGateway(options): ChainGateway

Defined in: packages/gswap-sdk/dist/index.d.ts:1603

Create a chain gateway client.

Parameters​

options​

ChainGatewayOptions

Returns​

ChainGateway

Properties​

dexBackendBaseUrl​

readonly dexBackendBaseUrl: string

Defined in: packages/gswap-sdk/dist/index.d.ts:1599

The swap backend base URL every request is sent to, without a trailing slash.


requestTimeoutMs​

readonly requestTimeoutMs: number

Defined in: packages/gswap-sdk/dist/index.d.ts:1597

The request timeout in milliseconds (Infinity when no timer is armed).


wire​

readonly wire: WireOptions

Defined in: packages/gswap-sdk/dist/index.d.ts:1601

Wire format shared by the read services built on this gateway.

Accessors​

httpRequestor​

Get Signature​

get httpRequestor(): HttpRequestor

Defined in: packages/gswap-sdk/dist/index.d.ts:1659

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>>

Defined in: packages/gswap-sdk/dist/index.d.ts:1613

Submit a signed v2 DTO through the chain gateway.

Parameters​
method​

"RequestTrade"

signedBody​

Record<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>>

Defined in: packages/gswap-sdk/dist/index.d.ts:1614

Submit a signed v2 DTO through the chain gateway.

Parameters​
method​

string

signedBody​

Record<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>

Defined in: packages/gswap-sdk/dist/index.d.ts:1635

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​

method​

string

signedBody​

Record<string, unknown>

options?​

ChainSubmitOptions

Returns​

Promise<ShadowSubmitResult>

Example​

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