Class: TorqueRequestClient

@torque-labs/torque-ts-sdkDocs


@torque-labs/torque-ts-sdk / TorqueRequestClient

Class: TorqueRequestClient

The TorqueRequestClient class is used to make requests to the Torque API. It provides methods for performing API requests and handling responses.

Example

const client = new TorqueRequestClient(<options>);

const response = await client.apiFetch<T>("https://api.torque.so/v1/users");

Constructors

new TorqueRequestClient()

new TorqueRequestClient(options): TorqueRequestClient

Create a new instance of the TorqueRequestClient class.

Parameters

Parameter
Type

Returns

TorqueRequestClient

Throws

Throws an error if a signer is not provided.

Defined in

src/classes/request.ts:78

Properties

Property
Type

apiAuthHeader

Record<string, string>

apiKey

undefined | string

apiUrl

string

appUrl

string

connection

undefined | Connection

functionsUrl

string

signer

undefined | Adapter | Keypair

signTransaction

undefined | SignTransaction

Methods

apiFetch()

apiFetch<T>(
   url, 
   options?, 
supressError?): Promise<T>

Perform a request to the Torque API.

Type Parameters

Type Parameter
Description

T

The type of the response data.

Parameters

Parameter
Type
Description

url

string

The URL of the API endpoint.

options?

RequestInit

The options for the request.

supressError?

boolean

-

Returns

Promise<T>

The response from the API.

Throws

If there is an error performing the request.

Defined in

src/classes/request.ts:141


buildTransaction()

private buildTransaction<T>(txnInput, token?): Promise<T & {
  serializedTx: string;
}>

Builds and returns a serialized transaction from the API based on the provided transaction input.

Type Parameters

Type Parameter
Description

T

The type of the response data.

Parameters

Parameter
Type
Description

txnInput

{ data: CreateCampaignInputSchema; txnType: CampaignCreate; } | { data: CampaignEndInputSchema; txnType: CampaignEnd; } | { data: PublisherCreateInputSchema; txnType: PublisherCreate; } | { data: PublisherPayoutInputSchema; txnType: PublisherPayout; }

The input object of the transaction to build.

token?

string

The Torque API token to use for the transaction.

Returns

Promise<T & { serializedTx: string; }>

A promise that resolves with the serialized transaction.

Throws

Throws an error if the API is not able to build the transaction.

Defined in

src/classes/request.ts:221


executeTransaction()

private executeTransaction(txnExecuteInput, token?): Promise<TxnExecuteResponse>

Executes the serialized transaction using the API.

Parameters

Parameter
Type
Description

txnExecuteInput

{ data: { blockhash: string; campaignId: string; userSignature: string; }; txnType: CampaignCreate | CampaignEnd; } | { data: TxnExecuteDefaults; txnType: string; }

The input object of the transaction to execute.

token?

string

The Torque API token to use for the transaction.

Returns

Promise<TxnExecuteResponse>

A promise that resolves with the signature of the transaction.

Throws

Throws an error if the API request is unsuccessful or if the transaction fails.

Defined in

src/classes/request.ts:263


functionsFetch()

functionsFetch<T>(url, options?): Promise<T>

Perform a request to a Torque Function endpoint.

Type Parameters

Type Parameter
Description

T

The type of the response data.

Parameters

Parameter
Type
Description

url

string

The URL of the API endpoint.

options?

RequestInit

The options for the request.

Returns

Promise<T>

The response from the API.

Throws

If there is an error performing the request.

Defined in

src/classes/request.ts:184


signWithKeypair()

private signWithKeypair(txn): VersionedTransaction

Signs a transaction with a Keypair.

Parameters

Parameter
Type
Description

txn

VersionedTransaction

The transaction to sign.

Returns

VersionedTransaction

The signed transaction.

Throws

If the signer is not initialized or if the signer is not a Keypair.

Defined in

src/classes/request.ts:366


transaction()

transaction<T>(txnInput, token?): Promise<WithSignature<T>>

Builds and executes the transaction using the Torque API.

Type Parameters

Type Parameter
Description

T

The type of the response data.

Parameters

Parameter
Type
Description

txnInput

{ data: CreateCampaignInputSchema; txnType: CampaignCreate; } | { data: CampaignEndInputSchema; txnType: CampaignEnd; } | { data: PublisherCreateInputSchema; txnType: PublisherCreate; } | { data: PublisherPayoutInputSchema; txnType: PublisherPayout; }

The input object of the transaction to process.

token?

string

The Torque API token to use for the transaction.

Returns

Promise<WithSignature<T>>

A promise that resolves with the signature of the transaction.

Defined in

src/classes/request.ts:310


anyFetch()

static anyFetch<T>(url, options?): Promise<T>

Perform a regular request to any endpoint.

Type Parameters

Type Parameter
Description

T

The type of the response data.

Parameters

Parameter
Type
Description

url

string

The URL of the API endpoint.

options?

RequestInit

The options for the request.

Returns

Promise<T>

The response from the API.

Throws

If there is an error performing the request.

Defined in

src/classes/request.ts:107

Last updated