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
Constructors
new TorqueRequestClient()
Create 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
Methods
apiFetch()
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()
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()
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()
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()
Signs 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()
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()
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