Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import type { ErrorType } from '../../errors/utils.js'
import type { BlockTag } from '../../types/block.js'
import type { Chain } from '../../types/chain.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Hex } from '../../types/misc.js'
import type { RpcTransactionRequest } from '../../types/rpc.js'
import type { StateOverride } from '../../types/stateOverride.js'
Expand Down Expand Up @@ -93,6 +94,8 @@ export type CallParameters<
factory?: Address | undefined
/** Calldata to execute on the factory to deploy the contract. */
factoryData?: Hex | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
/** State overrides for the call. */
stateOverride?: StateOverride | undefined
} & (
Expand Down Expand Up @@ -175,6 +178,7 @@ export async function call<chain extends Chain | undefined>(
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
requestOptions,
to,
value,
stateOverride,
Expand Down Expand Up @@ -280,10 +284,13 @@ export async function call<chain extends Chain | undefined>(
return base
})()

const response = await client.request({
method: 'eth_call',
params,
})
const response = await client.request(
{
method: 'eth_call',
params,
},
requestOptions,
)
if (response === '0x') return { data: undefined }
return { data: response }
} catch (err) {
Expand Down
15 changes: 11 additions & 4 deletions src/actions/public/createAccessList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { BlockTag } from '../../types/block.js'
import type { Chain } from '../../types/chain.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { RpcTransactionRequest } from '../../types/rpc.js'
import type { AccessList, TransactionRequest } from '../../types/transaction.js'
import type { ExactPartial, Prettify, UnionOmit } from '../../types/utils.js'
Expand Down Expand Up @@ -42,6 +43,8 @@ export type CreateAccessListParameters<
> & {
/** Account attached to the call (msg.sender). */
account?: Account | Address | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
} & (
| {
/** The balance of the account at a block number. */
Expand Down Expand Up @@ -111,6 +114,7 @@ export async function createAccessList<chain extends Chain | undefined>(
maxFeePerBlobGas,
maxFeePerGas,
maxPriorityFeePerGas,
requestOptions,
to,
value,
...rest
Expand Down Expand Up @@ -145,10 +149,13 @@ export async function createAccessList<chain extends Chain | undefined>(
'createAccessList',
) as TransactionRequest

const response = await client.request({
method: 'eth_createAccessList',
params: [request as ExactPartial<RpcTransactionRequest>, block],
})
const response = await client.request(
{
method: 'eth_createAccessList',
params: [request as ExactPartial<RpcTransactionRequest>, block],
},
requestOptions,
)
return {
accessList: response.accessList,
gasUsed: BigInt(response.gasUsed),
Expand Down
16 changes: 13 additions & 3 deletions src/actions/public/createBlockFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Filter } from '../../types/filter.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js'

export type CreateBlockFilterParameters = {
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
}

export type CreateBlockFilterReturnType = Filter<'block'>

export type CreateBlockFilterErrorType = RequestErrorType | ErrorType
Expand Down Expand Up @@ -33,12 +39,16 @@ export type CreateBlockFilterErrorType = RequestErrorType | ErrorType
*/
export async function createBlockFilter<chain extends Chain | undefined>(
client: Client<Transport, chain>,
{ requestOptions }: CreateBlockFilterParameters = {},
): Promise<CreateBlockFilterReturnType> {
const getRequest = createFilterRequestScope(client, {
method: 'eth_newBlockFilter',
})
const id = await client.request({
method: 'eth_newBlockFilter',
})
const id = await client.request(
{
method: 'eth_newBlockFilter',
},
requestOptions,
)
return { id, request: getRequest(id), type: 'block' }
}
42 changes: 28 additions & 14 deletions src/actions/public/createContractEventFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ContractEventName,
MaybeExtractEventArgsFromAbi,
} from '../../types/contract.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Filter } from '../../types/filter.js'
import type { Hex } from '../../types/misc.js'
import {
Expand Down Expand Up @@ -43,6 +44,8 @@ export type CreateContractEventFilterParameters<
*/
strict?: strict | boolean | undefined
toBlock?: toBlock | BlockNumber | BlockTag | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
} & (undefined extends eventName
? {
args?: undefined
Expand Down Expand Up @@ -125,8 +128,16 @@ export async function createContractEventFilter<
toBlock
>
> {
const { address, abi, args, eventName, fromBlock, strict, toBlock } =
parameters as CreateContractEventFilterParameters
const {
address,
abi,
args,
eventName,
fromBlock,
strict,
toBlock,
requestOptions,
} = parameters as CreateContractEventFilterParameters

const getRequest = createFilterRequestScope(client, {
method: 'eth_newFilter',
Expand All @@ -139,18 +150,21 @@ export async function createContractEventFilter<
eventName,
} as unknown as EncodeEventTopicsParameters)
: undefined
const id: Hex = await client.request({
method: 'eth_newFilter',
params: [
{
address,
fromBlock:
typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
topics,
},
],
})
const id: Hex = await client.request(
{
method: 'eth_newFilter',
params: [
{
address,
fromBlock:
typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
topics,
},
],
},
requestOptions,
)

return {
abi,
Expand Down
31 changes: 19 additions & 12 deletions src/actions/public/createEventFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
MaybeAbiEventName,
MaybeExtractEventArgsFromAbi,
} from '../../types/contract.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Filter } from '../../types/filter.js'
import type { Hex, LogTopic } from '../../types/misc.js'
import type { Prettify } from '../../types/utils.js'
Expand Down Expand Up @@ -42,6 +43,8 @@ export type CreateEventFilterParameters<
address?: Address | Address[] | undefined
fromBlock?: fromBlock | BlockNumber | BlockTag | undefined
toBlock?: toBlock | BlockNumber | BlockTag | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
} & (MaybeExtractEventArgsFromAbi<
abiEvents,
_eventName
Expand Down Expand Up @@ -160,6 +163,7 @@ export async function createEventFilter<
event,
events: events_,
fromBlock,
requestOptions,
strict,
toBlock,
}: CreateEventFilterParameters<
Expand Down Expand Up @@ -202,18 +206,21 @@ export async function createEventFilter<
if (event) topics = topics[0] as LogTopic[]
}

const id: Hex = await client.request({
method: 'eth_newFilter',
params: [
{
address,
fromBlock:
typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
...(topics.length ? { topics } : {}),
},
],
})
const id: Hex = await client.request(
{
method: 'eth_newFilter',
params: [
{
address,
fromBlock:
typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
...(topics.length ? { topics } : {}),
},
],
},
requestOptions,
)

return {
abi: events,
Expand Down
17 changes: 14 additions & 3 deletions src/actions/public/createPendingTransactionFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Filter } from '../../types/filter.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js'

export type CreatePendingTransactionFilterParameters = {
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
}

export type CreatePendingTransactionFilterReturnType = Filter<'transaction'>

export type CreatePendingTransactionFilterErrorType =
Expand All @@ -19,6 +25,7 @@ export type CreatePendingTransactionFilterErrorType =
* - JSON-RPC Methods: [`eth_newPendingTransactionFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newpendingtransactionfilter)
*
* @param client - Client to use
* @param parameters - {@link CreatePendingTransactionFilterParameters}
* @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateBlockFilterReturnType}
*
* @example
Expand All @@ -38,12 +45,16 @@ export async function createPendingTransactionFilter<
chain extends Chain | undefined,
>(
client: Client<transport, chain>,
{ requestOptions }: CreatePendingTransactionFilterParameters = {},
): Promise<CreatePendingTransactionFilterReturnType> {
const getRequest = createFilterRequestScope(client, {
method: 'eth_newPendingTransactionFilter',
})
const id = await client.request({
method: 'eth_newPendingTransactionFilter',
})
const id = await client.request(
{
method: 'eth_newPendingTransactionFilter',
},
requestOptions,
)
return { id, request: getRequest(id), type: 'transaction' }
}
3 changes: 3 additions & 0 deletions src/actions/public/estimateContractGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ContractFunctionParameters,
GetValue,
} from '../../types/contract.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type { Hex } from '../../types/misc.js'
import type { UnionOmit } from '../../types/utils.js'
import {
Expand Down Expand Up @@ -61,6 +62,8 @@ export type EstimateContractGasParameters<
> & {
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
dataSuffix?: Hex | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
}

export type EstimateContractGasReturnType = bigint
Expand Down
11 changes: 9 additions & 2 deletions src/actions/public/estimateFeesPerGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ChainFeesFnParameters,
GetChainParameter,
} from '../../types/chain.js'
import type { EIP1193RequestOptions } from '../../types/eip1193.js'
import type {
FeeValuesEIP1559,
FeeValuesLegacy,
Expand Down Expand Up @@ -43,6 +44,8 @@ export type EstimateFeesPerGasParameters<
* @default 'eip1559'
*/
type?: type | FeeValuesType | undefined
/** Request options. */
requestOptions?: EIP1193RequestOptions | undefined
} & GetChainParameter<chain, chainOverride>

export type EstimateFeesPerGasReturnType<
Expand Down Expand Up @@ -107,6 +110,7 @@ export async function internal_estimateFeesPerGas<
block: block_,
chain = client.chain,
request,
requestOptions,
type = 'eip1559',
} = args || {}

Expand All @@ -129,7 +133,7 @@ export async function internal_estimateFeesPerGas<

const block = block_
? block_
: await getAction(client, getBlock, 'getBlock')({})
: await getAction(client, getBlock, 'getBlock')({ requestOptions })

if (typeof chain?.fees?.estimateFeesPerGas === 'function') {
const fees = (await chain.fees.estimateFeesPerGas({
Expand All @@ -156,6 +160,7 @@ export async function internal_estimateFeesPerGas<
block: block as Block,
chain,
request,
requestOptions,
},
)

Expand All @@ -171,7 +176,9 @@ export async function internal_estimateFeesPerGas<

const gasPrice =
request?.gasPrice ??
multiply(await getAction(client, getGasPrice, 'getGasPrice')({}))
multiply(
await getAction(client, getGasPrice, 'getGasPrice')({ requestOptions }),
)
return {
gasPrice,
} as EstimateFeesPerGasReturnType<type>
Expand Down
Loading
Loading