Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.trustware.io/llms.txt

Use this file to discover all available pages before exploring further.

All types below are exported from @trustware/sdk and are available as named imports. You can use them to type your own integration code without importing runtime values.
import type {
  TrustwareConfigOptions,
  TrustwareEvent,
  TrustwareError,
  WalletInterFaceAPI,
} from "@trustware/sdk";

Public import paths

The package exposes its public surface through the root entry plus four scoped sub-paths. Pick whichever import keeps your bundle smallest:
Import pathContents
@trustware/sdkEverything — Trustware, TrustwareProvider, TrustwareWidget, types, constants, wallet helpers. Most integrations use only this.
@trustware/sdk/walletWallet adapters and detection — useWagmi, useEIP1193, connectDetectedWallet, related helpers.
@trustware/sdk/coreThe Trustware facade and core REST methods, without widget code.
@trustware/sdk/reactThe TrustwareWidget component bundle.
@trustware/sdk/constantsSDK_VERSION, API_ROOT, WALLETCONNECT_PROJECT_ID, and other constants.

Configuration

TrustwareConfigOptions

The shape passed to TrustwareProvider and Trustware.init.
type TrustwareConfigOptions = {
  apiKey: string;
  routes: {
    toChain: string;
    toToken: string;
    fromToken?: string;
    fromAddress?: string;
    toAddress?: string;
    defaultSlippage?: number;
    routeType?: string;
    options?: {
      routeRefreshMs?: number;
      fixedFromAmount?: string | number;
      minAmountOut?: string | number;
      maxAmountOut?: string | number;
    };
  };
  autoDetectProvider?: boolean;
  theme?: TrustwareWidgetTheme;
  messages?: Partial<TrustwareWidgetMessages>;
  retry?: RetryConfig;
  walletConnect?: WalletConnectConfig;
  features?: FeatureFlags;
  onError?: (error: TrustwareError) => void;
  onSuccess?: (transaction: Transaction) => void;
  onEvent?: (event: TrustwareEvent) => void;
};
FieldRequiredDescription
apiKeyYesYour Trustware API key.
routes.toChainYesDefault destination chain ID (e.g. "8453" for Base).
routes.toTokenYesDefault destination token address or symbol.
routes.toAddressNoRecipient address. Can be set later via Trustware.setDestinationAddress.
routes.defaultSlippageNoSlippage percentage. Defaults to 1.
autoDetectProviderNoWhether to auto-detect the wallet provider. Defaults to false.
features.shouldAllowGA4NoSet to false to disable SDK GA4 analytics tracking. Defaults to true.
themeNoWidget color and radius overrides. See TrustwareWidgetTheme.
messagesNoWidget title and description overrides. See TrustwareWidgetMessages.
retryNoRetry and rate-limit callback configuration. See RetryConfig.
walletConnectNoWalletConnect connector overrides. See WalletConnectConfig.
onErrorNoCallback fired on any TrustwareError.
onSuccessNoCallback fired when a transaction is confirmed. Receives the Transaction object.
onEventNoCallback fired for all SDK lifecycle events. Receives a TrustwareEvent.

ResolvedTrustwareConfig

The config object returned by Trustware.getConfig(). All optional fields have defaults applied.
type ResolvedTrustwareConfig = {
  apiKey: string;
  routes: {
    toChain: string;
    toToken: string;
    fromToken?: string;
    fromAddress?: string;
    toAddress?: string;
    defaultSlippage: number;
    routeType: string;
    options: {
      routeRefreshMs?: number;
      fixedFromAmount?: string | number;
      minAmountOut?: string | number;
      maxAmountOut?: string | number;
    };
  };
  autoDetectProvider: boolean;
  theme: TrustwareWidgetTheme;
  messages: TrustwareWidgetMessages;
  retry: ResolvedRetryConfig;
  walletConnect?: ResolvedWalletConnectConfig;
  features: ResolvedFeatureFlags;
  onError?: (error: TrustwareError) => void;
  onSuccess?: (transaction: Transaction) => void;
  onEvent?: (event: TrustwareEvent) => void;
};

RetryConfig

Controls how the SDK handles 429 Too Many Requests responses.
type RetryConfig = {
  autoRetry?: boolean;
  maxRetries?: number;
  baseDelayMs?: number;
  onRateLimitInfo?: (info: RateLimitInfo) => void;
  onRateLimited?: (info: RateLimitInfo, retryCount: number) => void;
  onRateLimitApproaching?: (info: RateLimitInfo, threshold: number) => void;
  approachingThreshold?: number;
};
FieldDefaultDescription
autoRetrytrueRetry automatically on 429 responses.
maxRetries3Maximum retry attempts.
baseDelayMs1000Base delay for exponential backoff in milliseconds.
approachingThreshold5Remaining-request count that triggers onRateLimitApproaching.

RateLimitInfo

Passed to RetryConfig callbacks when rate limit headers are present in a response.
type RateLimitInfo = {
  limit: number;
  remaining: number;
  reset: number;
  retryAfter?: number;
};

WalletConnectConfig

Optional WalletConnect overrides. The SDK includes built-in defaults for all fields.
type WalletConnectConfig = {
  projectId?: string;
  chains?: number[];
  optionalChains?: number[];
  metadata?: {
    name: string;
    description?: string;
    url: string;
    icons?: string[];
  };
  relayUrl?: string;
  showQrModal?: boolean;
  disabled?: boolean;
};

FeatureFlags

Controls optional SDK behaviours. Pass as features in TrustwareConfigOptions.
type FeatureFlags = {
  tokensPagination?: boolean;
  balanceStreaming?: boolean;
  shouldAllowGA4?: boolean;
};
FieldDefaultDescription
tokensPaginationtruePaginated token list fetching in the widget’s token picker. Emits token_page_loaded and token_page_error events. Set to false to fetch the full token list in a single request.
balanceStreamingtrueStreaming balance fetches across chains. Emits balance_stream_chunk and balance_stream_fallback events. Set to false to wait for all chains before rendering balances.
shouldAllowGA4trueWhen false, disables the SDK’s built-in Google Analytics 4 (GA4) tracking. Set this to false if your app has its own analytics pipeline, your users have opted out of tracking, or you need to comply with privacy regulations such as GDPR or CCPA.
Example — disable GA4 while keeping pagination and streaming on:
const config = {
  apiKey: process.env.NEXT_PUBLIC_TRUSTWARE_API_KEY!,
  routes: {
    toChain: "8453",
    toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  },
  features: {
    shouldAllowGA4: false,
  },
} satisfies TrustwareConfigOptions;

Theming

TrustwareWidgetTheme

Customizes the widget’s visual appearance. Pass as config.theme in TrustwareConfigOptions.
type TrustwareWidgetTheme = {
  primaryColor: string;
  secondaryColor: string;
  backgroundColor: string;
  textColor: string;
  borderColor: string;
  radius: number;
};
Defaults:
FieldDefault
primaryColor"#4F46E5" (Indigo-600)
secondaryColor"#6366F1" (Indigo-500)
backgroundColor"#FFFFFF" (White)
textColor"#111827" (Gray-900)
borderColor"#E5E7EB" (Gray-200)
radius8 (px)

TrustwareWidgetMessages

Overrides the default title and description shown in the widget header.
type TrustwareWidgetMessages = {
  title: string;
  description: string;
};

Widget

TrustwareWidgetRef

The type of the imperative handle returned when you pass a ref to TrustwareWidget.
interface TrustwareWidgetRef {
  open: () => void;
  close: () => void;
  isOpen: () => boolean;
}

Events

TrustwareEvent

A discriminated union of all events emitted via config.onEvent. Each variant has a type field you can use to narrow the type.
type TrustwareEvent =
  | { type: "error"; error: TrustwareError }
  | { type: "transaction_started" }
  | { type: "transaction_success"; txHash: string; transaction?: Transaction }
  | { type: "wallet_connected"; address: string }
  | {
      type: "token_page_loaded";
      chainRef: string;
      query?: string;
      count: number;
      hasNextPage: boolean;
      cursor?: string;
    }
  | {
      type: "token_page_error";
      chainRef: string;
      query?: string;
      cursor?: string;
      message: string;
    }
  | {
      type: "balance_stream_chunk";
      address: string;
      chunkSize: number;
    }
  | {
      type: "balance_stream_fallback";
      address: string;
      message: string;
    };
Event reference:
typeWhen it fires
errorAny SDK error, including API failures and invalid config.
transaction_startedA transaction has been initiated.
transaction_successA transaction completed successfully.
wallet_connectedA wallet was attached to the SDK.
token_page_loadedA page of tokens was fetched (pagination).
token_page_errorA token page fetch failed.
balance_stream_chunkA chunk of balances arrived from the streaming endpoint.
balance_stream_fallbackStreaming failed and the SDK fell back to a single request.

Errors

TrustwareError

Extends the native Error class. All SDK errors are instances of this class.
class TrustwareError extends Error {
  code: TrustwareErrorCode;
  userMessage?: string;
  cause?: unknown;
}
FieldDescription
codeMachine-readable error code (TrustwareErrorCode enum).
messageDeveloper-facing error message.
userMessageOptional user-facing message suitable for display in UI.
causeThe underlying error that triggered this one, if any.

TrustwareErrorCode

Enum of all error codes that can appear on a TrustwareError.
enum TrustwareErrorCode {
  INVALID_CONFIG = "INVALID_CONFIG",
  INVALID_API_KEY = "INVALID_API_KEY",
  WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED",
  BRIDGE_FAILED = "BRIDGE_FAILED",
  NETWORK_ERROR = "NETWORK_ERROR",
  UNKNOWN_ERROR = "UNKNOWN_ERROR",
  INPUT_ERROR = "INPUT_ERROR",
}
CodeDescription
INVALID_CONFIGThe config object is missing required fields or has invalid values.
INVALID_API_KEYAPI key validation against the Trustware backend failed.
WALLET_NOT_CONNECTEDA wallet operation was attempted before a wallet was attached.
BRIDGE_FAILEDThe bridge transaction failed on-chain or was rejected by the backend.
NETWORK_ERRORA network request failed (timeout, DNS failure, etc.).
UNKNOWN_ERRORAn unexpected error with no specific classification.
INPUT_ERRORInvalid user input, such as a malformed address or unsupported chain.

Routes & Transactions

BuildRouteResult

Returned by Trustware.buildRoute.
type BuildRouteResult = {
  intentId: string;
  txReq: TxRequest;
  actions: unknown[];
  finalExchangeRate: {
    fromAmountUSD?: string;
    toAmountMinUSD?: string;
  };
  route: RoutePlan | undefined;
};

Transaction

Returned by Trustware.getStatus and Trustware.pollStatus. Also passed to config.onSuccess.
type Transaction = {
  id: string;
  intentId: string;
  fromAddress: string;
  toAddress: string;
  fromChainId: string | number;
  toChainId: string | number;
  sourceTxHash: string;
  destTxHash: string;
  requestId: string;
  transactionRequest: unknown;
  status: "submitted" | "bridging" | "success" | "failed";
  statusRaw?: unknown;
  routePath?: unknown;
  routeStatus?: unknown;
  toAmountWei?: string | number;
  fromChainBlock: number;
  toChainBlock: number;
  fromChainTxUrl?: string;
  toChainTxUrl?: string;
  gasStatus?: string;
  isGMPTransaction?: boolean;
  axelarTransactionUrl?: string;
  createdDate: Date | string;
  updatedDate: Date | string;
  timeSpentMs?: number;
};

Wallet

WalletInterFaceAPI

The union type accepted by Trustware.useWallet and the wallet prop on TrustwareProvider. It is either an EVM wallet interface or a Solana wallet interface.
type WalletInterFaceAPI = EvmWalletInterface | SolanaWalletInterface;

type EvmWalletInterface = {
  ecosystem: "evm";
  getAddress(): Promise<string>;
  getChainId(): Promise<number>;
  switchChain(chainId: number): Promise<void>;
  disconnect?(): Promise<void>;
} & (
  | {
      type: "eip1193";
      request(args: { method: string; params?: unknown[] | object }): Promise<unknown>;
    }
  | {
      type: "wagmi";
      sendTransaction(tx: {
        to: `0x${string}`;
        data: `0x${string}`;
        value?: bigint;
        chainId?: number;
      }): Promise<{ hash: `0x${string}` }>;
    }
);

type SolanaWalletInterface = {
  ecosystem: "solana";
  type: "solana";
  getAddress(): Promise<string>;
  getChainKey(): Promise<string>;
  sendSerializedTransaction(
    serializedTransactionBase64: string,
    chainId?: string
  ): Promise<string>;
  disconnect?(): Promise<void>;
};

Balances

BalanceRow

A single token balance entry returned by Trustware.getBalances.
type BalanceRow = {
  chain_key: string;
  category: "native" | "erc20" | "spl" | "btc";
  contract?: string;
  address?: string;
  symbol?: string;
  decimals: number;
  balance: string;
  name?: string;
  logoURI?: string;
  usdPrice?: number;
};

WalletAddressBalanceWrapper

Wraps a set of BalanceRow entries for a specific chain, returned by Trustware.getBalancesByAddress.
type WalletAddressBalanceWrapper = {
  chain_id: string;
  balances: BalanceRow[];
  count: number;
  error: string | null;
  source: string;
};

BalanceStreamOptions

Options accepted by Trustware.getBalancesByAddress and Trustware.getBalancesByAddressStream.
type BalanceStreamOptions = {
  stream?: boolean;
  signal?: AbortSignal;
  strict?: boolean;
};