UNPKG

@bit-gpt/h402

Version:

BitGPT's 402 open protocol for blockchain-native payments

116 lines 3.82 kB
import { createPublicClient, createWalletClient, http, publicActions, } from "viem"; import { baseSepolia, avalancheFuji, bsc } from "viem/chains"; import { privateKeyToAccount } from "viem/accounts"; import { EvmNetworkToChainId } from "../network.js"; /** * Creates a public client based on the provided network ID * * @param networkId - The network ID to create a client for * @returns A public client instance for the specified network * @throws Error if the network ID is not supported */ export function getPublicClient(networkId) { switch (networkId) { /* case EvmNetworkToChainId.get("base")?.toString(): return createClientSepolia(); case EvmNetworkToChainId.get("avalanche")?.toString(): return createClientAvalancheFuji(); */ case EvmNetworkToChainId.get("bsc")?.toString(): return createClientBsc(); default: throw new Error(`Unsupported network ID: ${networkId}`); } } /** * Creates a public client configured for the Base Sepolia testnet * * @returns A public client instance connected to Base Sepolia */ export function createClientSepolia() { return createPublicClient({ chain: baseSepolia, transport: http(), }).extend(publicActions); } /** * Creates a public client configured for the Avalanche Fuji testnet * * @returns A public client instance connected to Avalanche Fuji */ export function createClientAvalancheFuji() { return createPublicClient({ chain: avalancheFuji, transport: http(), }).extend(publicActions); } /** * Creates a public client configured for the BSC mainnet * * @returns A public client instance connected to BSC */ export function createClientBsc() { return createPublicClient({ chain: bsc, transport: http(), }).extend(publicActions); } /** * Creates a wallet client configured for the Base Sepolia testnet with a private key * * @param privateKey - The private key to use for signing transactions * @returns A wallet client instance connected to Base Sepolia with the provided private key */ export function createSignerSepolia(privateKey) { return createWalletClient({ chain: baseSepolia, transport: http(), account: privateKeyToAccount(privateKey), }).extend(publicActions); } /** * Creates a wallet client configured for the Avalanche Fuji testnet with a private key * * @param privateKey - The private key to use for signing transactions * @returns A wallet client instance connected to Avalanche Fuji with the provided private key */ export function createSignerAvalancheFuji(privateKey) { return createWalletClient({ chain: avalancheFuji, transport: http(), account: privateKeyToAccount(privateKey), }).extend(publicActions); } /** * Creates a wallet client configured for the BSC mainnet with a private key * * @param privateKey - The private key to use for signing transactions * @returns A wallet client instance connected to BSC with the provided private key */ export function createSignerBsc(privateKey) { return createWalletClient({ chain: bsc, transport: http(), account: privateKeyToAccount(privateKey), }).extend(publicActions); } /** * Checks if a wallet is a signer wallet * * @param wallet - The wallet to check * @returns True if the wallet is a signer wallet, false otherwise */ export function isSignerWallet(wallet) { return "chain" in wallet && "transport" in wallet; } /** * Checks if a wallet is an account * * @param wallet - The wallet to check * @returns True if the wallet is an account, false otherwise */ export function isAccount(wallet) { return "address" in wallet && "type" in wallet; } //# sourceMappingURL=wallet.js.map