UNPKG

viem-tracer

Version:

[![npm package][npm-img]][npm-url] [![Build Status][build-img]][build-url] [![Downloads][downloads-img]][downloads-url] [![Issues][issues-img]][issues-url] [![Commitizen Friendly][commitizen-img]][commitizen-url] [![Semantic Release][semantic-release-img]

76 lines (75 loc) 2.51 kB
import { type Account, type Address, type BlockTag, type Chain, type Client, type ExactPartial, type FormattedTransactionRequest, type Hex, type RpcTransactionRequest, type Transport, type UnionOmit } from "viem"; export type TraceCallRpcSchema = { Method: "debug_traceCall"; Parameters: [ExactPartial<RpcTransactionRequest>, Hex | BlockTag] | [ ExactPartial<RpcTransactionRequest>, BlockTag | Hex, { tracer: "callTracer" | "prestateTracer"; tracerConfig?: { onlyTopCall?: boolean; withLog?: boolean; }; } ]; ReturnType: RpcCallTrace; }; export type RpcCallType = "CALL" | "STATICCALL" | "DELEGATECALL" | "CREATE" | "CREATE2" | "SELFDESTRUCT" | "CALLCODE"; export type RpcLogTrace = { address: Address; data: Hex; position: Hex; topics: [Hex, ...Hex[]]; }; export type RpcCallTrace = { from: Address; gas: Hex; gasUsed: Hex; to: Address; input: Hex; output: Hex; error?: string; revertReason?: string; calls?: RpcCallTrace[]; logs?: RpcLogTrace[]; value?: Hex; type: RpcCallType; }; export type TraceCallParameters<chain extends Chain | undefined = Chain | undefined> = UnionOmit<FormattedTransactionRequest<chain>, "from"> & { account?: Account | Address | undefined; tracer?: "callTracer" | "prestateTracer"; tracerConfig?: { onlyTopCall?: boolean; }; } & ({ blockNumber?: bigint | undefined; blockTag?: undefined; } | { blockNumber?: undefined; blockTag?: BlockTag | undefined; }); /** * Traces a call. * * - JSON-RPC Methods: [`debug_traceCall`](https://www.quicknode.com/docs/ethereum/debug_traceCall) * * @param client - Client to use * @param parameters - {@link TraceCallParameters} * @returns The call trace. {@link RpcCallTrace} * * @example * import { createPublicClient, http, parseEther } from 'viem' * import { mainnet } from 'viem/chains' * import { traceCall } from 'viem-tracer' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const gasEstimate = await traceCall(client, { * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: parseEther('1'), * }) */ export declare function traceCall<chain extends Chain | undefined>(client: Client<Transport, chain>, { tracer, tracerConfig, ...args }: TraceCallParameters<chain>): Promise<RpcCallTrace>;