@phala/cloud
Version:
TypeScript SDK for Phala Cloud API
101 lines • 3.6 kB
TypeScript
import { type Address, type Hash, type PublicClient, type WalletClient, type TransactionReceipt } from "viem";
export interface NetworkClients {
publicClient: PublicClient;
walletClient: WalletClient;
address: Address;
chainId: number;
}
export interface NetworkConfig {
chainId: number;
name: string;
rpcUrl: string;
blockExplorer?: string;
}
export interface WalletConnection {
address: Address;
chainId: number;
}
export interface BalanceCheckResult {
address: Address;
balance: bigint;
sufficient: boolean;
required?: bigint;
}
export interface TransactionOptions {
timeout?: number;
confirmations?: number;
onSubmitted?: (hash: Hash) => void;
onConfirmed?: (receipt: TransactionReceipt) => void;
onError?: (error: Error, hash?: Hash) => void;
}
export interface TransactionResult {
hash: Hash;
receipt: TransactionReceipt;
success: boolean;
}
export declare class NetworkError extends Error {
code?: string | undefined;
details?: unknown | undefined;
constructor(message: string, code?: string | undefined, details?: unknown | undefined);
}
export declare class WalletError extends Error {
code?: string | undefined;
details?: unknown | undefined;
constructor(message: string, code?: string | undefined, details?: unknown | undefined);
}
export declare class TransactionError extends Error {
hash?: Hash | undefined;
details?: unknown | undefined;
constructor(message: string, hash?: Hash | undefined, details?: unknown | undefined);
}
/**
* Create a NetworkClients object from existing viem clients
* This is the primary way to create NetworkClients - the caller provides pre-configured clients
*/
export declare function createNetworkClients(publicClient: PublicClient, walletClient: WalletClient, address: Address, chainId: number): NetworkClients;
/**
* Check wallet connection and network status
*/
export declare function checkNetworkStatus(clients: NetworkClients, targetChainId: number): Promise<{
isCorrectNetwork: boolean;
currentChainId: number;
}>;
/**
* Check wallet balance
*/
export declare function checkBalance(publicClient: PublicClient, address: Address, minBalance?: bigint): Promise<BalanceCheckResult>;
/**
* Wait for transaction receipt with timeout and polling
*/
export declare function waitForTransactionReceipt(publicClient: PublicClient, hash: Hash, options?: {
timeout?: number;
pollingInterval?: number;
confirmations?: number;
}): Promise<TransactionReceipt>;
/**
* Execute a transaction with automatic receipt waiting and error handling
*/
export declare function executeTransaction<T extends unknown[]>(clients: NetworkClients, operation: (clients: NetworkClients, ...args: T) => Promise<Hash>, args: T, options?: TransactionOptions): Promise<TransactionResult>;
/**
* Extract NetworkClients info from existing viem clients
* Useful when you have existing clients and want to create a NetworkClients object
*/
export declare function extractNetworkClients(publicClient: PublicClient, walletClient: WalletClient): Promise<NetworkClients>;
/**
* Comprehensive network validation
*/
export declare function validateNetworkPrerequisites(clients: NetworkClients, requirements: {
targetChainId: number;
minBalance?: bigint;
requiredAddress?: Address;
}): Promise<{
networkValid: boolean;
balanceValid: boolean;
addressValid: boolean;
details: {
currentChainId: number;
balance: bigint;
address: Address;
};
}>;
//# sourceMappingURL=network.d.ts.map