OZRelayerClient

class OZRelayerClient(relayerUrl: String, timeoutMs: Long = OZConstants.DEFAULT_RELAYER_TIMEOUT_MS, injectedClient: HttpClient? = null) : AutoCloseable

Client for submitting transactions to an OpenZeppelin Smart Account relayer.

The relayer provides fee sponsoring by wrapping user transactions with fee bumps, enabling gasless onboarding and transactions for users with empty wallets.

Two submission modes are supported:

  1. Host Function + Auth Entries: Submit transaction components separately for the relayer to construct and wrap the full transaction.

  2. Signed Transaction XDR: Submit a complete, signed transaction envelope for the relayer to wrap and submit.

Example usage:

val relayer = OZRelayerClient(relayerUrl = "https://relayer.example.com")

// Mode 1: Submit host function and auth entries
val hostFunction = // ... HostFunctionXdr
val authEntries = // ... List<SorobanAuthorizationEntryXdr>
val response = relayer.send(hostFunction, authEntries)

// Mode 2: Submit signed transaction XDR
val txEnvelope = // ... TransactionEnvelopeXdr
val response = relayer.sendXdr(txEnvelope)

if (response.success) {
println("Transaction hash: ${response.hash ?: "unknown"}")
} else {
println("Error: ${response.error ?: "unknown"} (${response.errorCode ?: ""})")
}

Parameters

relayerUrl

The relayer endpoint URL (trailing slashes are stripped)

timeoutMs

Default request timeout in milliseconds (default: 6 minutes for testnet retries)

injectedClient

Optional pre-configured HTTP client, typically used for testing. The caller retains ownership and is responsible for closing it.

Throws

if relayerUrl is blank or does not use HTTPS (http://localhost is permitted for development)

Constructors

Link copied to clipboard
constructor(relayerUrl: String, timeoutMs: Long = OZConstants.DEFAULT_RELAYER_TIMEOUT_MS, injectedClient: HttpClient? = null)

Functions

Link copied to clipboard
open override fun close()

Closes the owned HTTP client and releases resources.

Link copied to clipboard
suspend fun send(hostFunction: HostFunctionXdr, authEntries: List<SorobanAuthorizationEntryXdr>, perRequestTimeoutMs: Long? = null): RelayerResponse

Submits a transaction using host function and authorization entries.

Link copied to clipboard
suspend fun sendXdr(transactionEnvelope: TransactionEnvelopeXdr, perRequestTimeoutMs: Long? = null): RelayerResponse

Submits a complete signed transaction envelope.