import type { PublicClient } from 'viem'; import type { ContractCall, MulticallFailure, MulticallResult, MulticallSuccess } from './types.js'; /** * Executes multiple contract read calls in a single RPC request using multicall3. * * This utility batches multiple contract read operations into a single network request, * significantly improving performance and reducing RPC costs when fetching data from * multiple contracts or making multiple calls to the same contract. * * @example * ```typescript * import { multicall } from '@base-org/account'; * import { createPublicClient, http } from 'viem'; * import { base } from 'viem/chains'; * * const client = createPublicClient({ * chain: base, * transport: http(), * }); * * const results = await multicall(client, { * contracts: [ * { * address: '0x...', * abi: myAbi, * functionName: 'balanceOf', * args: ['0x...'], * }, * { * address: '0x...', * abi: myAbi, * functionName: 'totalSupply', * }, * ], * }); * * if (results[0].status === 'success') { * console.log('Balance:', results[0].result); * } * ``` * * @param client - Viem public client configured for the target chain * @param config - Configuration object containing contracts array and options * @param config.contracts - Array of contract calls to execute * @param config.allowPartialFailure - If true, returns failures in results; if false, throws on any failure * @param config.errorMessages - Custom error messages for each call * @returns Promise resolving to array of results, one for each contract call * @throws Error if allowPartialFailure is false and any call fails * * @public */ export declare function multicall(client: PublicClient, config: { contracts: readonly ContractCall[]; allowPartialFailure?: boolean; errorMessages?: string[]; }): Promise; /** * Unwraps multicall results, throwing an error if any call failed. * Use this helper when you want to ensure all calls succeeded and extract * the result values in a type-safe way. * * @example * ```typescript * const results = await multicall(client, { contracts: [...] }); * const [balance, supply] = unwrapMulticallResults(results, [ * 'Failed to fetch balance', * 'Failed to fetch supply', * ]); * ``` * * @param results - Array of multicall results * @param errorMessages - Custom error messages for each result * @returns Array of unwrapped result values * @throws Error if any result has status 'failure' * * @public */ export declare function unwrapMulticallResults(results: MulticallResult[], errorMessages?: string[]): T[]; /** * Type guard to check if a multicall result is successful * * @example * ```typescript * const results = await multicall(client, { contracts: [...], allowPartialFailure: true }); * const successfulResults = results.filter(isMulticallSuccess); * ``` * * @param result - Multicall result to check * @returns True if result is successful * * @public */ export declare function isMulticallSuccess(result: MulticallResult): result is MulticallSuccess; /** * Type guard to check if a multicall result is a failure * * @example * ```typescript * const results = await multicall(client, { contracts: [...], allowPartialFailure: true }); * const failures = results.filter(isMulticallFailure); * failures.forEach(f => console.error(f.error)); * ``` * * @param result - Multicall result to check * @returns True if result is a failure * * @public */ export declare function isMulticallFailure(result: MulticallResult): result is MulticallFailure; export type { ContractCall, MulticallFailure, MulticallOptions, MulticallResult, MulticallSuccess, } from './types.js'; //# sourceMappingURL=index.d.ts.map