import type { Abi, AbiEvent, AbiFunction, AbiParametersToPrimitiveTypes, Address, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiFunction, ExtractAbiFunctionNames } from 'abitype'; import type { Account } from '../accounts/types.js'; import type { Client } from '../clients/createClient.js'; import type { Transport } from '../clients/transports/createTransport.js'; import type { Chain } from '../types/chain.js'; import type { AbiEventParametersToPrimitiveTypes, ContractEventName, ContractFunctionArgs, ContractFunctionName, MaybeExtractEventArgsFromAbi } from '../types/contract.js'; import type { IsNarrowable, IsNever, IsUndefined, Or, Prettify, UnionOmit } from '../types/utils.js'; import type { ErrorType } from '../errors/utils.js'; import { type CreateContractEventFilterParameters, type CreateContractEventFilterReturnType } from './public/createContractEventFilter.js'; import { type EstimateContractGasParameters, type EstimateContractGasReturnType } from './public/estimateContractGas.js'; import { type GetContractEventsParameters, type GetContractEventsReturnType } from './public/getContractEvents.js'; import { type ReadContractParameters, type ReadContractReturnType } from './public/readContract.js'; import { type SimulateContractParameters, type SimulateContractReturnType } from './public/simulateContract.js'; import { type WatchContractEventParameters, type WatchContractEventReturnType } from './public/watchContractEvent.js'; import { type WriteContractParameters, type WriteContractReturnType } from './wallet/writeContract.js'; type KeyedClient = { public?: Client | undefined; wallet: Client; } | { public: Client; wallet?: Client | undefined; }; export type GetContractParameters | KeyedClient = Client | KeyedClient, address extends Address = Address> = { /** Contract ABI */ abi: abi; /** Contract address */ address: address; /** The Client. * * If you pass in a [`publicClient`](https://viem.sh/docs/clients/public), the following methods are available: * * - [`createEventFilter`](https://viem.sh/docs/contract/createContractEventFilter) * - [`estimateGas`](https://viem.sh/docs/contract/estimateContractGas) * - [`getEvents`](https://viem.sh/docs/contract/getContractEvents) * - [`read`](https://viem.sh/docs/contract/readContract) * - [`simulate`](https://viem.sh/docs/contract/simulateContract) * - [`watchEvent`](https://viem.sh/docs/contract/watchContractEvent) * * If you pass in a [`walletClient`](https://viem.sh/docs/clients/wallet), the following methods are available: * * - [`estimateGas`](https://viem.sh/docs/contract/estimateContractGas) * - [`write`](https://viem.sh/docs/contract/writeContract) */ client: client; }; export type GetContractReturnType : string, _readFunctionNames extends string = abi extends Abi ? Abi extends abi ? string : ExtractAbiFunctionNames : string, _writeFunctionNames extends string = abi extends Abi ? Abi extends abi ? string : ExtractAbiFunctionNames : string, _narrowable extends boolean = IsNarrowable, _publicClient extends Client | unknown = client extends { public: Client; } ? client['public'] : client, _walletClient extends Client | unknown = client extends { wallet: Client; } ? client['wallet'] : client> = Prettify extends true ? unknown : { /** * Calls a read-only function on a contract, and returns the response. * * A "read-only" function (constant function) on a Solidity contract is denoted by a `view` or `pure` keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas. * * Internally, `read` uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData). * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi([ * 'function balanceOf(address owner) view returns (uint256)', * ]), * client: publicClient, * }) * const result = await contract.read.balanceOf(['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e']) * // 424122n */ read: { [functionName in _readFunctionNames]: GetReadFunction<_narrowable, abi, functionName extends ContractFunctionName ? functionName : never>; }; }) & (IsNever<_writeFunctionNames> extends true ? unknown : { /** * Estimates the gas necessary to complete a transaction without submitting it to the network. * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint() public']), * client: publicClient, * }) * const gas = await contract.estimateGas.mint({ * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', * }) */ estimateGas: { [functionName in _writeFunctionNames]: GetEstimateFunction<_narrowable, _publicClient['chain'], undefined, abi, functionName extends ContractFunctionName ? functionName : never>; }; /** * Simulates/validates a contract interaction. This is useful for retrieving return data and revert reasons of contract write functions. * * This function does not require gas to execute and does not change the state of the blockchain. It is almost identical to [`readContract`](https://viem.sh/docs/contract/readContract), but also supports contract write functions. * * Internally, `simulate` uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData). * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint() public']), * client: publicClient, * }) * const result = await contract.simulate.mint({ * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', * }) */ simulate: { [functionName in _writeFunctionNames]: GetSimulateFunction<_narrowable, _publicClient['chain'], _walletClient extends Client ? _walletClient['account'] : _publicClient['account'], abi, functionName extends ContractFunctionName ? functionName : never>; }; }) & (IsNever<_eventNames> extends true ? unknown : { /** * Creates a Filter to retrieve event logs that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges) or [`getFilterLogs`](https://viem.sh/docs/actions/public/getFilterLogs). * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), * client: publicClient, * }) * const filter = await contract.createEventFilter.Transfer() */ createEventFilter: { [EventName in _eventNames]: GetEventFilter<_narrowable, abi, EventName extends ContractEventName ? EventName : never>; }; /** * Creates a Filter to retrieve event logs that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges) or [`getFilterLogs`](https://viem.sh/docs/actions/public/getFilterLogs). * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), * client: publicClient, * }) * const filter = await contract.createEventFilter.Transfer() */ getEvents: { [EventName in _eventNames]: GetEventsFunction<_narrowable, abi, EventName extends ContractEventName ? EventName : never>; }; /** * Watches and returns emitted contract event logs. * * This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs). * * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), * client: publicClient, * }) * const filter = await contract.createEventFilter.Transfer() * const unwatch = contract.watchEvent.Transfer( * { from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b' }, * { onLogs: (logs) => console.log(logs) }, * ) */ watchEvent: { [EventName in _eventNames]: GetWatchEvent<_narrowable, abi, EventName extends ContractEventName ? EventName : never>; }; }) : unknown) & (_walletClient extends Client ? IsNever<_writeFunctionNames> extends true ? unknown : { /** * Estimates the gas necessary to complete a transaction without submitting it to the network. * * @example * import { createWalletClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const walletClient = createWalletClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint() public']), * client: walletClient, * }) * const gas = await contract.estimateGas.mint({ * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', * }) */ estimateGas: { [functionName in _writeFunctionNames]: GetEstimateFunction<_narrowable, _walletClient['chain'], _walletClient['account'], abi, functionName extends ContractFunctionName ? functionName : never>; }; /** * Executes a write function on a contract. * * A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms) is needed to be broadcast in order to change the state. * * Internally, `write` uses a [Wallet Client](https://viem.sh/docs/clients/wallet) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData). * * __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract#usage) before you execute it.__ * * @example * import { createWalletClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const walletClient = createWalletClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint(uint32 tokenId) nonpayable']), * client: walletClient, * }) * const hash = await contract.write.min([69420], { * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * }) */ write: { [functionName in _writeFunctionNames]: GetWriteFunction<_narrowable, _walletClient['chain'], _walletClient['account'], abi, functionName extends ContractFunctionName ? functionName : never>; }; } : unknown)> & { address: address; abi: abi; }>; export type GetContractErrorType = ErrorType; /** * Gets type-safe interface for performing contract-related actions with a specific `abi` and `address`. * * - Docs https://viem.sh/docs/contract/getContract * * Using Contract Instances can make it easier to work with contracts if you don't want to pass the `abi` and `address` properties every time you perform contract actions, e.g. [`readContract`](https://viem.sh/docs/contract/readContract), [`writeContract`](https://viem.sh/docs/contract/writeContract), [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas), etc. * * @example * import { createPublicClient, getContract, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const publicClient = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const contract = getContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi([ * 'function balanceOf(address owner) view returns (uint256)', * 'function ownerOf(uint256 tokenId) view returns (address)', * 'function totalSupply() view returns (uint256)', * ]), * client: publicClient, * }) */ export declare function getContract | KeyedClient, chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined>({ abi, address, client: client_, }: GetContractParameters): GetContractReturnType; /** * @internal exporting for testing only */ export declare function getFunctionParameters(values: [args?: readonly unknown[] | undefined, options?: object | undefined]): { args: readonly unknown[]; options: object; }; /** * @internal exporting for testing only */ export declare function getEventParameters(values: [args?: object | unknown[], options?: object], abiEvent: AbiEvent): { args: object | undefined; options: object; }; type GetReadFunction, args extends ContractFunctionArgs = ContractFunctionArgs, abiFunction extends AbiFunction = abi extends Abi ? ExtractAbiFunction : AbiFunction, _args = AbiParametersToPrimitiveTypes, _options = Prettify, 'abi' | 'address' | 'args' | 'functionName'>>> = narrowable extends true ? (...parameters: _args extends readonly [] ? [options?: _options] : [args: _args, options?: _options]) => Promise> : (...parameters: [options?: _options] | [args: readonly unknown[], options?: _options]) => Promise; type GetEstimateFunction, args extends ContractFunctionArgs = ContractFunctionArgs, abiFunction extends AbiFunction = abi extends Abi ? ExtractAbiFunction : AbiFunction, _args = AbiParametersToPrimitiveTypes, _options = Prettify, 'abi' | 'address' | 'args' | 'functionName'>>, IsOptionsRequired = IsUndefined> = narrowable extends true ? (...parameters: _args extends readonly [] ? IsOptionsRequired extends true ? [options: _options] : [options?: _options] : [ args: _args, ...parameters: IsOptionsRequired extends true ? [options: _options] : [options?: _options] ]) => Promise : (...parameters: (IsOptionsRequired extends true ? [options: _options] : [options?: _options]) | [ args: readonly unknown[], ...parameters: IsOptionsRequired extends true ? [options: _options] : [options?: _options] ]) => Promise; type GetSimulateFunction, args extends ContractFunctionArgs = ContractFunctionArgs, abiFunction extends AbiFunction = abi extends Abi ? ExtractAbiFunction : AbiFunction, _args = AbiParametersToPrimitiveTypes> = narrowable extends true ? (...parameters: _args extends readonly [] ? [ options?: Omit, 'abi' | 'address' | 'args' | 'functionName'> ] : [ args: _args, options?: Omit, 'abi' | 'address' | 'args' | 'functionName'> ]) => Promise> : (...parameters: [ options?: Omit, 'abi' | 'address' | 'args' | 'functionName'> ] | [ args: readonly unknown[], options?: Omit, 'abi' | 'address' | 'args' | 'functionName'> ]) => Promise; type GetWriteFunction, args extends ContractFunctionArgs = ContractFunctionArgs, abiFunction extends AbiFunction = abi extends Abi ? ExtractAbiFunction : AbiFunction, _args = AbiParametersToPrimitiveTypes, _isOptionsRequired = Or<[IsUndefined, IsUndefined]>> = narrowable extends true ? , 'abi' | 'address' | 'args' | 'functionName'>>>(...parameters: _args extends readonly [] ? _isOptionsRequired extends true ? [options: options] : [options?: options] : [ args: _args, ...parameters: _isOptionsRequired extends true ? [options: options] : [options?: options] ]) => Promise : , 'abi' | 'address' | 'args' | 'functionName'>>, Rest extends unknown[] = _isOptionsRequired extends true ? [options: options] : [options?: options]>(...parameters: Rest | [args: readonly unknown[], ...parameters: Rest]) => Promise; type GetEventFilter, abiEvent extends AbiEvent = abi extends Abi ? ExtractAbiEvent : AbiEvent, _args = AbiEventParametersToPrimitiveTypes, _options = Prettify, 'abi' | 'address' | 'args' | 'eventName' | 'strict'>>, IndexedInputs = Extract> = narrowable extends true ? | undefined, strict extends boolean | undefined = undefined>(...parameters: IsNever extends true ? [options?: _options & { strict?: strict; }] : [ args: _args | (_args extends args ? Readonly : never), options?: _options & { strict?: strict; } ]) => Promise> : (...parameters: [options?: _options & { strict?: strict; }] | [ args: readonly unknown[] | CreateContractFilterOptions, options?: _options & { strict?: strict; } ]) => Promise; type GetEventsFunction, abiEvent extends AbiEvent = abi extends Abi ? ExtractAbiEvent : AbiEvent, _args = AbiEventParametersToPrimitiveTypes, _options = Prettify, 'abi' | 'address' | 'args' | 'eventName'>>, IndexedInputs = Extract> = narrowable extends true ? (...parameters: IsNever extends true ? [options?: _options] : [args?: _args, options?: _options]) => Promise> : (...parameters: [options?: _options] | [ args?: readonly unknown[] | WatchContractEventOptions, options?: _options ]) => Promise>; type GetWatchEvent, abiEvent extends AbiEvent = abi extends Abi ? ExtractAbiEvent : AbiEvent, _args = AbiEventParametersToPrimitiveTypes, _options = Prettify, 'abi' | 'address' | 'args' | 'eventName'>>, _indexedInputs = Extract> = narrowable extends true ? (...parameters: IsNever<_indexedInputs> extends true ? [options: _options] : [args: _args, options: _options]) => WatchContractEventReturnType : (...parameters: [options?: _options] | [ args: readonly unknown[] | WatchContractEventOptions, options?: _options ]) => WatchContractEventReturnType; type CreateContractFilterOptions = RemoveProperties; type WatchContractEventOptions = RemoveProperties; type RemoveProperties = Prettify<{ [key: string]: unknown; } & { [_ in keyof T]?: never; }>; export {}; //# sourceMappingURL=getContract.d.ts.map