viem 1.16.6 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/_cjs/actions/ens/getEnsAddress.js +2 -1
- package/_cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/_cjs/actions/ens/getEnsAvatar.js +2 -1
- package/_cjs/actions/ens/getEnsAvatar.js.map +1 -1
- package/_cjs/actions/ens/getEnsName.js +2 -1
- package/_cjs/actions/ens/getEnsName.js.map +1 -1
- package/_cjs/actions/ens/getEnsResolver.js +2 -1
- package/_cjs/actions/ens/getEnsResolver.js.map +1 -1
- package/_cjs/actions/ens/getEnsText.js +2 -1
- package/_cjs/actions/ens/getEnsText.js.map +1 -1
- package/_cjs/actions/getContract.js +8 -7
- package/_cjs/actions/getContract.js.map +1 -1
- package/_cjs/actions/public/estimateContractGas.js +2 -1
- package/_cjs/actions/public/estimateContractGas.js.map +1 -1
- package/_cjs/actions/public/estimateFeesPerGas.js +3 -2
- package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js +4 -3
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_cjs/actions/public/getContractEvents.js +2 -1
- package/_cjs/actions/public/getContractEvents.js.map +1 -1
- package/_cjs/actions/public/getTransactionConfirmations.js +3 -2
- package/_cjs/actions/public/getTransactionConfirmations.js.map +1 -1
- package/_cjs/actions/public/multicall.js +2 -1
- package/_cjs/actions/public/multicall.js.map +1 -1
- package/_cjs/actions/public/readContract.js +2 -1
- package/_cjs/actions/public/readContract.js.map +1 -1
- package/_cjs/actions/public/simulateContract.js +2 -1
- package/_cjs/actions/public/simulateContract.js.map +1 -1
- package/_cjs/actions/public/verifyHash.js +2 -1
- package/_cjs/actions/public/verifyHash.js.map +1 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js +6 -5
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +2 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +4 -3
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +6 -5
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +6 -5
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/public/watchPendingTransactions.js +4 -3
- package/_cjs/actions/public/watchPendingTransactions.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +4 -3
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +5 -4
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/signTransaction.js +2 -1
- package/_cjs/actions/wallet/signTransaction.js.map +1 -1
- package/_cjs/actions/wallet/writeContract.js +2 -1
- package/_cjs/actions/wallet/writeContract.js.map +1 -1
- package/_cjs/chains/definitions/modeTestnet.js +6 -0
- package/_cjs/chains/definitions/modeTestnet.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/errors/node.js +11 -11
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/rpc.js +18 -18
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/utils/getAction.js +8 -0
- package/_cjs/utils/getAction.js.map +1 -0
- package/_esm/actions/ens/getEnsAddress.js +2 -1
- package/_esm/actions/ens/getEnsAddress.js.map +1 -1
- package/_esm/actions/ens/getEnsAvatar.js +2 -1
- package/_esm/actions/ens/getEnsAvatar.js.map +1 -1
- package/_esm/actions/ens/getEnsName.js +2 -1
- package/_esm/actions/ens/getEnsName.js.map +1 -1
- package/_esm/actions/ens/getEnsResolver.js +2 -1
- package/_esm/actions/ens/getEnsResolver.js.map +1 -1
- package/_esm/actions/ens/getEnsText.js +2 -1
- package/_esm/actions/ens/getEnsText.js.map +1 -1
- package/_esm/actions/getContract.js +8 -7
- package/_esm/actions/getContract.js.map +1 -1
- package/_esm/actions/public/estimateContractGas.js +2 -1
- package/_esm/actions/public/estimateContractGas.js.map +1 -1
- package/_esm/actions/public/estimateFeesPerGas.js +3 -2
- package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js +4 -3
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_esm/actions/public/getContractEvents.js +2 -1
- package/_esm/actions/public/getContractEvents.js.map +1 -1
- package/_esm/actions/public/getTransactionConfirmations.js +3 -2
- package/_esm/actions/public/getTransactionConfirmations.js.map +1 -1
- package/_esm/actions/public/multicall.js +2 -1
- package/_esm/actions/public/multicall.js.map +1 -1
- package/_esm/actions/public/readContract.js +2 -1
- package/_esm/actions/public/readContract.js.map +1 -1
- package/_esm/actions/public/simulateContract.js +2 -1
- package/_esm/actions/public/simulateContract.js.map +1 -1
- package/_esm/actions/public/verifyHash.js +2 -1
- package/_esm/actions/public/verifyHash.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +6 -5
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +2 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +4 -3
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +6 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +6 -5
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/public/watchPendingTransactions.js +4 -3
- package/_esm/actions/public/watchPendingTransactions.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +4 -3
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +5 -4
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/signTransaction.js +2 -1
- package/_esm/actions/wallet/signTransaction.js.map +1 -1
- package/_esm/actions/wallet/writeContract.js +2 -1
- package/_esm/actions/wallet/writeContract.js.map +1 -1
- package/_esm/chains/definitions/modeTestnet.js +6 -0
- package/_esm/chains/definitions/modeTestnet.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/errors/node.js +11 -22
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +18 -36
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/utils/getAction.js +4 -0
- package/_esm/utils/getAction.js.map +1 -0
- package/_types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/_types/actions/ens/getEnsAvatar.d.ts.map +1 -1
- package/_types/actions/ens/getEnsName.d.ts.map +1 -1
- package/_types/actions/ens/getEnsResolver.d.ts.map +1 -1
- package/_types/actions/ens/getEnsText.d.ts.map +1 -1
- package/_types/actions/getContract.d.ts.map +1 -1
- package/_types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/_types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
- package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
- package/_types/actions/public/getContractEvents.d.ts.map +1 -1
- package/_types/actions/public/getTransactionConfirmations.d.ts.map +1 -1
- package/_types/actions/public/multicall.d.ts.map +1 -1
- package/_types/actions/public/readContract.d.ts.map +1 -1
- package/_types/actions/public/simulateContract.d.ts.map +1 -1
- package/_types/actions/public/verifyHash.d.ts.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/public/watchPendingTransactions.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/signTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/writeContract.d.ts.map +1 -1
- package/_types/chains/definitions/modeTestnet.d.ts +6 -0
- package/_types/chains/definitions/modeTestnet.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -2
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/utils/getAction.d.ts +3 -0
- package/_types/utils/getAction.d.ts.map +1 -0
- package/actions/ens/getEnsAddress.ts +5 -1
- package/actions/ens/getEnsAvatar.ts +5 -1
- package/actions/ens/getEnsName.ts +5 -1
- package/actions/ens/getEnsResolver.ts +5 -1
- package/actions/ens/getEnsText.ts +5 -1
- package/actions/getContract.ts +29 -7
- package/actions/public/estimateContractGas.ts +5 -1
- package/actions/public/estimateFeesPerGas.ts +4 -2
- package/actions/public/estimateMaxPriorityFeePerGas.ts +4 -3
- package/actions/public/getContractEvents.ts +5 -1
- package/actions/public/getTransactionConfirmations.ts +3 -2
- package/actions/public/multicall.ts +5 -1
- package/actions/public/readContract.ts +5 -1
- package/actions/public/simulateContract.ts +5 -1
- package/actions/public/verifyHash.ts +5 -1
- package/actions/public/waitForTransactionReceipt.ts +19 -6
- package/actions/public/watchBlockNumber.ts +5 -1
- package/actions/public/watchBlocks.ts +10 -3
- package/actions/public/watchContractEvent.ts +12 -5
- package/actions/public/watchEvent.ts +12 -5
- package/actions/public/watchPendingTransactions.ts +7 -3
- package/actions/wallet/prepareTransactionRequest.ts +10 -3
- package/actions/wallet/sendTransaction.ts +11 -4
- package/actions/wallet/signTransaction.ts +2 -1
- package/actions/wallet/writeContract.ts +5 -1
- package/chains/definitions/modeTestnet.ts +6 -0
- package/clients/createClient.ts +39 -2
- package/package.json +1 -1
- package/utils/getAction.ts +13 -0
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
type GetAbiItemParameters,
|
14
14
|
getAbiItem,
|
15
15
|
} from '../../utils/abi/getAbiItem.js'
|
16
|
+
import { getAction } from '../../utils/getAction.js'
|
16
17
|
import {
|
17
18
|
type GetLogsErrorType,
|
18
19
|
type GetLogsParameters,
|
@@ -130,7 +131,10 @@ export async function getContractEvents<
|
|
130
131
|
const events = !event
|
131
132
|
? (abi as Abi).filter((x) => x.type === 'event')
|
132
133
|
: undefined
|
133
|
-
return
|
134
|
+
return getAction(
|
135
|
+
client,
|
136
|
+
getLogs,
|
137
|
+
)({
|
134
138
|
address,
|
135
139
|
args,
|
136
140
|
blockHash,
|
@@ -4,6 +4,7 @@ import type { ErrorType } from '../../errors/utils.js'
|
|
4
4
|
import type { Chain } from '../../types/chain.js'
|
5
5
|
import type { Hash } from '../../types/misc.js'
|
6
6
|
import type { FormattedTransactionReceipt } from '../../utils/formatters/transactionReceipt.js'
|
7
|
+
import { getAction } from '../../utils/getAction.js'
|
7
8
|
|
8
9
|
import {
|
9
10
|
type GetBlockNumberErrorType,
|
@@ -66,8 +67,8 @@ export async function getTransactionConfirmations<
|
|
66
67
|
{ hash, transactionReceipt }: GetTransactionConfirmationsParameters<TChain>,
|
67
68
|
): Promise<GetTransactionConfirmationsReturnType> {
|
68
69
|
const [blockNumber, transaction] = await Promise.all([
|
69
|
-
|
70
|
-
hash ?
|
70
|
+
getAction(client, getBlockNumber)({}),
|
71
|
+
hash ? getAction(client, getTransaction)({ hash }) : undefined,
|
71
72
|
])
|
72
73
|
const transactionBlockNumber =
|
73
74
|
transactionReceipt?.blockNumber || transaction?.blockNumber
|
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
} from '../../utils/errors/getContractError.js'
|
33
33
|
|
34
34
|
import type { ErrorType } from '../../errors/utils.js'
|
35
|
+
import { getAction } from '../../utils/getAction.js'
|
35
36
|
import type { CallParameters } from './call.js'
|
36
37
|
import { type ReadContractErrorType, readContract } from './readContract.js'
|
37
38
|
|
@@ -200,7 +201,10 @@ export async function multicall<
|
|
200
201
|
|
201
202
|
const aggregate3Results = await Promise.allSettled(
|
202
203
|
chunkedCalls.map((calls) =>
|
203
|
-
|
204
|
+
getAction(
|
205
|
+
client,
|
206
|
+
readContract,
|
207
|
+
)({
|
204
208
|
abi: multicall3Abi,
|
205
209
|
address: multicallAddress!,
|
206
210
|
args: [calls],
|
@@ -22,6 +22,7 @@ import {
|
|
22
22
|
type GetContractErrorReturnType,
|
23
23
|
getContractError,
|
24
24
|
} from '../../utils/errors/getContractError.js'
|
25
|
+
import { getAction } from '../../utils/getAction.js'
|
25
26
|
|
26
27
|
import { type CallErrorType, type CallParameters, call } from './call.js'
|
27
28
|
|
@@ -91,7 +92,10 @@ export async function readContract<
|
|
91
92
|
functionName,
|
92
93
|
} as unknown as EncodeFunctionDataParameters<TAbi, TFunctionName>)
|
93
94
|
try {
|
94
|
-
const { data } = await
|
95
|
+
const { data } = await getAction(
|
96
|
+
client,
|
97
|
+
call,
|
98
|
+
)({
|
95
99
|
data: calldata,
|
96
100
|
to: address,
|
97
101
|
...callRequest,
|
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
import type { WriteContractParameters } from '../wallet/writeContract.js'
|
33
33
|
|
34
34
|
import type { ErrorType } from '../../errors/utils.js'
|
35
|
+
import { getAction } from '../../utils/getAction.js'
|
35
36
|
import { type CallErrorType, type CallParameters, call } from './call.js'
|
36
37
|
|
37
38
|
export type SimulateContractParameters<
|
@@ -142,7 +143,10 @@ export async function simulateContract<
|
|
142
143
|
functionName,
|
143
144
|
} as unknown as EncodeFunctionDataParameters<TAbi, TFunctionName>)
|
144
145
|
try {
|
145
|
-
const { data } = await
|
146
|
+
const { data } = await getAction(
|
147
|
+
client,
|
148
|
+
call,
|
149
|
+
)({
|
146
150
|
batch: false,
|
147
151
|
data: `${calldata}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
|
148
152
|
to: address,
|
@@ -15,6 +15,7 @@ import {
|
|
15
15
|
} from '../../utils/data/isBytesEqual.js'
|
16
16
|
import type { IsHexErrorType } from '../../utils/data/isHex.js'
|
17
17
|
import type { ToHexErrorType } from '../../utils/encoding/toHex.js'
|
18
|
+
import { getAction } from '../../utils/getAction.js'
|
18
19
|
import { encodeDeployData, isHex, toHex } from '../../utils/index.js'
|
19
20
|
import { type CallErrorType, type CallParameters, call } from './call.js'
|
20
21
|
|
@@ -54,7 +55,10 @@ export async function verifyHash<TChain extends Chain | undefined,>(
|
|
54
55
|
const signatureHex = isHex(signature) ? signature : toHex(signature)
|
55
56
|
|
56
57
|
try {
|
57
|
-
const { data } = await
|
58
|
+
const { data } = await getAction(
|
59
|
+
client,
|
60
|
+
call,
|
61
|
+
)({
|
58
62
|
data: encodeDeployData({
|
59
63
|
abi: universalSignatureValidatorAbi,
|
60
64
|
args: [address, hash, signatureHex],
|
@@ -9,6 +9,7 @@ import type { ErrorType } from '../../errors/utils.js'
|
|
9
9
|
import type { Chain } from '../../types/chain.js'
|
10
10
|
import type { Hash } from '../../types/misc.js'
|
11
11
|
import type { Transaction } from '../../types/transaction.js'
|
12
|
+
import { getAction } from '../../utils/getAction.js'
|
12
13
|
import { type ObserveErrorType, observe } from '../../utils/observe.js'
|
13
14
|
import { withRetry } from '../../utils/promise/withRetry.js'
|
14
15
|
import { stringify } from '../../utils/stringify.js'
|
@@ -140,7 +141,10 @@ export async function waitForTransactionReceipt<
|
|
140
141
|
observerId,
|
141
142
|
{ onReplaced, resolve, reject },
|
142
143
|
(emit) => {
|
143
|
-
const _unwatch =
|
144
|
+
const _unwatch = getAction(
|
145
|
+
client,
|
146
|
+
watchBlockNumber,
|
147
|
+
)({
|
144
148
|
emitMissed: true,
|
145
149
|
emitOnBegin: true,
|
146
150
|
poll: true,
|
@@ -178,7 +182,10 @@ export async function waitForTransactionReceipt<
|
|
178
182
|
retrying = true
|
179
183
|
await withRetry(
|
180
184
|
async () => {
|
181
|
-
transaction = await
|
185
|
+
transaction = (await getAction(
|
186
|
+
client,
|
187
|
+
getTransaction,
|
188
|
+
)({ hash })) as GetTransactionReturnType<TChain>
|
182
189
|
if (transaction.blockNumber)
|
183
190
|
blockNumber = transaction.blockNumber
|
184
191
|
},
|
@@ -192,7 +199,7 @@ export async function waitForTransactionReceipt<
|
|
192
199
|
}
|
193
200
|
|
194
201
|
// Get the receipt to check if it's been processed.
|
195
|
-
receipt = await
|
202
|
+
receipt = await getAction(client, getTransactionReceipt)({ hash })
|
196
203
|
|
197
204
|
// Check if we have enough confirmations. If not, continue polling.
|
198
205
|
if (
|
@@ -215,13 +222,16 @@ export async function waitForTransactionReceipt<
|
|
215
222
|
replacedTransaction = transaction
|
216
223
|
|
217
224
|
// Let's retrieve the transactions from the current block.
|
218
|
-
const block = await
|
225
|
+
const block = await getAction(
|
226
|
+
client,
|
227
|
+
getBlock,
|
228
|
+
)({
|
219
229
|
blockNumber,
|
220
230
|
includeTransactions: true,
|
221
231
|
})
|
222
232
|
|
223
233
|
const replacementTransaction = (
|
224
|
-
block.transactions as Transaction[]
|
234
|
+
block.transactions as {} as Transaction[]
|
225
235
|
).find(
|
226
236
|
({ from, nonce }) =>
|
227
237
|
from === replacedTransaction!.from &&
|
@@ -232,7 +242,10 @@ export async function waitForTransactionReceipt<
|
|
232
242
|
if (!replacementTransaction) return
|
233
243
|
|
234
244
|
// If we found a replacement transaction, return it's receipt.
|
235
|
-
receipt = await
|
245
|
+
receipt = await getAction(
|
246
|
+
client,
|
247
|
+
getTransactionReceipt,
|
248
|
+
)({
|
236
249
|
hash: replacementTransaction.hash,
|
237
250
|
})
|
238
251
|
|
@@ -4,6 +4,7 @@ import type { ErrorType } from '../../errors/utils.js'
|
|
4
4
|
import type { Chain } from '../../types/chain.js'
|
5
5
|
import type { GetTransportConfig } from '../../types/transport.js'
|
6
6
|
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
7
|
+
import { getAction } from '../../utils/getAction.js'
|
7
8
|
import { observe } from '../../utils/observe.js'
|
8
9
|
import { type PollErrorType, poll } from '../../utils/poll.js'
|
9
10
|
import { stringify } from '../../utils/stringify.js'
|
@@ -108,7 +109,10 @@ export function watchBlockNumber<
|
|
108
109
|
poll(
|
109
110
|
async () => {
|
110
111
|
try {
|
111
|
-
const blockNumber = await
|
112
|
+
const blockNumber = await getAction(
|
113
|
+
client,
|
114
|
+
getBlockNumber,
|
115
|
+
)({ cacheTime: 0 })
|
112
116
|
|
113
117
|
if (prevBlockNumber) {
|
114
118
|
// If the current block number is the same as the previous,
|
@@ -5,6 +5,7 @@ import type { BlockTag } from '../../types/block.js'
|
|
5
5
|
import type { Chain } from '../../types/chain.js'
|
6
6
|
import type { GetTransportConfig } from '../../types/transport.js'
|
7
7
|
import { formatBlock } from '../../utils/formatters/block.js'
|
8
|
+
import { getAction } from '../../utils/getAction.js'
|
8
9
|
import { observe } from '../../utils/observe.js'
|
9
10
|
import { type PollErrorType, poll } from '../../utils/poll.js'
|
10
11
|
import { type StringifyErrorType, stringify } from '../../utils/stringify.js'
|
@@ -140,7 +141,10 @@ export function watchBlocks<
|
|
140
141
|
poll(
|
141
142
|
async () => {
|
142
143
|
try {
|
143
|
-
const block = await
|
144
|
+
const block = await getAction(
|
145
|
+
client,
|
146
|
+
getBlock,
|
147
|
+
)({
|
144
148
|
blockTag,
|
145
149
|
includeTransactions,
|
146
150
|
})
|
@@ -153,10 +157,13 @@ export function watchBlocks<
|
|
153
157
|
// `emitMissed` flag is truthy, let's emit those blocks.
|
154
158
|
if (block.number - prevBlock.number > 1 && emitMissed) {
|
155
159
|
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
156
|
-
const block = await
|
160
|
+
const block = (await getAction(
|
161
|
+
client,
|
162
|
+
getBlock,
|
163
|
+
)({
|
157
164
|
blockNumber: i,
|
158
165
|
includeTransactions,
|
159
|
-
})
|
166
|
+
})) as GetBlockReturnType<TChain>
|
160
167
|
emit.onBlock(block as any, prevBlock as any)
|
161
168
|
prevBlock = block
|
162
169
|
}
|
@@ -25,6 +25,7 @@ import {
|
|
25
25
|
encodeEventTopics,
|
26
26
|
} from '../../utils/abi/encodeEventTopics.js'
|
27
27
|
import { formatLog } from '../../utils/formatters/log.js'
|
28
|
+
import { getAction } from '../../utils/getAction.js'
|
28
29
|
import {
|
29
30
|
type CreateContractEventFilterParameters,
|
30
31
|
createContractEventFilter,
|
@@ -187,7 +188,10 @@ export function watchContractEvent<
|
|
187
188
|
async () => {
|
188
189
|
if (!initialized) {
|
189
190
|
try {
|
190
|
-
filter = (await
|
191
|
+
filter = (await getAction(
|
192
|
+
client,
|
193
|
+
createContractEventFilter,
|
194
|
+
)({
|
191
195
|
abi,
|
192
196
|
address,
|
193
197
|
args,
|
@@ -206,19 +210,22 @@ export function watchContractEvent<
|
|
206
210
|
try {
|
207
211
|
let logs: Log[]
|
208
212
|
if (filter) {
|
209
|
-
logs = await
|
213
|
+
logs = await getAction(client, getFilterChanges)({ filter })
|
210
214
|
} else {
|
211
215
|
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
212
216
|
// The fall back exists because some RPC Providers do not support filters.
|
213
217
|
|
214
218
|
// Fetch the block number to use for `getLogs`.
|
215
|
-
const blockNumber = await
|
219
|
+
const blockNumber = await getAction(client, getBlockNumber)({})
|
216
220
|
|
217
221
|
// If the block number has changed, we will need to fetch the logs.
|
218
222
|
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
219
223
|
// so do not emit any logs.
|
220
224
|
if (previousBlockNumber && previousBlockNumber !== blockNumber) {
|
221
|
-
logs = await
|
225
|
+
logs = await getAction(
|
226
|
+
client,
|
227
|
+
getContractEvents,
|
228
|
+
)({
|
222
229
|
abi,
|
223
230
|
address,
|
224
231
|
args,
|
@@ -250,7 +257,7 @@ export function watchContractEvent<
|
|
250
257
|
)
|
251
258
|
|
252
259
|
return async () => {
|
253
|
-
if (filter) await
|
260
|
+
if (filter) await getAction(client, uninstallFilter)({ filter })
|
254
261
|
unwatch()
|
255
262
|
}
|
256
263
|
})
|
@@ -22,6 +22,7 @@ import {
|
|
22
22
|
} from '../../errors/abi.js'
|
23
23
|
import { InvalidInputRpcError } from '../../errors/rpc.js'
|
24
24
|
import type { ErrorType } from '../../errors/utils.js'
|
25
|
+
import { getAction } from '../../utils/getAction.js'
|
25
26
|
import {
|
26
27
|
decodeEventLog,
|
27
28
|
encodeEventTopics,
|
@@ -222,7 +223,10 @@ export function watchEvent<
|
|
222
223
|
async () => {
|
223
224
|
if (!initialized) {
|
224
225
|
try {
|
225
|
-
filter = (await
|
226
|
+
filter = (await getAction(
|
227
|
+
client,
|
228
|
+
createEventFilter as any,
|
229
|
+
)({
|
226
230
|
address,
|
227
231
|
args,
|
228
232
|
event: event!,
|
@@ -241,19 +245,22 @@ export function watchEvent<
|
|
241
245
|
try {
|
242
246
|
let logs: Log[]
|
243
247
|
if (filter) {
|
244
|
-
logs = await
|
248
|
+
logs = await getAction(client, getFilterChanges)({ filter })
|
245
249
|
} else {
|
246
250
|
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
247
251
|
// The fall back exists because some RPC Providers do not support filters.
|
248
252
|
|
249
253
|
// Fetch the block number to use for `getLogs`.
|
250
|
-
const blockNumber = await
|
254
|
+
const blockNumber = await getAction(client, getBlockNumber)({})
|
251
255
|
|
252
256
|
// If the block number has changed, we will need to fetch the logs.
|
253
257
|
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
254
258
|
// so do not emit any logs.
|
255
259
|
if (previousBlockNumber && previousBlockNumber !== blockNumber) {
|
256
|
-
logs = await
|
260
|
+
logs = await getAction(
|
261
|
+
client,
|
262
|
+
getLogs,
|
263
|
+
)({
|
257
264
|
address,
|
258
265
|
args,
|
259
266
|
event: event!,
|
@@ -285,7 +292,7 @@ export function watchEvent<
|
|
285
292
|
)
|
286
293
|
|
287
294
|
return async () => {
|
288
|
-
if (filter) await
|
295
|
+
if (filter) await getAction(client, uninstallFilter)({ filter })
|
289
296
|
unwatch()
|
290
297
|
}
|
291
298
|
})
|
@@ -5,6 +5,7 @@ import type { Chain } from '../../types/chain.js'
|
|
5
5
|
import type { Filter } from '../../types/filter.js'
|
6
6
|
import type { Hash } from '../../types/misc.js'
|
7
7
|
import type { GetTransportConfig } from '../../types/transport.js'
|
8
|
+
import { getAction } from '../../utils/getAction.js'
|
8
9
|
import { type ObserveErrorType, observe } from '../../utils/observe.js'
|
9
10
|
import { poll } from '../../utils/poll.js'
|
10
11
|
import { type StringifyErrorType, stringify } from '../../utils/stringify.js'
|
@@ -125,7 +126,10 @@ export function watchPendingTransactions<
|
|
125
126
|
try {
|
126
127
|
if (!filter) {
|
127
128
|
try {
|
128
|
-
filter = await
|
129
|
+
filter = await getAction(
|
130
|
+
client,
|
131
|
+
createPendingTransactionFilter,
|
132
|
+
)({})
|
129
133
|
return
|
130
134
|
} catch (err) {
|
131
135
|
unwatch()
|
@@ -133,7 +137,7 @@ export function watchPendingTransactions<
|
|
133
137
|
}
|
134
138
|
}
|
135
139
|
|
136
|
-
const hashes = await
|
140
|
+
const hashes = await getAction(client, getFilterChanges)({ filter })
|
137
141
|
if (hashes.length === 0) return
|
138
142
|
if (batch) emit.onTransactions(hashes)
|
139
143
|
else hashes.forEach((hash) => emit.onTransactions([hash]))
|
@@ -148,7 +152,7 @@ export function watchPendingTransactions<
|
|
148
152
|
)
|
149
153
|
|
150
154
|
return async () => {
|
151
|
-
if (filter) await
|
155
|
+
if (filter) await getAction(client, uninstallFilter)({ filter })
|
152
156
|
unwatch()
|
153
157
|
}
|
154
158
|
})
|
@@ -36,6 +36,7 @@ import type { GetChain } from '../../types/chain.js'
|
|
36
36
|
import type { TransactionSerializable } from '../../types/transaction.js'
|
37
37
|
import type { UnionOmit } from '../../types/utils.js'
|
38
38
|
import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
|
39
|
+
import { getAction } from '../../utils/getAction.js'
|
39
40
|
import type {
|
40
41
|
AssertRequestErrorType,
|
41
42
|
AssertRequestParameters,
|
@@ -129,12 +130,15 @@ export async function prepareTransactionRequest<
|
|
129
130
|
if (!account_) throw new AccountNotFoundError()
|
130
131
|
const account = parseAccount(account_)
|
131
132
|
|
132
|
-
const block = await
|
133
|
+
const block = await getAction(client, getBlock)({ blockTag: 'latest' })
|
133
134
|
|
134
135
|
const request = { ...args, from: account.address }
|
135
136
|
|
136
137
|
if (typeof nonce === 'undefined')
|
137
|
-
request.nonce = await
|
138
|
+
request.nonce = await getAction(
|
139
|
+
client,
|
140
|
+
getTransactionCount,
|
141
|
+
)({
|
138
142
|
address: account.address,
|
139
143
|
blockTag: 'pending',
|
140
144
|
})
|
@@ -189,7 +193,10 @@ export async function prepareTransactionRequest<
|
|
189
193
|
}
|
190
194
|
|
191
195
|
if (typeof gas === 'undefined')
|
192
|
-
request.gas = await
|
196
|
+
request.gas = await getAction(
|
197
|
+
client,
|
198
|
+
estimateGas,
|
199
|
+
)({
|
193
200
|
...request,
|
194
201
|
account: { address: account.address, type: 'json-rpc' },
|
195
202
|
} as EstimateGasParameters)
|
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
type FormattedTransactionRequest,
|
33
33
|
formatTransactionRequest,
|
34
34
|
} from '../../utils/formatters/transactionRequest.js'
|
35
|
+
import { getAction } from '../../utils/getAction.js'
|
35
36
|
import {
|
36
37
|
type AssertRequestErrorType,
|
37
38
|
type AssertRequestParameters,
|
@@ -154,7 +155,7 @@ export async function sendTransaction<
|
|
154
155
|
|
155
156
|
let chainId
|
156
157
|
if (chain !== null) {
|
157
|
-
chainId = await
|
158
|
+
chainId = await getAction(client, getChainId)({})
|
158
159
|
assertCurrentChain({
|
159
160
|
currentChainId: chainId,
|
160
161
|
chain,
|
@@ -163,7 +164,10 @@ export async function sendTransaction<
|
|
163
164
|
|
164
165
|
if (account.type === 'local') {
|
165
166
|
// Prepare the request for signing (assign appropriate fees, etc.)
|
166
|
-
const request = await
|
167
|
+
const request = await getAction(
|
168
|
+
client,
|
169
|
+
prepareTransactionRequest,
|
170
|
+
)({
|
167
171
|
account,
|
168
172
|
accessList,
|
169
173
|
chain,
|
@@ -178,7 +182,7 @@ export async function sendTransaction<
|
|
178
182
|
...rest,
|
179
183
|
} as any)
|
180
184
|
|
181
|
-
if (!chainId) chainId = await
|
185
|
+
if (!chainId) chainId = await getAction(client, getChainId)({})
|
182
186
|
|
183
187
|
const serializer = chain?.serializers?.transaction
|
184
188
|
const serializedTransaction = (await account.signTransaction(
|
@@ -188,7 +192,10 @@ export async function sendTransaction<
|
|
188
192
|
} as TransactionSerializable,
|
189
193
|
{ serializer },
|
190
194
|
)) as Hash
|
191
|
-
return await
|
195
|
+
return await getAction(
|
196
|
+
client,
|
197
|
+
sendRawTransaction,
|
198
|
+
)({
|
192
199
|
serializedTransaction,
|
193
200
|
})
|
194
201
|
}
|
@@ -27,6 +27,7 @@ import {
|
|
27
27
|
type FormattedTransactionRequest,
|
28
28
|
formatTransactionRequest,
|
29
29
|
} from '../../utils/formatters/transactionRequest.js'
|
30
|
+
import { getAction } from '../../utils/getAction.js'
|
30
31
|
import { numberToHex } from '../../utils/index.js'
|
31
32
|
import {
|
32
33
|
type AssertRequestErrorType,
|
@@ -127,7 +128,7 @@ export async function signTransaction<
|
|
127
128
|
...args,
|
128
129
|
})
|
129
130
|
|
130
|
-
const chainId = await
|
131
|
+
const chainId = await getAction(client, getChainId)({})
|
131
132
|
if (chain !== null)
|
132
133
|
assertCurrentChain({
|
133
134
|
currentChainId: chainId,
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
encodeFunctionData,
|
17
17
|
} from '../../utils/abi/encodeFunctionData.js'
|
18
18
|
import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
|
19
|
+
import { getAction } from '../../utils/getAction.js'
|
19
20
|
import {
|
20
21
|
type SendTransactionErrorType,
|
21
22
|
type SendTransactionParameters,
|
@@ -138,7 +139,10 @@ export async function writeContract<
|
|
138
139
|
args,
|
139
140
|
functionName,
|
140
141
|
} as unknown as EncodeFunctionDataParameters<TAbi, TFunctionName>)
|
141
|
-
const hash = await
|
142
|
+
const hash = await getAction(
|
143
|
+
client,
|
144
|
+
sendTransaction,
|
145
|
+
)({
|
142
146
|
data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
|
143
147
|
to: address,
|
144
148
|
...request,
|
@@ -19,5 +19,11 @@ export const modeTestnet = /*#__PURE__*/ defineChain({
|
|
19
19
|
url: 'https://sepolia.explorer.mode.network',
|
20
20
|
},
|
21
21
|
},
|
22
|
+
contracts: {
|
23
|
+
multicall3: {
|
24
|
+
address: '0xBAba8373113Fb7a68f195deF18732e01aF8eDfCF',
|
25
|
+
blockCreated: 3019007,
|
26
|
+
},
|
27
|
+
},
|
22
28
|
testnet: true,
|
23
29
|
})
|
package/clients/createClient.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type { JsonRpcAccount } from '../accounts/types.js'
|
4
4
|
import type { ParseAccountErrorType } from '../accounts/utils/parseAccount.js'
|
5
5
|
import type { ErrorType } from '../errors/utils.js'
|
6
|
+
import type { Account } from '../types/account.js'
|
6
7
|
import type { Chain } from '../types/chain.js'
|
7
8
|
import type {
|
8
9
|
EIP1193RequestFn,
|
@@ -12,6 +13,8 @@ import type {
|
|
12
13
|
import type { Prettify } from '../types/utils.js'
|
13
14
|
import { parseAccount } from '../utils/accounts.js'
|
14
15
|
import { uid } from '../utils/uid.js'
|
16
|
+
import type { PublicActions } from './decorators/public.js'
|
17
|
+
import type { WalletActions } from './decorators/wallet.js'
|
15
18
|
import type { Transport } from './transports/createTransport.js'
|
16
19
|
|
17
20
|
export type ClientConfig<
|
@@ -53,6 +56,38 @@ export type ClientConfig<
|
|
53
56
|
type?: string | undefined
|
54
57
|
}
|
55
58
|
|
59
|
+
// Actions that are used internally by other Actions (ie. `call` is used by `readContract`).
|
60
|
+
// They are allowed to be extended, but must conform to their parameter & return type interfaces.
|
61
|
+
// Example: an extended `call` action must accept `CallParameters` as parameters,
|
62
|
+
// and conform to the `CallReturnType` return type.
|
63
|
+
type ExtendableProtectedActions = Pick<
|
64
|
+
PublicActions,
|
65
|
+
| 'call'
|
66
|
+
| 'createContractEventFilter'
|
67
|
+
| 'createEventFilter'
|
68
|
+
| 'estimateContractGas'
|
69
|
+
| 'estimateGas'
|
70
|
+
| 'getBlock'
|
71
|
+
| 'getBlockNumber'
|
72
|
+
| 'getChainId'
|
73
|
+
| 'getContractEvents'
|
74
|
+
| 'getEnsText'
|
75
|
+
| 'getFilterChanges'
|
76
|
+
| 'getGasPrice'
|
77
|
+
| 'getLogs'
|
78
|
+
| 'getTransaction'
|
79
|
+
| 'getTransactionCount'
|
80
|
+
| 'getTransactionReceipt'
|
81
|
+
| 'prepareTransactionRequest'
|
82
|
+
| 'readContract'
|
83
|
+
| 'sendRawTransaction'
|
84
|
+
| 'simulateContract'
|
85
|
+
| 'uninstallFilter'
|
86
|
+
| 'watchBlockNumber'
|
87
|
+
| 'watchContractEvent'
|
88
|
+
> &
|
89
|
+
Pick<WalletActions, 'sendTransaction' | 'writeContract'>
|
90
|
+
|
56
91
|
// TODO: Move `transport` to slot index 2 since `chain` and `account` used more frequently.
|
57
92
|
// Otherwise, we end up with a lot of `Client<Transport, chain, account>` in actions.
|
58
93
|
export type Client<
|
@@ -63,7 +98,9 @@ export type Client<
|
|
63
98
|
extended extends Extended | undefined = Extended | undefined,
|
64
99
|
> = Client_Base<transport, chain, account, rpcSchema> &
|
65
100
|
(extended extends Extended ? extended : unknown) & {
|
66
|
-
extend: <
|
101
|
+
extend: <
|
102
|
+
const client extends Extended & Partial<ExtendableProtectedActions>,
|
103
|
+
>(
|
67
104
|
fn: (
|
68
105
|
client: Client<transport, chain, account, rpcSchema, extended>,
|
69
106
|
) => client,
|
package/package.json
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { Client } from '../clients/createClient.js'
|
2
|
+
|
3
|
+
export function getAction<params extends {}, returnType extends {}>(
|
4
|
+
client: Client,
|
5
|
+
action: (_: any, params: params) => returnType,
|
6
|
+
) {
|
7
|
+
return (params: params): returnType =>
|
8
|
+
(
|
9
|
+
client as Client & {
|
10
|
+
[key: string]: (params: params) => returnType
|
11
|
+
}
|
12
|
+
)[action.name]?.(params) ?? action(client, params)
|
13
|
+
}
|