RelayerForwarder
Umbra SDK reference for Relayer Forwarder.
Defined in: src/client/implementation/relayer-forwarder.ts:174
Transaction forwarder implementation that uses a relayer service to forward transactions.
Remarks
This forwarder submits transactions to a relayer service endpoint. The endpoint URL is
constructed by appending the relayer's public key to the base URL defined in
RELAYER_BASE_URL. Transactions are sent as base64-encoded payloads and the relayer
returns transaction signatures.
Features:
- Relayer service submission via HTTP
- Sequential transaction forwarding
- Fixed and variable delay support between transactions
- Offset-based forwarding support
- Comprehensive error handling with specific error types
Example
// Create from relayer public key (uses RELAYER_BASE_URL constant)
const relayerPublicKey = new PublicKey('...') as SolanaAddress;
const forwarder = RelayerForwarder.fromPublicKey(relayerPublicKey);
// Forward a single transaction
const signature = await forwarder.forwardTransaction(signedTx);
// Forward multiple transactions sequentially
const signatures = await forwarder.forwardTransactions([tx1, tx2, tx3]);Extends
Properties
relayerPublicKey
readonlyrelayerPublicKey:SolanaAddress
Defined in: src/client/implementation/relayer-forwarder.ts:178
The relayer's public key used to construct the endpoint URL.
Methods
forwardTransaction()
forwardTransaction(
transaction):Promise<string>
Defined in: src/client/implementation/relayer-forwarder.ts:500
Forwards a single signed transaction to the network via relayer service.
Parameters
transaction
VersionedTransaction
The signed VersionedTransaction to forward
Returns
Promise<string>
A promise resolving to the transaction signature
Throws
RelayerTransactionForwardingError When forwarding fails due to network errors, invalid transaction, or relayer service errors
Remarks
This method submits a single signed transaction to the relayer service endpoint. The transaction is base64-encoded and sent via HTTP POST. The relayer service processes the transaction and returns the signature. The transaction must be fully signed before calling this method.
Example
const signedTx = await signer.signTransaction(transaction);
const signature = await forwarder.forwardTransaction(signedTx);
console.log(`Transaction forwarded via relayer: ${signature}`);Overrides
ITransactionForwarder.forwardTransaction
forwardTransactions()
Internal
Implementation of forwardTransactions that handles all overloads.
Call Signature
forwardTransactions(
transactions):Promise<string[]>
Defined in: src/client/implementation/relayer-forwarder.ts:531
Forwards multiple signed transactions to the network in a batch operation.
Parameters
transactions
VersionedTransaction[]
Array of signed VersionedTransaction objects to forward
Returns
Promise<string[]>
A promise resolving to an array of transaction signatures in the same order as input
Throws
RelayerBatchTransactionForwardingError When forwarding fails for any transaction in the batch
Remarks
This method submits multiple signed transactions to the relayer service sequentially. Each transaction is sent and confirmed before the next one is sent. All transactions must be fully signed before calling this method.
Execution Flow:
- Send and confirm
transactions[0] - Send and confirm
transactions[1] - Continue for all transactions
Example
const signedTxs = await signer.signTransactions(transactions);
const signatures = await forwarder.forwardTransactions(signedTxs);
// signatures[0] corresponds to transactions[0], signatures[1] to transactions[1], etc.Overrides
ITransactionForwarder.forwardTransactions
Call Signature
forwardTransactions(
transactions,delayMs):Promise<string[]>
Defined in: src/client/implementation/relayer-forwarder.ts:565
Forwards multiple signed transactions to the network with a fixed delay between each transaction.
Parameters
transactions
VersionedTransaction[]
Array of signed VersionedTransaction objects to forward
delayMs
number
Fixed delay in milliseconds to wait between forwarding each transaction
Returns
Promise<string[]>
A promise resolving to an array of transaction signatures in the same order as input
Throws
RelayerBatchTransactionForwardingError When forwarding fails for any transaction in the batch
Remarks
This overload submits transactions sequentially with a fixed delay between each submission. The delay helps prevent rate limiting and allows for better transaction ordering control.
Execution Flow:
- Send and confirm
transactions[0] - Wait
delayMsmilliseconds - Send and confirm
transactions[1] - Wait
delayMsmilliseconds - Continue for all transactions
This is useful when you need to space out transactions to avoid network congestion or rate limiting issues.
Example
const signedTxs = await signer.signTransactions(transactions);
// Forward with 500ms delay between each transaction
const signatures = await forwarder.forwardTransactions(signedTxs, 500);Overrides
ITransactionForwarder.forwardTransactions
Call Signature
forwardTransactions(
transactions,delaysMs):Promise<string[]>
Defined in: src/client/implementation/relayer-forwarder.ts:606
Forwards multiple signed transactions to the network with variable delays between transactions.
Parameters
transactions
VersionedTransaction[]
Array of signed VersionedTransaction objects to forward
delaysMs
number[]
Array of delays in milliseconds between each transaction (must have length transactions.length - 1)
Returns
Promise<string[]>
A promise resolving to an array of transaction signatures in the same order as input
Throws
RelayerBatchTransactionForwardingError When forwarding fails for any transaction in the batch
Throws
RelayerInvalidDelayArrayError When the delays array length does not match transactions.length - 1
Remarks
This overload submits transactions sequentially with variable delays between each submission. Each delay in the array corresponds to the wait time after forwarding the transaction at the same index.
Execution Flow:
- Send and confirm
transactions[0] - Wait
delaysMs[0]milliseconds - Send and confirm
transactions[1] - Wait
delaysMs[1]milliseconds - Continue for all transactions
The delaysMs array must have exactly transactions.length - 1 elements, as there is
one delay between each pair of transactions (no delay needed after the last transaction).
This is useful when you need different delays between different transactions, such as longer delays for more critical transactions or adaptive delays based on network conditions.
Example
const signedTxs = await signer.signTransactions(transactions);
// Variable delays: 200ms after first, 500ms after second, 300ms after third
const delays = [200, 500, 300];
const signatures = await forwarder.forwardTransactions(signedTxs, delays);Overrides
ITransactionForwarder.forwardTransactions
Call Signature
forwardTransactions(
transactions,offset,delayMs):Promise<string[]>
Defined in: src/client/implementation/relayer-forwarder.ts:647
Forwards multiple signed transactions to the network starting from a specific offset with a fixed delay between each transaction.
Parameters
transactions
VersionedTransaction[]
Array of signed VersionedTransaction objects to forward
offset
number
The index in the array to start forwarding from (0-based). Transactions before this index are skipped.
delayMs
number
Fixed delay in milliseconds to wait between forwarding each transaction
Returns
Promise<string[]>
A promise resolving to an array of transaction signatures in the same order as the remaining transactions
Throws
RelayerBatchTransactionForwardingError When forwarding fails for any transaction in the batch or when offset is out of bounds
Remarks
This overload combines offset-based forwarding with a fixed delay between transactions.
Transactions before the offset are skipped, and the remaining transactions are forwarded
sequentially with a fixed delay between each. To forward without delay, pass 0 as delayMs.
Execution Flow:
- Skip transactions from index 0 to
offset - 1 - Send and confirm
transactions[offset] - Wait
delayMsmilliseconds (ifdelayMs > 0) - Send and confirm
transactions[offset + 1] - Wait
delayMsmilliseconds (ifdelayMs > 0) - Continue for all remaining transactions
The returned array contains results only for transactions starting from the offset.
For example, if offset = 2 and there are 5 transactions, only results for
transactions[2], transactions[3], and transactions[4] are returned.
Example
const signedTxs = await signer.signTransactions(transactions);
// Resume from index 2 with 500ms delay between each
const signatures = await forwarder.forwardTransactions(signedTxs, 2, 500);
// Or resume from index 3 without delay
const signatures = await forwarder.forwardTransactions(signedTxs, 3, 0);Overrides
ITransactionForwarder.forwardTransactions
Call Signature
forwardTransactions(
transactions,offset,delaysMs):Promise<string[]>
Defined in: src/client/implementation/relayer-forwarder.ts:688
Forwards multiple signed transactions to the network starting from a specific offset with variable delays between transactions.
Parameters
transactions
VersionedTransaction[]
Array of signed VersionedTransaction objects to forward
offset
number
The index in the array to start forwarding from (0-based). Transactions before this index are skipped.
delaysMs
number[]
Array of delays in milliseconds between each transaction (must have length equal to remaining transactions minus 1)
Returns
Promise<string[]>
A promise resolving to an array of transaction signatures in the same order as the remaining transactions
Throws
RelayerBatchTransactionForwardingError When forwarding fails for any transaction in the batch or when offset is out of bounds
Throws
RelayerInvalidDelayArrayError When the delays array length does not match (transactions.length - offset) - 1
Remarks
This overload combines offset-based forwarding with variable delays between transactions. Transactions before the offset are skipped, and the remaining transactions are forwarded sequentially with variable delays between each.
Execution Flow:
- Skip transactions from index 0 to
offset - 1 - Send and confirm
transactions[offset] - Wait
delaysMs[0]milliseconds - Send and confirm
transactions[offset + 1] - Wait
delaysMs[1]milliseconds - Continue for all remaining transactions
The delaysMs array must have exactly (transactions.length - offset) - 1 elements,
as there is one delay between each pair of remaining transactions.
Example
const signedTxs = await signer.signTransactions(transactions);
// Resume from index 1 with variable delays: 200ms, 500ms, 300ms
const delays = [200, 500, 300];
const signatures = await forwarder.forwardTransactions(signedTxs, 1, delays);Overrides
ITransactionForwarder.forwardTransactions
fromPublicKey()
staticfromPublicKey(relayerPublicKey):RelayerForwarder
Defined in: src/client/implementation/relayer-forwarder.ts:207
Creates a RelayerForwarder from a relayer public key.
Parameters
relayerPublicKey
The relayer's public key (will be appended to RELAYER_BASE_URL)
Returns
RelayerForwarder
A new RelayerForwarder instance
Remarks
The endpoint URL is constructed using the RELAYER_BASE_URL constant
from @/constants/anchor with the relayer's public key appended.
The full endpoint URL will be: ${RELAYER_BASE_URL}${relayerPublicKey.toBase58()}
Example
const relayerPublicKey = new PublicKey('...') as SolanaAddress;
const forwarder = RelayerForwarder.fromPublicKey(relayerPublicKey);getRandomRelayerForwarder()
staticgetRandomRelayerForwarder():Promise<RelayerForwarder>
Defined in: src/client/implementation/relayer-forwarder.ts:241
Creates a RelayerForwarder using a randomly selected relayer.
Returns
Promise<RelayerForwarder>
A promise resolving to a new RelayerForwarder instance.
Remarks
This method selects a random relayer index and queries the relayer
discovery service at https://relayer.umbraprivacy.com to obtain
the corresponding relayer public key.
Request body
{ "relayerIndex": number }Successful response
{ "relayerPublicKey": string }Error response
{ "error": object }Throws
RelayerServiceError When the relayer discovery service returns an error object.
Throws
RelayerTransactionForwardingError When the HTTP request fails or the response format is invalid.
getRelayerList()
staticgetRelayerList():Promise<SolanaAddress[]>
Defined in: src/client/implementation/relayer-forwarder.ts:326
Fetches the list of currently registered relayer public keys.
Returns
Promise<SolanaAddress[]>
A promise resolving to an array of SolanaAddress values.
Remarks
This method performs a simple GET request to https://relayer.umbraprivacy.com.
The service responds with either:
Successful response
{ "relayerPublicKeys": string[] }Error response
{ "error": object }At most 10 relayer public keys will be returned.
Throws
RelayerServiceError When the relayer discovery service returns an error object.
Throws
RelayerTransactionForwardingError When the HTTP request fails or the response format is invalid.