UNPKG

viem

Version:

TypeScript Interface for Ethereum

1,380 lines (1,378 loc) • 77.6 kB
import type { Abi, AbiEvent, Address } from 'abitype' import { type GetEnsAddressParameters, type GetEnsAddressReturnType, getEnsAddress, } from '../../actions/ens/getEnsAddress.js' import { type GetEnsAvatarParameters, type GetEnsAvatarReturnType, getEnsAvatar, } from '../../actions/ens/getEnsAvatar.js' import { type GetEnsNameParameters, type GetEnsNameReturnType, getEnsName, } from '../../actions/ens/getEnsName.js' import { type GetEnsResolverParameters, type GetEnsResolverReturnType, getEnsResolver, } from '../../actions/ens/getEnsResolver.js' import { type GetEnsTextParameters, type GetEnsTextReturnType, getEnsText, } from '../../actions/ens/getEnsText.js' import { type CallParameters, type CallReturnType, call, } from '../../actions/public/call.js' import { type CreateAccessListParameters, type CreateAccessListReturnType, createAccessList, } from '../../actions/public/createAccessList.js' import { type CreateBlockFilterReturnType, createBlockFilter, } from '../../actions/public/createBlockFilter.js' import { type CreateContractEventFilterParameters, type CreateContractEventFilterReturnType, createContractEventFilter, } from '../../actions/public/createContractEventFilter.js' import { type CreateEventFilterParameters, type CreateEventFilterReturnType, createEventFilter, } from '../../actions/public/createEventFilter.js' import { type CreatePendingTransactionFilterReturnType, createPendingTransactionFilter, } from '../../actions/public/createPendingTransactionFilter.js' import { type EstimateContractGasParameters, type EstimateContractGasReturnType, estimateContractGas, } from '../../actions/public/estimateContractGas.js' import { type EstimateFeesPerGasParameters, type EstimateFeesPerGasReturnType, estimateFeesPerGas, } from '../../actions/public/estimateFeesPerGas.js' import { type EstimateGasParameters, type EstimateGasReturnType, estimateGas, } from '../../actions/public/estimateGas.js' import { type EstimateMaxPriorityFeePerGasParameters, type EstimateMaxPriorityFeePerGasReturnType, estimateMaxPriorityFeePerGas, } from '../../actions/public/estimateMaxPriorityFeePerGas.js' import { type GetBalanceParameters, type GetBalanceReturnType, getBalance, } from '../../actions/public/getBalance.js' import { type GetBlobBaseFeeReturnType, getBlobBaseFee, } from '../../actions/public/getBlobBaseFee.js' import { type GetBlockParameters, type GetBlockReturnType, getBlock, } from '../../actions/public/getBlock.js' import { type GetBlockNumberParameters, type GetBlockNumberReturnType, getBlockNumber, } from '../../actions/public/getBlockNumber.js' import { type GetBlockTransactionCountParameters, type GetBlockTransactionCountReturnType, getBlockTransactionCount, } from '../../actions/public/getBlockTransactionCount.js' import { type GetChainIdReturnType, getChainId, } from '../../actions/public/getChainId.js' import { type GetCodeParameters, type GetCodeReturnType, getCode, } from '../../actions/public/getCode.js' import { type GetContractEventsParameters, type GetContractEventsReturnType, getContractEvents, } from '../../actions/public/getContractEvents.js' import { type GetEip712DomainParameters, type GetEip712DomainReturnType, getEip712Domain, } from '../../actions/public/getEip712Domain.js' import { type GetFeeHistoryParameters, type GetFeeHistoryReturnType, getFeeHistory, } from '../../actions/public/getFeeHistory.js' import { type GetFilterChangesParameters, type GetFilterChangesReturnType, getFilterChanges, } from '../../actions/public/getFilterChanges.js' import { type GetFilterLogsParameters, type GetFilterLogsReturnType, getFilterLogs, } from '../../actions/public/getFilterLogs.js' import { type GetGasPriceReturnType, getGasPrice, } from '../../actions/public/getGasPrice.js' import { type GetLogsParameters, type GetLogsReturnType, getLogs, } from '../../actions/public/getLogs.js' import { type GetProofParameters, type GetProofReturnType, getProof, } from '../../actions/public/getProof.js' import { type GetStorageAtParameters, type GetStorageAtReturnType, getStorageAt, } from '../../actions/public/getStorageAt.js' import { type GetTransactionParameters, type GetTransactionReturnType, getTransaction, } from '../../actions/public/getTransaction.js' import { type GetTransactionConfirmationsParameters, type GetTransactionConfirmationsReturnType, getTransactionConfirmations, } from '../../actions/public/getTransactionConfirmations.js' import { type GetTransactionCountParameters, type GetTransactionCountReturnType, getTransactionCount, } from '../../actions/public/getTransactionCount.js' import { type GetTransactionReceiptParameters, type GetTransactionReceiptReturnType, getTransactionReceipt, } from '../../actions/public/getTransactionReceipt.js' import { type MulticallParameters, type MulticallReturnType, multicall, } from '../../actions/public/multicall.js' import { type ReadContractParameters, type ReadContractReturnType, readContract, } from '../../actions/public/readContract.js' import { type SimulateBlocksParameters, type SimulateBlocksReturnType, simulateBlocks, } from '../../actions/public/simulateBlocks.js' import { type SimulateCallsParameters, type SimulateCallsReturnType, simulateCalls, } from '../../actions/public/simulateCalls.js' import { type SimulateContractParameters, type SimulateContractReturnType, simulateContract, } from '../../actions/public/simulateContract.js' import { type UninstallFilterParameters, type UninstallFilterReturnType, uninstallFilter, } from '../../actions/public/uninstallFilter.js' import { type VerifyMessageParameters, type VerifyMessageReturnType, verifyMessage, } from '../../actions/public/verifyMessage.js' import { type VerifyTypedDataParameters, type VerifyTypedDataReturnType, verifyTypedData, } from '../../actions/public/verifyTypedData.js' import { type WaitForTransactionReceiptParameters, type WaitForTransactionReceiptReturnType, waitForTransactionReceipt, } from '../../actions/public/waitForTransactionReceipt.js' import { type WatchBlockNumberParameters, type WatchBlockNumberReturnType, watchBlockNumber, } from '../../actions/public/watchBlockNumber.js' import { type WatchBlocksParameters, type WatchBlocksReturnType, watchBlocks, } from '../../actions/public/watchBlocks.js' import { type WatchContractEventParameters, type WatchContractEventReturnType, watchContractEvent, } from '../../actions/public/watchContractEvent.js' import { type WatchEventParameters, type WatchEventReturnType, watchEvent, } from '../../actions/public/watchEvent.js' import { type WatchPendingTransactionsParameters, type WatchPendingTransactionsReturnType, watchPendingTransactions, } from '../../actions/public/watchPendingTransactions.js' import { type VerifySiweMessageParameters, type VerifySiweMessageReturnType, verifySiweMessage, } from '../../actions/siwe/verifySiweMessage.js' import { type PrepareTransactionRequestParameters, type PrepareTransactionRequestRequest, type PrepareTransactionRequestReturnType, prepareTransactionRequest, } from '../../actions/wallet/prepareTransactionRequest.js' import { type SendRawTransactionParameters, type SendRawTransactionReturnType, sendRawTransaction, } from '../../actions/wallet/sendRawTransaction.js' import type { Account } from '../../types/account.js' import type { BlockNumber, BlockTag } from '../../types/block.js' import type { Chain } from '../../types/chain.js' import type { ContractEventName, ContractFunctionArgs, ContractFunctionName, MaybeAbiEventName, MaybeExtractEventArgsFromAbi, } from '../../types/contract.js' import type { FeeValuesType } from '../../types/fee.js' import type { FilterType } from '../../types/filter.js' import type { Client } from '../createClient.js' import type { Transport } from '../transports/createTransport.js' export type PublicActions< transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined, > = { /** * Executes a new message call immediately without submitting a transaction to the network. * * - Docs: https://viem.sh/docs/actions/public/call * - JSON-RPC Methods: [`eth_call`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call) * * @param args - {@link CallParameters} * @returns The call data. {@link CallReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const data = await client.call({ * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', * data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * }) */ call: (parameters: CallParameters<chain>) => Promise<CallReturnType> /** * Creates an EIP-2930 access list that you can include in a transaction. * * - Docs: https://viem.sh/docs/actions/public/createAccessList * - JSON-RPC Methods: `eth_createAccessList` * * @param args - {@link CreateAccessListParameters} * @returns The call data. {@link CreateAccessListReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * * const data = await client.createAccessList({ * data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * }) */ createAccessList: ( parameters: CreateAccessListParameters<chain>, ) => Promise<CreateAccessListReturnType> /** * Creates a Filter to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges). * * - Docs: https://viem.sh/docs/actions/public/createBlockFilter * - JSON-RPC Methods: [`eth_newBlockFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newBlockFilter) * * @returns Filter. {@link CreateBlockFilterReturnType} * * @example * import { createPublicClient, createBlockFilter, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await createBlockFilter(client) * // { id: "0x345a6572337856574a76364e457a4366", type: 'block' } */ createBlockFilter: () => Promise<CreateBlockFilterReturnType> /** * 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). * * - Docs: https://viem.sh/docs/contract/createContractEventFilter * * @param args - {@link CreateContractEventFilterParameters} * @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateContractEventFilterReturnType} * * @example * import { createPublicClient, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createContractEventFilter({ * abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), * }) */ createContractEventFilter: < const abi extends Abi | readonly unknown[], eventName extends ContractEventName<abi> | undefined, args extends MaybeExtractEventArgsFromAbi<abi, eventName> | undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, >( args: CreateContractEventFilterParameters< abi, eventName, args, strict, fromBlock, toBlock >, ) => Promise< CreateContractEventFilterReturnType< abi, eventName, args, strict, fromBlock, toBlock > > /** * Creates a [`Filter`](https://viem.sh/docs/glossary/types#filter) to listen for new events that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges). * * - Docs: https://viem.sh/docs/actions/public/createEventFilter * - JSON-RPC Methods: [`eth_newFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter) * * @param args - {@link CreateEventFilterParameters} * @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateEventFilterReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createEventFilter({ * address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2', * }) */ createEventFilter: < const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends | readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, _EventName extends string | undefined = MaybeAbiEventName<abiEvent>, _Args extends | MaybeExtractEventArgsFromAbi<abiEvents, _EventName> | undefined = undefined, >( args?: | CreateEventFilterParameters< abiEvent, abiEvents, strict, fromBlock, toBlock, _EventName, _Args > | undefined, ) => Promise< CreateEventFilterReturnType< abiEvent, abiEvents, strict, fromBlock, toBlock, _EventName, _Args > > /** * Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges). * * - Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter * - JSON-RPC Methods: [`eth_newPendingTransactionFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newpendingtransactionfilter) * * @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateBlockFilterReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createPendingTransactionFilter() * // { id: "0x345a6572337856574a76364e457a4366", type: 'transaction' } */ createPendingTransactionFilter: () => Promise<CreatePendingTransactionFilterReturnType> /** * Estimates the gas required to successfully execute a contract write function call. * * - Docs: https://viem.sh/docs/contract/estimateContractGas * * @remarks * Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`estimateGas` action](https://viem.sh/docs/actions/public/estimateGas) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData). * * @param args - {@link EstimateContractGasParameters} * @returns The gas estimate (in wei). {@link EstimateContractGasReturnType} * * @example * import { createPublicClient, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const gas = await client.estimateContractGas({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint() public']), * functionName: 'mint', * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', * }) */ estimateContractGas: < chain extends Chain | undefined, const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>, args extends ContractFunctionArgs< abi, 'nonpayable' | 'payable', functionName >, >( args: EstimateContractGasParameters<abi, functionName, args, chain>, ) => Promise<EstimateContractGasReturnType> /** * Estimates the gas necessary to complete a transaction without submitting it to the network. * * - Docs: https://viem.sh/docs/actions/public/estimateGas * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas) * * @param args - {@link EstimateGasParameters} * @returns The gas estimate (in wei). {@link EstimateGasReturnType} * * @example * import { createPublicClient, http, parseEther } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const gasEstimate = await client.estimateGas({ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: parseEther('1'), * }) */ estimateGas: ( args: EstimateGasParameters<chain>, ) => Promise<EstimateGasReturnType> /** * Returns the balance of an address in wei. * * - Docs: https://viem.sh/docs/actions/public/getBalance * - JSON-RPC Methods: [`eth_getBalance`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getbalance) * * @remarks * You can convert the balance to ether units with [`formatEther`](https://viem.sh/docs/utilities/formatEther). * * ```ts * const balance = await getBalance(client, { * address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * blockTag: 'safe' * }) * const balanceAsEther = formatEther(balance) * // "6.942" * ``` * * @param args - {@link GetBalanceParameters} * @returns The balance of the address in wei. {@link GetBalanceReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const balance = await client.getBalance({ * address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * }) * // 10000000000000000000000n (wei) */ getBalance: (args: GetBalanceParameters) => Promise<GetBalanceReturnType> /** * Returns the base fee per blob gas in wei. * * - Docs: https://viem.sh/docs/actions/public/getBlobBaseFee * - JSON-RPC Methods: [`eth_blobBaseFee`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blobBaseFee) * * @param client - Client to use * @returns The blob base fee (in wei). {@link GetBlobBaseFeeReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { getBlobBaseFee } from 'viem/public' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const blobBaseFee = await client.getBlobBaseFee() */ getBlobBaseFee: () => Promise<GetBlobBaseFeeReturnType> /** * Returns information about a block at a block number, hash, or tag. * * - Docs: https://viem.sh/docs/actions/public/getBlock * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_fetching-blocks * - JSON-RPC Methods: * - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) for `blockNumber` & `blockTag`. * - Calls [`eth_getBlockByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash) for `blockHash`. * * @param args - {@link GetBlockParameters} * @returns Information about the block. {@link GetBlockReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const block = await client.getBlock() */ getBlock: < includeTransactions extends boolean = false, blockTag extends BlockTag = 'latest', >( args?: GetBlockParameters<includeTransactions, blockTag> | undefined, ) => Promise<GetBlockReturnType<chain, includeTransactions, blockTag>> /** * Returns the number of the most recent block seen. * * - Docs: https://viem.sh/docs/actions/public/getBlockNumber * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_fetching-blocks * - JSON-RPC Methods: [`eth_blockNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blocknumber) * * @param args - {@link GetBlockNumberParameters} * @returns The number of the block. {@link GetBlockNumberReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const blockNumber = await client.getBlockNumber() * // 69420n */ getBlockNumber: ( args?: GetBlockNumberParameters | undefined, ) => Promise<GetBlockNumberReturnType> /** * Returns the number of Transactions at a block number, hash, or tag. * * - Docs: https://viem.sh/docs/actions/public/getBlockTransactionCount * - JSON-RPC Methods: * - Calls [`eth_getBlockTransactionCountByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblocktransactioncountbynumber) for `blockNumber` & `blockTag`. * - Calls [`eth_getBlockTransactionCountByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblocktransactioncountbyhash) for `blockHash`. * * @param args - {@link GetBlockTransactionCountParameters} * @returns The block transaction count. {@link GetBlockTransactionCountReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const count = await client.getBlockTransactionCount() */ getBlockTransactionCount: ( args?: GetBlockTransactionCountParameters | undefined, ) => Promise<GetBlockTransactionCountReturnType> /** @deprecated Use `getCode` instead. */ getBytecode: (args: GetCodeParameters) => Promise<GetCodeReturnType> /** * Returns the chain ID associated with the current network. * * - Docs: https://viem.sh/docs/actions/public/getChainId * - JSON-RPC Methods: [`eth_chainId`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid) * * @returns The current chain ID. {@link GetChainIdReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const chainId = await client.getChainId() * // 1 */ getChainId: () => Promise<GetChainIdReturnType> /** * Retrieves the bytecode at an address. * * - Docs: https://viem.sh/docs/contract/getCode * - JSON-RPC Methods: [`eth_getCode`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getcode) * * @param args - {@link GetBytecodeParameters} * @returns The contract's bytecode. {@link GetBytecodeReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const code = await client.getCode({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * }) */ getCode: (args: GetCodeParameters) => Promise<GetCodeReturnType> /** * Returns a list of event logs emitted by a contract. * * - Docs: https://viem.sh/docs/actions/public/getContractEvents * - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs) * * @param client - Client to use * @param parameters - {@link GetContractEventsParameters} * @returns A list of event logs. {@link GetContractEventsReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { wagmiAbi } from './abi' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const logs = await client.getContractEvents(client, { * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: wagmiAbi, * eventName: 'Transfer' * }) */ getContractEvents: < const abi extends Abi | readonly unknown[], eventName extends ContractEventName<abi> | undefined = undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, >( args: GetContractEventsParameters< abi, eventName, strict, fromBlock, toBlock >, ) => Promise< GetContractEventsReturnType<abi, eventName, strict, fromBlock, toBlock> > /** * Reads the EIP-712 domain from a contract, based on the ERC-5267 specification. * * @param client - A {@link Client} instance. * @param parameters - The parameters of the action. {@link GetEip712DomainParameters} * @returns The EIP-712 domain, fields, and extensions. {@link GetEip712DomainReturnType} * * @example * ```ts * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * * const domain = await client.getEip712Domain({ * address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', * }) * // { * // domain: { * // name: 'ExampleContract', * // version: '1', * // chainId: 1, * // verifyingContract: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', * // }, * // fields: '0x0f', * // extensions: [], * // } * ``` */ getEip712Domain: ( args: GetEip712DomainParameters, ) => Promise<GetEip712DomainReturnType> /** * Gets address for ENS name. * * - Docs: https://viem.sh/docs/ens/actions/getEnsAddress * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens * * @remarks * Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract. * * Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this. * * @param args - {@link GetEnsAddressParameters} * @returns Address for ENS name or `null` if not found. {@link GetEnsAddressReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { normalize } from 'viem/ens' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const ensAddress = await client.getEnsAddress({ * name: normalize('wevm.eth'), * }) * // '0xd2135CfB216b74109775236E36d4b433F1DF507B' */ getEnsAddress: ( args: GetEnsAddressParameters, ) => Promise<GetEnsAddressReturnType> /** * Gets the avatar of an ENS name. * * - Docs: https://viem.sh/docs/ens/actions/getEnsAvatar * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens * * @remarks * Calls [`getEnsText`](https://viem.sh/docs/ens/actions/getEnsText) with `key` set to `'avatar'`. * * Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this. * * @param args - {@link GetEnsAvatarParameters} * @returns Avatar URI or `null` if not found. {@link GetEnsAvatarReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { normalize } from 'viem/ens' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const ensAvatar = await client.getEnsAvatar({ * name: normalize('wevm.eth'), * }) * // 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio' */ getEnsAvatar: ( args: GetEnsAvatarParameters, ) => Promise<GetEnsAvatarReturnType> /** * Gets primary name for specified address. * * - Docs: https://viem.sh/docs/ens/actions/getEnsName * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens * * @remarks * Calls `reverse(bytes)` on ENS Universal Resolver Contract to "reverse resolve" the address to the primary ENS name. * * @param args - {@link GetEnsNameParameters} * @returns Name or `null` if not found. {@link GetEnsNameReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const ensName = await client.getEnsName({ * address: '0xd2135CfB216b74109775236E36d4b433F1DF507B', * }) * // 'wevm.eth' */ getEnsName: (args: GetEnsNameParameters) => Promise<GetEnsNameReturnType> /** * Gets resolver for ENS name. * * - Docs: https://viem.sh/docs/ens/actions/getEnsResolver * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens * * @remarks * Calls `findResolver(bytes)` on ENS Universal Resolver Contract to retrieve the resolver of an ENS name. * * Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this. * * @param args - {@link GetEnsResolverParameters} * @returns Address for ENS resolver. {@link GetEnsResolverReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { normalize } from 'viem/ens' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const resolverAddress = await client.getEnsResolver({ * name: normalize('wevm.eth'), * }) * // '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41' */ getEnsResolver: ( args: GetEnsResolverParameters, ) => Promise<GetEnsResolverReturnType> /** * Gets a text record for specified ENS name. * * - Docs: https://viem.sh/docs/ens/actions/getEnsResolver * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens * * @remarks * Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract. * * Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this. * * @param args - {@link GetEnsTextParameters} * @returns Address for ENS resolver. {@link GetEnsTextReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { normalize } from 'viem/ens' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const twitterRecord = await client.getEnsText({ * name: normalize('wevm.eth'), * key: 'com.twitter', * }) * // 'wevm_dev' */ getEnsText: (args: GetEnsTextParameters) => Promise<GetEnsTextReturnType> /** * Returns a collection of historical gas information. * * - Docs: https://viem.sh/docs/actions/public/getFeeHistory * - JSON-RPC Methods: [`eth_feeHistory`](https://docs.alchemy.com/reference/eth-feehistory) * * @param args - {@link GetFeeHistoryParameters} * @returns The gas estimate (in wei). {@link GetFeeHistoryReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const feeHistory = await client.getFeeHistory({ * blockCount: 4, * rewardPercentiles: [25, 75], * }) */ getFeeHistory: ( args: GetFeeHistoryParameters, ) => Promise<GetFeeHistoryReturnType> /** * Returns an estimate for the fees per gas for a transaction to be included * in the next block. * * - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas * * @param client - Client to use * @param parameters - {@link EstimateFeesPerGasParameters} * @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const maxPriorityFeePerGas = await client.estimateFeesPerGas() * // { maxFeePerGas: ..., maxPriorityFeePerGas: ... } */ estimateFeesPerGas: < chainOverride extends Chain | undefined = undefined, type extends FeeValuesType = 'eip1559', >( args?: EstimateFeesPerGasParameters<chain, chainOverride, type> | undefined, ) => Promise<EstimateFeesPerGasReturnType<type>> /** * Returns a list of logs or hashes based on a [Filter](/docs/glossary/terms#filter) since the last time it was called. * * - Docs: https://viem.sh/docs/actions/public/getFilterChanges * - JSON-RPC Methods: [`eth_getFilterChanges`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterchanges) * * @remarks * A Filter can be created from the following actions: * * - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter) * - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter) * - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter) * - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter) * * Depending on the type of filter, the return value will be different: * * - If the filter was created with `createContractEventFilter` or `createEventFilter`, it returns a list of logs. * - If the filter was created with `createPendingTransactionFilter`, it returns a list of transaction hashes. * - If the filter was created with `createBlockFilter`, it returns a list of block hashes. * * @param args - {@link GetFilterChangesParameters} * @returns Logs or hashes. {@link GetFilterChangesReturnType} * * @example * // Blocks * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createBlockFilter() * const hashes = await client.getFilterChanges({ filter }) * * @example * // Contract Events * import { createPublicClient, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createContractEventFilter({ * address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', * abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), * eventName: 'Transfer', * }) * const logs = await client.getFilterChanges({ filter }) * * @example * // Raw Events * import { createPublicClient, http, parseAbiItem } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createEventFilter({ * address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', * event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'), * }) * const logs = await client.getFilterChanges({ filter }) * * @example * // Transactions * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createPendingTransactionFilter() * const hashes = await client.getFilterChanges({ filter }) */ getFilterChanges: < filterType extends FilterType, const abi extends Abi | readonly unknown[] | undefined, eventName extends string | undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, >( args: GetFilterChangesParameters< filterType, abi, eventName, strict, fromBlock, toBlock >, ) => Promise< GetFilterChangesReturnType< filterType, abi, eventName, strict, fromBlock, toBlock > > /** * Returns a list of event logs since the filter was created. * * - Docs: https://viem.sh/docs/actions/public/getFilterLogs * - JSON-RPC Methods: [`eth_getFilterLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterlogs) * * @remarks * `getFilterLogs` is only compatible with **event filters**. * * @param args - {@link GetFilterLogsParameters} * @returns A list of event logs. {@link GetFilterLogsReturnType} * * @example * import { createPublicClient, http, parseAbiItem } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const filter = await client.createEventFilter({ * address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', * event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'), * }) * const logs = await client.getFilterLogs({ filter }) */ getFilterLogs: < const abi extends Abi | readonly unknown[] | undefined, eventName extends string | undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, >( args: GetFilterLogsParameters<abi, eventName, strict, fromBlock, toBlock>, ) => Promise< GetFilterLogsReturnType<abi, eventName, strict, fromBlock, toBlock> > /** * Returns the current price of gas (in wei). * * - Docs: https://viem.sh/docs/actions/public/getGasPrice * - JSON-RPC Methods: [`eth_gasPrice`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gasprice) * * @returns The gas price (in wei). {@link GetGasPriceReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const gasPrice = await client.getGasPrice() */ getGasPrice: () => Promise<GetGasPriceReturnType> /** * Returns a list of event logs matching the provided parameters. * * - Docs: https://viem.sh/docs/actions/public/getLogs * - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/logs_event-logs * - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs) * * @param args - {@link GetLogsParameters} * @returns A list of event logs. {@link GetLogsReturnType} * * @example * import { createPublicClient, http, parseAbiItem } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const logs = await client.getLogs() */ getLogs: < const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends | readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined, fromBlock extends BlockNumber | BlockTag | undefined = undefined, toBlock extends BlockNumber | BlockTag | undefined = undefined, >( args?: | GetLogsParameters<abiEvent, abiEvents, strict, fromBlock, toBlock> | undefined, ) => Promise< GetLogsReturnType<abiEvent, abiEvents, strict, fromBlock, toBlock> > /** * Returns the account and storage values of the specified account including the Merkle-proof. * * - Docs: https://viem.sh/docs/actions/public/getProof * - JSON-RPC Methods: * - Calls [`eth_getProof`](https://eips.ethereum.org/EIPS/eip-1186) * * @param client - Client to use * @param parameters - {@link GetProofParameters} * @returns Proof data. {@link GetProofReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const block = await client.getProof({ * address: '0x...', * storageKeys: ['0x...'], * }) */ getProof: (args: GetProofParameters) => Promise<GetProofReturnType> /** * Returns an estimate for the max priority fee per gas (in wei) for a transaction * to be included in the next block. * * - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas * * @param client - Client to use * @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const maxPriorityFeePerGas = await client.estimateMaxPriorityFeePerGas() * // 10000000n */ estimateMaxPriorityFeePerGas: < chainOverride extends Chain | undefined = undefined, >( args?: | EstimateMaxPriorityFeePerGasParameters<chain, chainOverride> | undefined, ) => Promise<EstimateMaxPriorityFeePerGasReturnType> /** * Returns the value from a storage slot at a given address. * * - Docs: https://viem.sh/docs/contract/getStorageAt * - JSON-RPC Methods: [`eth_getStorageAt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getstorageat) * * @param args - {@link GetStorageAtParameters} * @returns The value of the storage slot. {@link GetStorageAtReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { getStorageAt } from 'viem/contract' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const code = await client.getStorageAt({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * slot: toHex(0), * }) */ getStorageAt: ( args: GetStorageAtParameters, ) => Promise<GetStorageAtReturnType> /** * Returns information about a [Transaction](https://viem.sh/docs/glossary/terms#transaction) given a hash or block identifier. * * - Docs: https://viem.sh/docs/actions/public/getTransaction * - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions * - JSON-RPC Methods: [`eth_getTransactionByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionByHash) * * @param args - {@link GetTransactionParameters} * @returns The transaction information. {@link GetTransactionReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const transaction = await client.getTransaction({ * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', * }) */ getTransaction: <blockTag extends BlockTag = 'latest'>( args: GetTransactionParameters<blockTag>, ) => Promise<GetTransactionReturnType<chain, blockTag>> /** * Returns the number of blocks passed (confirmations) since the transaction was processed on a block. * * - Docs: https://viem.sh/docs/actions/public/getTransactionConfirmations * - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions * - JSON-RPC Methods: [`eth_getTransactionConfirmations`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionConfirmations) * * @param args - {@link GetTransactionConfirmationsParameters} * @returns The number of blocks passed since the transaction was processed. If confirmations is 0, then the Transaction has not been confirmed & processed yet. {@link GetTransactionConfirmationsReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const confirmations = await client.getTransactionConfirmations({ * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', * }) */ getTransactionConfirmations: ( args: GetTransactionConfirmationsParameters<chain>, ) => Promise<GetTransactionConfirmationsReturnType> /** * Returns the number of [Transactions](https://viem.sh/docs/glossary/terms#transaction) an Account has broadcast / sent. * * - Docs: https://viem.sh/docs/actions/public/getTransactionCount * - JSON-RPC Methods: [`eth_getTransactionCount`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount) * * @param args - {@link GetTransactionCountParameters} * @returns The number of transactions an account has sent. {@link GetTransactionCountReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const transactionCount = await client.getTransactionCount({ * address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * }) */ getTransactionCount: ( args: GetTransactionCountParameters, ) => Promise<GetTransactionCountReturnType> /** * Returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms#transaction-receipt) given a [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. * * - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt * - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions * - JSON-RPC Methods: [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt) * * @param args - {@link GetTransactionReceiptParameters} * @returns The transaction receipt. {@link GetTransactionReceiptReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const transactionReceipt = await client.getTransactionReceipt({ * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', * }) */ getTransactionReceipt: ( args: GetTransactionReceiptParameters, ) => Promise<GetTransactionReceiptReturnType<chain>> /** * Similar to [`readContract`](https://viem.sh/docs/contract/readContract), but batches up multiple functions on a contract in a single RPC call via the [`multicall3` contract](https://github.com/mds1/multicall). * * - Docs: https://viem.sh/docs/contract/multicall * * @param args - {@link MulticallParameters} * @returns An array of results with accompanying status. {@link MulticallReturnType} * * @example * import { createPublicClient, http, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }) * const abi = parseAbi([ * 'function balanceOf(address) view re