Class: TorqueRequestClient
@torque-labs/torque-ts-sdk • Docs
@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): TorqueRequestClientCreate a new instance of the TorqueRequestClient class.
Parameters
options
Returns
Throws
Throws an error if a signer is not provided.
Defined in
Properties
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
T
The type of the response data.
Parameters
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
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
T
The type of the response data.
Parameters
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
executeTransaction()
private executeTransaction(txnExecuteInput, token?): Promise<TxnExecuteResponse>Executes the serialized transaction using the API.
Parameters
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
functionsFetch()
functionsFetch<T>(url, options?): Promise<T>Perform a request to a Torque Function endpoint.
Type Parameters
T
The type of the response data.
Parameters
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
signWithKeypair()
private signWithKeypair(txn): VersionedTransactionSigns a transaction with a Keypair.
Parameters
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
transaction()
transaction<T>(txnInput, token?): Promise<WithSignature<T>>Builds and executes the transaction using the Torque API.
Type Parameters
T
The type of the response data.
Parameters
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
anyFetch()
static anyFetch<T>(url, options?): Promise<T>Perform a regular request to any endpoint.
Type Parameters
T
The type of the response data.
Parameters
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
Last updated