PollarPollar
Sdk Reference

@pollar/react

React hooks and pre-built UI components for Pollar. Built on top of @pollar/core.

Version: 0.10.1

npm install @pollar/react

<PollarProvider>

Wraps your application root. Required for all hooks and components to work. Internally renders every Pollar modal — login, transaction, send, receive, KYC, ramp, tx history, wallet balance, enabled-assets, swap, earn, sessions, and distribution-rules — so you do not need to mount them manually.

import { PollarProvider } from '@pollar/react';

<PollarProvider
  client={{ apiKey: 'pub_testnet_xxxxxxxxxxxxxxxxxxxx' }}
>
  <App />
</PollarProvider>

Props:

PropTypeRequiredDescription
clientPollarClientConfig | PollarClientYesA PollarClientConfig (the provider builds the client) or a pre-built PollarClient instance. Locked at first render.
appConfigPollarConfigNoLocal override of the remote /applications/config (styles, app name). If provided, the remote fetch is skipped.
adaptersPollarAdaptersNoTransaction-building adapters (e.g. @pollar/accesly-adapter), consumed via createPollarAdapterHook. This is not the wallet-login slot — wallet login providers go on the client's walletAdapters config; see Wallet Adapters.
onStorageDegradeOnStorageDegradeNoNotified when persistent storage silently degrades to in-memory mode.

To register wallet-login providers (Stellar Wallets Kit, Privy), put them on client.walletAdapters, not on this component. See Wallet Adapters.

PollarClientConfig:

OptionTypeDefaultDescription
apiKeystringRequired. Your Pollar API key.
stellarNetworkStellarNetwork'testnet'Target network: 'testnet' or 'mainnet'.
baseUrlstring'https://sdk.api.pollar.xyz' (the SDK appends /v1)Override the Pollar API base URL.

usePollar()

The primary hook. Provides access to all Pollar functionality from a single import. Must be used inside <PollarProvider>.

'use client';
import { usePollar } from '@pollar/react';

function MyComponent() {
  const {
    isAuthenticated,
    verified,
    wallet,
    login,
    logout,
    buildTx,
    signAndSubmitTx,
    signTx,
    submitTx,
    buildAndSignAndSubmitTx,
    runTx,
    tx,
    txHistory,
    network,
    setNetwork,
    walletBalance,
    refreshWalletBalance,
    enabledAssets,
    refreshAssets,
    setTrustline,
    getSwapConfig,
    getSwapTokens,
    getSwapQuote,
    swap,
    getEarnProviders,
    getEarnOpportunities,
    getEarnPosition,
    earnDeposit,
    earnWithdraw,
    getClient,
    openLoginModal,
    openTxModal,
    openKycModal,
    openRampModal,
    openTxHistoryModal,
    openWalletBalanceModal,
    openSendModal,
    openReceiveModal,
    openEnabledAssetsModal,
    openSwapModal,
    openEarnModal,
    openSessionsModal,
    openDistributionRulesModal,
    sessions,
    appConfig,
    styles,
  } = usePollar();
}

Authentication

PropertyTypeDescription
isAuthenticatedbooleanWhether the user has an active session.
verifiedbooleantrue once the server has confirmed the session (login / refresh / resume). false while a cold-start session is still optimistic — gate sensitive actions (e.g. signing) on this.
walletWalletInfo | nullThe authenticated wallet as a discriminated union over custody (internal | smart | external), or null when unauthenticated. Use wallet.address for the on-chain address and wallet.provider for the login/wallet provider.
login(options: PollarLoginOptions) => voidInitiates an authentication flow.
logout() => voidSigns out the current user and clears the session.

PollarLoginOptions:

ValueDescription
{ provider: 'google' }Opens Google OAuth flow.
{ provider: 'github' }Opens GitHub OAuth flow.
{ provider: 'email', email: string }Sends an OTP code to the provided email address.
{ provider: WalletType.FREIGHTER }Connects the built-in Freighter wallet (id 'freighter-native').
{ provider: WalletType.ALBEDO }Connects the built-in Albedo wallet (id 'albedo-native').
{ provider: '<adapter id>' }Any wallet registered via walletAdapters ('xbull', 'lobstr', 'privy', …). See Wallet Adapters.

Transactions

PropertyTypeDescription
txTransactionStateCurrent transaction state (reactive).
buildTx(operation, params, options?) => Promise<BuildOutcome>Builds an unsigned Stellar transaction.
signAndSubmitTx(unsignedXdr?: string) => Promise<SubmitOutcome>Signs and submits a built transaction (defaults to the current built XDR if omitted).
signTx(unsignedXdr: string) => Promise<SignOutcome>External-wallet only — sign without submitting.
submitTx(signedXdr: string) => Promise<SubmitOutcome>Submits an already-signed XDR.
buildAndSignAndSubmitTx(operation, params, options?) => Promise<SubmitOutcome>One-shot build → sign → submit.
runTx(operation, params, options?) => Promise<SubmitOutcome>Alias of buildAndSignAndSubmitTx.
openTxModal() => voidOpens the transaction modal programmatically.

The transaction modal opens automatically when buildTx is called. See @pollar/core for TransactionState step details and the per-call BuildOutcome / SignOutcome / SubmitOutcome return types.


Network

PropertyTypeDescription
networkStellarNetworkCurrently active network.
setNetwork(network: StellarNetwork) => voidSwitches the active Stellar network.

Wallet Balance

PropertyTypeDescription
walletBalanceWalletBalanceStateCurrent wallet balance state (reactive).
refreshWalletBalance() => Promise<void>Refreshes balances for the authenticated wallet. Drives walletBalance.
openWalletBalanceModal() => voidOpens the wallet balance modal.

For an arbitrary public key / network, use getClient().getWalletBalance(publicKey) from @pollar/core.


Enabled assets & trustlines

PropertyTypeDescription
enabledAssetsEnabledAssetsStateApp-enabled assets paired with the wallet's trustline state.
refreshAssets() => Promise<void>Refreshes the enabled-assets state.
setTrustline(asset: { code; issuer }, opts?: { limit?; sponsored? }) => Promise<TrustlineOutcome>Establish (omit limit) or remove (limit: '0') a trustline. Pass sponsored: true so the app covers reserve + fee when eligible.
openEnabledAssetsModal() => voidOpens the enabled-assets / trustline modal.

Swap

PropertyTypeDescription
getSwapConfig() => Promise<SwapVenue[]>Venues this app exposes (empty = swap disabled).
getSwapTokens() => Promise<SwapToken[]>Curated "buy" token catalog.
getSwapQuote(params: SwapQuoteParams) => Promise<SwapQuote[]>Quotes ranked best-first.
swap(quote: SwapQuote, opts?: { autoTrustline? }) => Promise<SubmitOutcome>Executes a quote; drives tx.
openSwapModal() => voidOpens the swap modal.

Earn

PropertyTypeDescription
getEarnProviders() => Promise<EarnProviderId[]>Yield providers this app exposes (empty = disabled).
getEarnOpportunities(provider: EarnProviderId) => Promise<EarnOpportunity[]>Vaults/pools with live APY.
getEarnPosition(params: EarnPositionParams) => Promise<EarnPosition>The wallet's position.
earnDeposit(params: EarnTxParams) => Promise<SubmitOutcome>Deposit into a vault/pool; drives tx.
earnWithdraw(params: EarnTxParams) => Promise<SubmitOutcome>Withdraw from a vault/pool; drives tx.
openEarnModal() => voidOpens the Earn modal.

Transaction History

PropertyTypeDescription
txHistoryTxHistoryStateCurrent tx history state (reactive).
openTxHistoryModal() => voidOpens the transaction history modal.

KYC

PropertyTypeDescription
openKycModal(options?: { country?: string; level?: KycLevel; onApproved?: () => void }) => voidOpens the KYC verification modal.
OptionTypeDefaultDescription
countrystring'MX'ISO 3166-1 alpha-2 country code to filter providers.
levelKycLevel'basic'Required KYC level: 'basic', 'intermediate', or 'enhanced'.
onApproved() => voidCallback invoked when the KYC verification is successfully approved.

Ramps

PropertyTypeDescription
openRampModal() => voidOpens the fiat on/off-ramp widget.

Utilities

PropertyTypeDescription
getClient() => PollarClientReturns the underlying PollarClient instance for direct API access.
appConfigPollarConfigApplication configuration fetched from the Pollar Dashboard.
stylesPollarStylesResolved styles, merging remote config with any local overrides.

Modal entry points

All Pollar modals are mounted inside <PollarProvider> and controlled programmatically:

FunctionDescription
openLoginModal()Opens the login modal.
openTxModal()Opens the transaction modal.
openKycModal(options?)Opens the KYC modal.
openRampModal()Opens the ramp widget.
openTxHistoryModal()Opens the transaction history modal.
openWalletBalanceModal()Opens the wallet balance modal.
openSendModal()Opens the send-payment modal.
openReceiveModal()Opens the receive modal.
openEnabledAssetsModal()Opens the enabled-assets / trustline modal.
openSwapModal()Opens the swap modal.
openEarnModal()Opens the Earn modal.
openSessionsModal()Opens the active-sessions modal.
openDistributionRulesModal()Opens the distribution-rules modal.

Components

<WalletButton>

Pre-built button that handles the complete authentication flow. When logged out, opens the login modal. When logged in, shows the wallet address with a dropdown for balance, transaction history, and logout.

import { WalletButton } from '@pollar/react';

<WalletButton />

No props required. Appearance comes from your remote dashboard configuration (or the appConfig override passed to <PollarProvider>), exposed as styles on usePollar().


<KycModal>

Pre-built KYC verification modal. Can be rendered directly when you need more control than openKycModal() provides.

import { KycModal } from '@pollar/react';

<KycModal
  onClose={() => setOpen(false)}
  country="US"
  level="basic"
  onApproved={() => console.log('KYC approved')}
/>
PropTypeDefaultDescription
onClose() => voidRequired. Called when the user dismisses the modal.
countrystring'MX'ISO 3166-1 alpha-2 country code to filter providers.
levelKycLevel'basic'Required KYC level.
onApproved() => voidCalled when KYC is successfully approved.

<KycStatus>

Displays the current KYC status for the authenticated user.

import { KycStatus } from '@pollar/react';

<KycStatus />

<RampWidget>

Pre-built fiat on/off-ramp widget with support for on-ramp (fiat → crypto) and off-ramp (crypto → fiat) flows.

import { RampWidget } from '@pollar/react';

<RampWidget onClose={() => setOpen(false)} />
PropTypeDescription
onClose() => voidRequired. Called when the user dismisses the widget.

<WalletBalanceModal>

Displays the token balances of the authenticated wallet with a manual refresh option.

import { WalletBalanceModal } from '@pollar/react';

<WalletBalanceModal onClose={() => setOpen(false)} />
PropTypeDescription
onClose() => voidRequired. Called when the user dismisses the modal.

Template components

Template components handle rendering only — they receive all data and callbacks as props and contain no internal logic. Use them to build fully custom UI while reusing Pollar's layout and visual structure.

ComponentDescription
<WalletButtonTemplate>Wallet button (logged-out / logged-in) presentation.
<LoginModalTemplate>Login provider selection and email OTP screens.
<KycModalTemplate>KYC provider selection and verification screens.
<RampWidgetTemplate>Ramp input, quote selection, and payment instruction screens.
<TransactionModalTemplate>Transaction details, signing, and result screens.
<TxHistoryModalTemplate>Transaction history list screen.
<WalletBalanceModalTemplate>Wallet balance screen.
<EnabledAssetsModalTemplate>Enabled-assets / trustline screen.
<SendModalTemplate>Send-payment screen.
<SwapModalTemplate>Swap screen (exports SwapAssetOption).
<ReceiveModalTemplate>Receive (address / QR) screen.
<SessionsModalTemplate>Active-sessions list screen.
<DistributionRulesModalTemplate>Claimable distribution rules screen.

Live (non-template) modal components are also exported for direct rendering: SendModal, SwapModal, EarnModal, ReceiveModal, EnabledAssetsModal, WalletBalanceModal, SessionsModal, DistributionRulesModal, plus KycStatus, RouteDisplay, and TxStatusView.

Import the corresponding *Props type for full type safety:

import {
  TransactionModalTemplate,
  type TransactionModalTemplateProps,
  WalletBalanceModalTemplate,
  type WalletBalanceModalTemplateProps,
} from '@pollar/react';

Types

import type {
  PollarConfig,
  PollarStyles,
  LoginButtonProps,
  AuthModalProps,
  KycStep,
  RampStep,
  TransactionModalTemplateProps,
  WalletBalanceModalTemplateProps,
  // re-exported from @pollar/core so you can author custom login providers
  PollarAuthProvider,
  AuthProviderContext,
} from '@pollar/react';

Core types such as WalletInfo, TransactionState, TxHistoryState, EnabledAssetsState, WalletBalanceContent, SwapQuote, EarnOpportunity, PollarLoginOptions, StellarNetwork, and WalletType are imported directly from @pollar/core.

On this page

Was this helpful?