PollarPollar
SDK Reference

@pollar/core

Framework-agnostic TypeScript client for Pollar. Use this package directly if you are not using React, or to build custom integrations on top of the Pollar platform.

npm install @pollar/core

PollarClient

import { PollarClient } from '@pollar/core';

const pollar = new PollarClient({
  apiKey: 'pub_testnet_xxxxxxxxxxxxxxxxxxxx',
});

Constructor options:

OptionTypeDefaultDescription
apiKeystringRequired. Your Pollar publishable key.
stellarNetworkStellarNetwork'testnet'Target Stellar network: 'testnet' or 'mainnet'.
baseUrlstring'https://sdk.api.pollar.xyz'Override the Pollar API base URL. Useful for self-hosted deployments.

Authentication

Pollar supports four authentication providers: Google OAuth, GitHub OAuth, Email OTP, and external Stellar wallets (Freighter and Albedo). All flows update AuthState, which can be observed via onAuthStateChange.


pollar.login(options)

Unified entry point for starting an authentication flow. For email, this initiates the session and sends the OTP code in a single call. For wallet providers, it connects and authenticates the wallet.

// OAuth providers
pollar.login({ provider: 'google' });
pollar.login({ provider: 'github' });

// Email OTP (sends code automatically)
pollar.login({ provider: 'email', email: 'user@example.com' });

// External wallet
pollar.login({ provider: 'wallet', type: WalletType.FREIGHTER });
pollar.login({ provider: 'wallet', type: WalletType.ALBEDO });
OptionTypeDescription
provider'google' | 'github' | 'email' | 'wallet'Authentication provider.
emailstringRequired when provider is 'email'.
typeWalletTypeRequired when provider is 'wallet'.

Email OTP — step-by-step flow

For use cases that require manual control over each step of the email OTP flow (e.g. custom UI), the following methods are available individually:

pollar.beginEmailLogin()

Initializes a new email session. Transitions AuthState to entering_email.

pollar.beginEmailLogin();

pollar.sendEmailCode(email)

Sends the OTP code to the provided email address. Must be called when AuthState.step === 'entering_email'.

pollar.sendEmailCode('user@example.com');

pollar.verifyEmailCode(code)

Verifies the OTP code entered by the user and completes authentication. Must be called when AuthState.step === 'entering_code'.

pollar.verifyEmailCode('123456');

pollar.loginWallet(type)

Directly initiates a wallet connection and authentication flow. Equivalent to login({ provider: 'wallet', type }).

import { WalletType } from '@pollar/core';

pollar.loginWallet(WalletType.FREIGHTER);
pollar.loginWallet(WalletType.ALBEDO);
ParameterTypeDescription
typeWalletTypeWalletType.FREIGHTER or WalletType.ALBEDO.

pollar.cancelLogin()

Cancels any in-progress authentication flow and resets AuthState to idle.

pollar.cancelLogin();

pollar.logout()

Signs out the current user, clears the session from storage, and resets all client state.

pollar.logout();

pollar.getAuthState()

Returns the current authentication state synchronously.

const state = pollar.getAuthState();

if (state.step === 'authenticated') {
  console.log(state.session);
}

pollar.onAuthStateChange(callback)

Subscribes to authentication state changes. The callback is invoked immediately with the current state, and on every subsequent change. Returns an unsubscribe function.

const unsubscribe = pollar.onAuthStateChange((state) => {
  if (state.step === 'authenticated') {
    console.log('Logged in:', state.session);
  }
});

// Later:
unsubscribe();

AuthState steps:

StepDescription
idleNo active session or flow.
creating_sessionCreating a client session on the server.
entering_emailWaiting for the user to provide their email address.
sending_emailSending the OTP code to the user's email.
entering_codeWaiting for the user to enter the OTP code.
verifying_email_codeVerifying the submitted OTP code.
opening_oauthOpening the OAuth provider window.
connecting_walletConnecting to the external wallet extension.
wallet_not_installedThe requested wallet extension is not installed.
authenticating_walletAuthenticating with the connected wallet.
authenticatingFinalizing authentication with the Pollar server.
authenticatedUser is authenticated. session is available.
errorAn error occurred. message and errorCode are set.

Network

pollar.getNetwork()

Returns the currently active Stellar network.

const network = pollar.getNetwork(); // 'testnet' | 'mainnet'

pollar.setNetwork(network)

Switches the active Stellar network.

pollar.setNetwork('mainnet');

pollar.onNetworkStateChange(callback)

Subscribes to network state changes. Returns an unsubscribe function.

const unsubscribe = pollar.onNetworkStateChange((state) => {
  if (state.step === 'connected') {
    console.log('Network:', state.network);
  }
});

Transactions

Pollar handles transaction building and signing through a state machine. Use onTransactionStateChange to observe progress in your UI.

pollar.buildTx(operation, params, options?)

Builds an unsigned Stellar transaction on the server. Transitions TransactionState through buildingbuilt (or error).

await pollar.buildTx('payment', {
  destination: 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  amount: '10.00',
  asset: { type: 'credit_alphanum4', code: 'USDC', issuer: 'GABC...' },
});
ParameterTypeDescription
operationstringStellar operation type (e.g. payment).
paramsobjectOperation-specific parameters.
optionsobjectOptional build-time overrides.

pollar.signAndSubmitTx(unsignedXdr)

Signs and submits a previously built transaction. For custodial wallets (social/email login), signing is performed server-side. For external wallets (Freighter/Albedo), signing is performed client-side and submitted directly to Horizon.

Must be called when TransactionState.step === 'built'.

const state = pollar.getTransactionState();

if (state?.step === 'built') {
  await pollar.signAndSubmitTx(state.buildData.unsignedXdr);
}

pollar.getTransactionState()

Returns the current transaction state synchronously, or null if no transaction is in progress.

const state = pollar.getTransactionState();

pollar.onTransactionStateChange(callback)

Subscribes to transaction state changes. Returns an unsubscribe function.

const unsubscribe = pollar.onTransactionStateChange((state) => {
  if (state.step === 'success') {
    console.log('Transaction hash:', state.hash);
  }
});

TransactionState steps:

StepDescription
idleNo transaction in progress.
buildingBuilding the transaction on the server.
builtTransaction built. buildData.unsignedXdr is available.
signingSigning and submitting the transaction.
successTransaction confirmed. hash is available.
errorTransaction failed. details may contain the error.

Wallet Balance

pollar.refreshBalance(publicKey?)

Fetches the current balances for the given public key. If omitted, uses the authenticated wallet's public key.

await pollar.refreshBalance();

pollar.getWalletBalanceState()

Returns the current wallet balance state synchronously.

const state = pollar.getWalletBalanceState();

if (state.step === 'loaded') {
  console.log(state.data.balances);
}

pollar.onWalletBalanceStateChange(callback)

Subscribes to wallet balance state changes. Returns an unsubscribe function.

const unsubscribe = pollar.onWalletBalanceStateChange((state) => {
  if (state.step === 'loaded') {
    console.log(state.data.balances);
  }
});

Transaction History

pollar.fetchTxHistory(params?)

Fetches paginated transaction history for the authenticated wallet.

await pollar.fetchTxHistory({
  limit: 20,
  type: 'payment',
  asset: 'USDC',
});
OptionTypeDefaultDescription
limitnumberNumber of records to return.
cursorstringPagination cursor from a previous response.
typestringFilter by transaction type: payment, activation, trustline, receive.
assetstringFilter by asset code.

pollar.getTxHistoryState()

Returns the current transaction history state synchronously.

const state = pollar.getTxHistoryState();

if (state.step === 'loaded') {
  console.log(state.data.records);
}

pollar.onTxHistoryStateChange(callback)

Subscribes to transaction history state changes. Returns an unsubscribe function.

const unsubscribe = pollar.onTxHistoryStateChange((state) => {
  if (state.step === 'loaded') {
    console.log(state.data.records);
  }
});

KYC

Pollar provides a KYC (Know Your Customer) flow that integrates with third-party identity verification providers.

pollar.getKycProviders(country)

Returns the list of available KYC providers for the given country code.

const providers = await pollar.getKycProviders('US');

pollar.getKycStatus(providerId?)

Returns the current KYC status for the authenticated user. Optionally scoped to a specific provider.

const status = await pollar.getKycStatus();
// 'none' | 'pending' | 'approved' | 'rejected'

pollar.startKyc(body)

Initiates a KYC verification session with the specified provider.

const session = await pollar.startKyc({
  providerId: 'provider_id',
  level: 'basic',
  redirectUrl: 'https://yourapp.com/kyc/callback',
});

pollar.resolveKyc(providerId, level?)

Resolves the outcome of a completed KYC session.

await pollar.resolveKyc('provider_id', 'basic');

pollar.pollKycStatus(providerId, opts?)

Polls the KYC status until it reaches a terminal state (approved or rejected), or until the timeout is exceeded.

const finalStatus = await pollar.pollKycStatus('provider_id', {
  intervalMs: 2000,
  timeoutMs: 60000,
});
OptionTypeDescription
intervalMsnumberPolling interval in milliseconds.
timeoutMsnumberMaximum wait time before throwing.

KycStatus values: 'none' · 'pending' · 'approved' · 'rejected'

KycLevel values: 'basic' · 'intermediate' · 'enhanced'


Ramps

Pollar supports on-ramp (fiat → crypto) and off-ramp (crypto → fiat) flows through integrated third-party providers.

pollar.getRampsQuote(query)

Returns available quotes for a ramp operation.

const quotes = await pollar.getRampsQuote({
  direction: 'onramp',
  fiatCurrency: 'USD',
  cryptoAsset: 'USDC',
  amount: '100',
});

pollar.createOnRamp(body)

Creates an on-ramp transaction (fiat → crypto).

const onramp = await pollar.createOnRamp({ ... });
console.log(onramp.paymentInstructions);

pollar.createOffRamp(body)

Creates an off-ramp transaction (crypto → fiat).

const offramp = await pollar.createOffRamp({ ... });

pollar.getRampTransaction(txId)

Returns the current state of a ramp transaction by ID.

const tx = await pollar.getRampTransaction('tx_id');
console.log(tx.status);

pollar.pollRampTransaction(txId, opts?)

Polls a ramp transaction until it reaches a terminal status.

const finalStatus = await pollar.pollRampTransaction('tx_id', {
  intervalMs: 3000,
  timeoutMs: 120000,
});
OptionTypeDescription
intervalMsnumberPolling interval in milliseconds.
timeoutMsnumberMaximum wait time before throwing.

App Config

pollar.getAppConfig()

Returns the application configuration associated with your API key, as configured in the Pollar Dashboard.

const config = await pollar.getAppConfig();

Types

import type {
  PollarClientConfig,
  PollarLoginOptions,
  AuthState,
  AuthErrorCode,
  NetworkState,
  TransactionState,
  TxBuildBody,
  TxBuildContent,
  TxHistoryState,
  TxHistoryParams,
  TxHistoryRecord,
  WalletBalanceState,
  WalletBalanceRecord,
  KycLevel,
  KycStatus,
  KycFlow,
  KycProvider,
  KycStartBody,
  KycStartResponse,
  RampsQuoteQuery,
  RampQuote,
  RampsQuoteResponse,
  RampsOnrampBody,
  RampsOnrampResponse,
  RampsOfframpBody,
  RampsOfframpResponse,
  RampsTransactionResponse,
  RampTxStatus,
  RampDirection,
  PaymentInstructions,
  PollarFlowError,
} from '@pollar/core';

import { WalletType } from '@pollar/core';

On this page

Was this helpful?