Embeddable Web3 authentication solution that integrates OAuth logins with Multi Party Computation technology for passwordless wallet access
—
Ethereum network configuration and Web3 provider management with support for multiple networks and custom RPC endpoints.
Change the Ethereum network configuration for the wallet and provider.
/**
* Change the Ethereum network provider configuration
* Opens provider change confirmation window for user approval
* @param network - Network configuration parameters
* @returns Promise that resolves when network change is complete
*/
setProvider(network: NetworkInterface): Promise<void>;
interface NetworkInterface {
/** Ethereum network host (predefined network or custom RPC URL) */
host: ETHEREUM_NETWORK_TYPE | string;
/** Network chain ID (auto-detected if not provided) */
chainId?: number;
/** Display name for the network */
networkName?: string;
/** Block explorer URL for transactions */
blockExplorer?: string;
/** Native currency ticker symbol */
ticker?: string;
/** Native currency display name */
tickerName?: string;
}Usage Examples:
// Switch to Polygon network
await torus.setProvider({
host: "matic",
chainId: 137,
networkName: "Polygon Mainnet",
blockExplorer: "https://polygonscan.com",
ticker: "MATIC",
tickerName: "Polygon"
});
// Switch to custom RPC
await torus.setProvider({
host: "https://rpc.ankr.com/avalanche",
chainId: 43114,
networkName: "Avalanche Network",
blockExplorer: "https://snowtrace.io",
ticker: "AVAX",
tickerName: "Avalanche"
});
// Switch to mainnet (minimal config)
await torus.setProvider({
host: "mainnet"
});Get public address information for specific verifiers and users.
/**
* Get public address for a verifier and verifier ID
* Can return extended public key information
* @param args - Verifier arguments
* @returns Promise resolving to address string or extended public key
*/
getPublicAddress(args: VerifierArgs): Promise<string | TorusPublicKey>;
interface VerifierArgs {
/** OAuth verifier type */
verifier: "google" | "reddit" | "discord";
/** User identifier for the verifier */
verifierId: string;
/** Return extended public key information */
isExtended?: boolean;
}
interface TorusPublicKey {
/** Ethereum address */
address: string;
/** X coordinate of public key */
X: string;
/** Y coordinate of public key */
Y: string;
}Usage Examples:
// Get basic address
const address = await torus.getPublicAddress({
verifier: "google",
verifierId: "user@gmail.com"
});
console.log("Address:", address);
// Get extended public key information
const publicKey = await torus.getPublicAddress({
verifier: "discord",
verifierId: "user-discord-id",
isExtended: true
}) as TorusPublicKey;
console.log("Extended info:", {
address: publicKey.address,
publicKeyX: publicKey.X,
publicKeyY: publicKey.Y
});type ETHEREUM_NETWORK_TYPE =
| "sepolia" // Ethereum Sepolia testnet
| "mainnet" // Ethereum mainnet
| "goerli" // Ethereum Goerli testnet (deprecated)
| "localhost" // Local development network
| "matic" // Polygon mainnet
| "mumbai" // Polygon Mumbai testnet
| "xdai" // Gnosis Chain
| "bsc_mainnet" // Binance Smart Chain mainnet
| "bsc_testnet"; // Binance Smart Chain testnetAccess current network state through the provider.
/** Access Ethereum provider instance */
readonly provider: TorusInpageProvider;
readonly ethereum: TorusInpageProvider; // Alias for provider
// Provider properties for network information
interface TorusInpageProvider {
/** Current chain ID in hex format */
readonly chainId: string | null;
/** Current network version */
readonly networkVersion: string | null;
/** Currently selected account address */
readonly selectedAddress: string | null;
}Usage Example:
// Get current network information
console.log("Current network:", {
chainId: torus.provider.chainId,
networkVersion: torus.provider.networkVersion,
selectedAddress: torus.provider.selectedAddress
});
// Listen for network changes
torus.provider.on("chainChanged", (chainId) => {
console.log("Network changed to:", chainId);
});
torus.provider.on("accountsChanged", (accounts) => {
console.log("Account changed to:", accounts[0]);
});For applications requiring specific network configurations or enterprise deployments.
// Example custom network configurations
const customNetworks = {
// Private enterprise network
enterprise: {
host: "https://rpc.enterprise.com",
chainId: 12345,
networkName: "Enterprise Network",
blockExplorer: "https://explorer.enterprise.com",
ticker: "ENT",
tickerName: "Enterprise Token"
},
// Layer 2 solution
arbitrum: {
host: "https://arb1.arbitrum.io/rpc",
chainId: 42161,
networkName: "Arbitrum One",
blockExplorer: "https://arbiscan.io",
ticker: "ETH",
tickerName: "Ether"
},
// Optimism network
optimism: {
host: "https://mainnet.optimism.io",
chainId: 10,
networkName: "Optimism",
blockExplorer: "https://optimistic.etherscan.io",
ticker: "ETH",
tickerName: "Ether"
}
};
// Usage
await torus.setProvider(customNetworks.arbitrum);The provider automatically validates network configurations and will prompt users for approval when switching networks.
// The following operations may trigger user confirmation dialogs:
// 1. Network switching
await torus.setProvider({ host: "matic" });
// 2. Custom RPC addition
await torus.setProvider({
host: "https://custom-rpc.com",
chainId: 999,
networkName: "Custom Network"
});
// Error handling for network operations
try {
await torus.setProvider(networkConfig);
} catch (error) {
if (error.code === 4001) {
console.log("User rejected network change");
} else {
console.error("Network change failed:", error.message);
}
}// Predefined payment networks (for fiat-to-crypto)
type SUPPORTED_PAYMENT_NETWORK_TYPE =
| "mainnet" // Ethereum mainnet
| "matic" // Polygon
| "bsc_mainnet" // Binance Smart Chain
| "avalanche_mainnet" // Avalanche
| "xdai" // Gnosis Chain
| "arbitrum_mainnet" // Arbitrum
| "optimism_mainnet"; // Optimism
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