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
20 changes: 12 additions & 8 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -92,6 +93,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 @@ -174,6 +177,7 @@ export async function call<chain extends Chain | undefined>(
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
requestOptions,
to,
value,
stateOverride,
Expand Down Expand Up @@ -276,10 +280,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 Expand Up @@ -428,10 +435,7 @@ type ToDeploylessCallViaBytecodeDataErrorType =
| EncodeDeployDataErrorType
| ErrorType

function toDeploylessCallViaBytecodeData(parameters: {
code: Hex
data: Hex
}) {
function toDeploylessCallViaBytecodeData(parameters: { code: Hex; data: Hex }) {
const { code, data } = parameters
return encodeDeployData({
abi: parseAbi(['constructor(bytes, bytes)']),
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 @@ -142,10 +146,13 @@ export async function createAccessList<chain extends Chain | undefined>(
value,
} as TransactionRequest) 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' }
}
15 changes: 13 additions & 2 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 Expand Up @@ -106,8 +109,15 @@ export async function estimateContractGas<
client: Client<Transport, chain, account>,
parameters: EstimateContractGasParameters<abi, functionName, args, chain>,
): Promise<EstimateContractGasReturnType> {
const { abi, address, args, functionName, dataSuffix, ...request } =
parameters as EstimateContractGasParameters
const {
abi,
address,
args,
functionName,
dataSuffix,
requestOptions,
...request
} = parameters as EstimateContractGasParameters
const data = encodeFunctionData({
abi,
args,
Expand All @@ -122,6 +132,7 @@ export async function estimateContractGas<
data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
to: address,
...request,
requestOptions,
} as unknown as EstimateGasParameters)
return gas
} catch (error) {
Expand Down
Loading
Loading