Embeddable Web3 authentication solution that integrates OAuth logins with Multi Party Computation technology for passwordless wallet access
—
Wallet interface management and payment integration with support for multiple fiat-to-crypto providers and WalletConnect.
Open and navigate the Torus wallet interface in a popup window.
/**
* Open the Torus wallet interface in a popup window
* @param path - Wallet section to display
* @param params - Optional query parameters for the wallet
*/
showWallet(path: WALLET_PATH, params?: Record<string, string>): void;
type WALLET_PATH =
| "transfer" // Send/receive tokens
| "topup" // Buy cryptocurrency
| "home" // Main wallet dashboard
| "settings" // Wallet settings
| "history" // Transaction history
| "discover"; // DApp browser/discoveryUsage Examples:
// Open main wallet dashboard
torus.showWallet("home");
// Open transfer page
torus.showWallet("transfer");
// Open topup page with specific token
torus.showWallet("topup", {
selectedCryptoCurrency: "ETH",
selectedCurrency: "USD"
});
// Open transaction history
torus.showWallet("history");
// Open settings with specific tab
torus.showWallet("settings", {
tab: "privacy"
});Initiate cryptocurrency purchases through integrated payment providers.
/**
* Initiate fiat-to-crypto purchase through payment providers
* @param provider - Payment provider to use
* @param params - Payment configuration parameters
* @returns Promise resolving to success status
*/
initiateTopup(provider: PAYMENT_PROVIDER_TYPE, params: PaymentParams): Promise<boolean>;
type PAYMENT_PROVIDER_TYPE =
| "moonpay" // MoonPay
| "rampnetwork" // Ramp Network
| "mercuryo" // Mercuryo
| "transak" // Transak
| "banxa"; // Banxa
interface PaymentParams {
/** Recipient wallet address */
selectedAddress?: string;
/** Fiat currency for payment */
selectedCurrency?: string;
/** Amount in fiat currency */
fiatValue?: number;
/** Cryptocurrency to purchase */
selectedCryptoCurrency?: string;
/** Blockchain network for the purchase */
chainNetwork?: SUPPORTED_PAYMENT_NETWORK_TYPE;
}
type SUPPORTED_PAYMENT_NETWORK_TYPE =
| "mainnet" // Ethereum
| "matic" // Polygon
| "bsc_mainnet" // Binance Smart Chain
| "avalanche_mainnet" // Avalanche
| "xdai" // Gnosis Chain
| "arbitrum_mainnet" // Arbitrum
| "optimism_mainnet"; // OptimismUsage Examples:
// Basic topup with MoonPay
const success = await torus.initiateTopup("moonpay", {
selectedAddress: "0x742d35Cc6765C788200b9aa5FdCFD9A3ebFCF2d7",
selectedCurrency: "USD",
fiatValue: 100,
selectedCryptoCurrency: "ETH",
chainNetwork: "mainnet"
});
if (success) {
console.log("Payment process initiated");
}
// Buy MATIC on Polygon
await torus.initiateTopup("transak", {
selectedCurrency: "EUR",
fiatValue: 50,
selectedCryptoCurrency: "MATIC",
chainNetwork: "matic"
});
// Buy BNB on BSC
await torus.initiateTopup("banxa", {
selectedCurrency: "GBP",
fiatValue: 200,
selectedCryptoCurrency: "BNB",
chainNetwork: "bsc_mainnet"
});Display WalletConnect QR code scanner for connecting to dApps.
/**
* Show WalletConnect QR code scanner interface
* Requires useWalletConnect to be enabled and user to be logged in
* @returns Promise resolving to success status
*/
showWalletConnectScanner(): Promise<boolean>;Usage Example:
// Initialize with WalletConnect support
await torus.init({
useWalletConnect: true,
// ... other config
});
// After user login, show WalletConnect scanner
if (torus.isLoggedIn) {
try {
const success = await torus.showWalletConnectScanner();
if (success) {
console.log("WalletConnect scanner opened");
}
} catch (error) {
console.error("Failed to open WalletConnect scanner:", error);
}
}Access and validate available payment providers.
/** Available payment providers with configurations */
readonly paymentProviders: Record<PAYMENT_PROVIDER_TYPE, IPaymentProvider>;
interface IPaymentProvider {
/** Provider description line 1 */
line1: string;
/** Provider description line 2 */
line2: string;
/** Provider description line 3 */
line3: string;
/** Support page URL */
supportPage: string;
/** Minimum order value */
minOrderValue: number;
/** Maximum order value */
maxOrderValue: number;
/** Supported fiat currencies */
validCurrencies: string[];
/** Supported cryptocurrencies by chain */
validCryptoCurrenciesByChain: Partial<Record<string, { value: string; display: string }[]>>;
/** Whether fees are included in the price */
includeFees: boolean;
/** Whether maximum limits are enforced */
enforceMax: boolean;
/** Whether selling is supported */
sell?: boolean;
}Usage Example:
// Check available payment providers
const providers = torus.paymentProviders;
Object.entries(providers).forEach(([key, provider]) => {
console.log(`${key}:`, {
description: `${provider.line1} - ${provider.line2}`,
limits: `${provider.minOrderValue} - ${provider.maxOrderValue}`,
currencies: provider.validCurrencies,
supportsSelling: provider.sell
});
});
// Validate provider supports specific currency and amount
function canUseProvider(providerType: PAYMENT_PROVIDER_TYPE, currency: string, amount: number): boolean {
const provider = torus.paymentProviders[providerType];
return provider.validCurrencies.includes(currency) &&
amount >= provider.minOrderValue &&
amount <= provider.maxOrderValue;
}
if (canUseProvider("moonpay", "USD", 100)) {
await torus.initiateTopup("moonpay", {
selectedCurrency: "USD",
fiatValue: 100
});
}Check wallet state and configure wallet-related settings.
/** Whether the wallet widget button is currently visible */
readonly torusWidgetVisibility: boolean;
/** Whether the iframe is currently in fullscreen mode */
readonly isIframeFullScreen: boolean;Usage Example:
// Check wallet state
console.log("Wallet state:", {
widgetVisible: torus.torusWidgetVisibility,
fullscreen: torus.isIframeFullScreen,
loggedIn: torus.isLoggedIn
});
// Show wallet conditionally
if (torus.isLoggedIn && !torus.torusWidgetVisibility) {
torus.showTorusButton();
}For applications requiring custom payment flows or additional validation.
// Custom payment validation
async function initiateCustomTopup(amount: number, currency: string, crypto: string) {
// Validate user is logged in
if (!torus.isLoggedIn) {
throw new Error("User must be logged in to purchase crypto");
}
// Get user's current address
const address = torus.provider.selectedAddress;
if (!address) {
throw new Error("No active wallet address");
}
// Find suitable payment provider
const suitableProvider = findBestProvider(amount, currency, crypto);
// Initiate purchase
try {
const success = await torus.initiateTopup(suitableProvider, {
selectedAddress: address,
selectedCurrency: currency,
fiatValue: amount,
selectedCryptoCurrency: crypto,
chainNetwork: getCurrentNetwork()
});
if (success) {
// Track purchase initiation
analytics.track("crypto_purchase_initiated", {
provider: suitableProvider,
amount,
currency,
crypto
});
}
return success;
} catch (error) {
console.error("Purchase failed:", error);
throw error;
}
}
function findBestProvider(amount: number, currency: string, crypto: string): PAYMENT_PROVIDER_TYPE {
const providers = torus.paymentProviders;
// Find providers that support the currency and amount
const suitable = Object.entries(providers).filter(([key, provider]) =>
provider.validCurrencies.includes(currency) &&
amount >= provider.minOrderValue &&
amount <= provider.maxOrderValue
);
if (suitable.length === 0) {
throw new Error(`No provider supports ${currency} for amount ${amount}`);
}
// Return the first suitable provider (or implement custom logic)
return suitable[0][0] as PAYMENT_PROVIDER_TYPE;
}
function getCurrentNetwork(): SUPPORTED_PAYMENT_NETWORK_TYPE {
const chainId = torus.provider.chainId;
switch (chainId) {
case "0x1": return "mainnet";
case "0x89": return "matic";
case "0x38": return "bsc_mainnet";
case "0xa86a": return "avalanche_mainnet";
case "0x64": return "xdai";
case "0xa4b1": return "arbitrum_mainnet";
case "0xa": return "optimism_mainnet";
default: return "mainnet";
}
}const PAYMENT_PROVIDER = {
MOONPAY: "moonpay",
RAMPNETWORK: "rampnetwork",
MERCURYO: "mercuryo",
TRANSAK: "transak",
BANXA: "banxa"
} as const;
const SUPPORTED_PAYMENT_NETWORK = {
MAINNET: "mainnet",
MATIC: "matic",
BSC_MAINNET: "bsc_mainnet",
AVALANCHE_MAINNET: "avalanche_mainnet",
XDAI: "xdai",
ARBITRUM_MAINNET: "arbitrum_mainnet",
OPTIMISM_MAINNET: "optimism_mainnet"
} as const;Install with Tessl CLI
npx tessl i tessl/npm-toruslabs--torus-embed