UNPKG

viem

Version:

TypeScript Interface for Ethereum

72 lines 5.26 kB
import type { Address } from 'abitype'; import type { Account } from '../../accounts/types.js'; import { type ParseAccountErrorType } from '../../accounts/utils/parseAccount.js'; import { type EstimateFeesPerGasErrorType } from '../../actions/public/estimateFeesPerGas.js'; import { type EstimateGasErrorType } from '../../actions/public/estimateGas.js'; import { type GetBlockErrorType } from '../../actions/public/getBlock.js'; import { type GetTransactionCountErrorType } from '../../actions/public/getTransactionCount.js'; import type { Client } from '../../clients/createClient.js'; import type { Transport } from '../../clients/transports/createTransport.js'; import { type AccountNotFoundErrorType } from '../../errors/account.js'; import type { DeriveAccount, GetAccountParameter } from '../../types/account.js'; import type { Chain, DeriveChain } from '../../types/chain.js'; import type { GetChainParameter } from '../../types/chain.js'; import type { UnionOmit, UnionRequiredBy } from '../../types/utils.js'; import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'; import type { AssertRequestErrorType } from '../../utils/transaction/assertRequest.js'; export type PrepareTransactionRequestParameterType = 'fees' | 'gas' | 'nonce' | 'type'; type ParameterTypeToParameters<TParameterType extends PrepareTransactionRequestParameterType> = TParameterType extends 'fees' ? 'maxFeePerGas' | 'maxPriorityFeePerGas' | 'gasPrice' : TParameterType; export type PrepareTransactionRequestParameters<TChain extends Chain | undefined = Chain | undefined, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, TAccountOverride extends Account | Address | undefined = Account | Address | undefined, TParameterType extends PrepareTransactionRequestParameterType = PrepareTransactionRequestParameterType, derivedChain extends Chain | undefined = DeriveChain<TChain, TChainOverride>> = UnionOmit<FormattedTransactionRequest<derivedChain>, 'from'> & GetAccountParameter<TAccount, TAccountOverride, false> & GetChainParameter<TChain, TChainOverride> & { parameters?: TParameterType[]; }; export type PrepareTransactionRequestReturnType<TChain extends Chain | undefined = Chain | undefined, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, TAccountOverride extends Account | Address | undefined = Account | Address | undefined, TParameterType extends PrepareTransactionRequestParameterType = PrepareTransactionRequestParameterType, derivedAccount extends Account | Address | undefined = DeriveAccount<TAccount, TAccountOverride>, derivedChain extends Chain | undefined = DeriveChain<TChain, TChainOverride>> = UnionRequiredBy<UnionOmit<FormattedTransactionRequest<derivedChain>, 'from'>, ParameterTypeToParameters<TParameterType>> & GetChainParameter<TChain, TChainOverride> & (derivedAccount extends Account ? { account: derivedAccount; from: Address; } : { account?: undefined; from?: undefined; }); export type PrepareTransactionRequestErrorType = AccountNotFoundErrorType | AssertRequestErrorType | ParseAccountErrorType | GetBlockErrorType | GetTransactionCountErrorType | EstimateGasErrorType | EstimateFeesPerGasErrorType; /** * Prepares a transaction request for signing. * * - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest.html * * @param args - {@link PrepareTransactionRequestParameters} * @returns The transaction request. {@link PrepareTransactionRequestReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * import { prepareTransactionRequest } from 'viem/actions' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const request = await prepareTransactionRequest(client, { * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x0000000000000000000000000000000000000000', * value: 1n, * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * import { prepareTransactionRequest } from 'viem/actions' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: custom(window.ethereum), * }) * const request = await prepareTransactionRequest(client, { * to: '0x0000000000000000000000000000000000000000', * value: 1n, * }) */ export declare function prepareTransactionRequest<TChain extends Chain | undefined, TAccount extends Account | undefined, TParameterType extends PrepareTransactionRequestParameterType, TAccountOverride extends Account | Address | undefined = undefined, TChainOverride extends Chain | undefined = undefined>(client: Client<Transport, TChain, TAccount>, args: PrepareTransactionRequestParameters<TChain, TAccount, TChainOverride, TAccountOverride, TParameterType>): Promise<PrepareTransactionRequestReturnType<TChain, TAccount, TChainOverride, TAccountOverride, TParameterType>>; export {}; //# sourceMappingURL=prepareTransactionRequest.d.ts.map