Skip to main content

Overview

RelayerClient handles communication with a relayer proxy for fee-sponsored transactions. It’s created automatically when you pass relayerUrl to SmartAccountKit, and accessed via kit.relayer.
import { RelayerClient } from 'smart-account-kit';
Configure a relayerUrl and the SDK handles routing automatically:
const kit = new SmartAccountKit({
  // ...
  relayerUrl: 'https://my-relayer.example.com',
});

// Uses relayer automatically
await kit.transfer(tokenContract, recipient, amount);

// Bypass relayer for a specific call
await kit.transfer(tokenContract, recipient, amount, { forceMethod: 'rpc' });

// Access client directly
if (kit.relayer) {
  const result = await kit.relayer.sendXdr(signedTx);
}

Direct Usage

const relayer = new RelayerClient('https://my-relayer.example.com');

send()

Submit a transaction via func + auth (for invokeHostFunction flows). The relayer wraps it in a fee bump and sponsors fees.
const result = await relayer.send(
  funcXdr: string,
  authXdrs: string[]
): Promise<RelayerResponse>

sendXdr()

Submit a fully signed transaction XDR. Used for deployments and other non-invoke flows.
const result = await relayer.sendXdr(
  signedTransactionXdr: string
): Promise<RelayerResponse>

Response

import type { RelayerResponse } from 'smart-account-kit';

interface RelayerResponse {
  success: boolean;
  hash?: string;        // Transaction hash on success
  error?: string;       // Error message on failure
  errorCode?: RelayerErrorCode;
}

Error Codes

import { RelayerErrorCodes } from 'smart-account-kit';
import type { RelayerErrorCode } from 'smart-account-kit';
CodeDescription
NETWORK_ERRORCould not reach the relayer
SUBMISSION_FAILEDRelayer received the request but the transaction failed
INVALID_REQUESTMalformed request
TIMEOUTRelayer did not respond in time