viem 1.16.5 → 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.
Files changed (191) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/_cjs/actions/ens/getEnsAddress.js +2 -1
  3. package/_cjs/actions/ens/getEnsAddress.js.map +1 -1
  4. package/_cjs/actions/ens/getEnsAvatar.js +2 -1
  5. package/_cjs/actions/ens/getEnsAvatar.js.map +1 -1
  6. package/_cjs/actions/ens/getEnsName.js +2 -1
  7. package/_cjs/actions/ens/getEnsName.js.map +1 -1
  8. package/_cjs/actions/ens/getEnsResolver.js +2 -1
  9. package/_cjs/actions/ens/getEnsResolver.js.map +1 -1
  10. package/_cjs/actions/ens/getEnsText.js +2 -1
  11. package/_cjs/actions/ens/getEnsText.js.map +1 -1
  12. package/_cjs/actions/getContract.js +8 -7
  13. package/_cjs/actions/getContract.js.map +1 -1
  14. package/_cjs/actions/public/estimateContractGas.js +2 -1
  15. package/_cjs/actions/public/estimateContractGas.js.map +1 -1
  16. package/_cjs/actions/public/estimateFeesPerGas.js +3 -2
  17. package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
  18. package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js +4 -3
  19. package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  20. package/_cjs/actions/public/getContractEvents.js +2 -1
  21. package/_cjs/actions/public/getContractEvents.js.map +1 -1
  22. package/_cjs/actions/public/getTransactionConfirmations.js +3 -2
  23. package/_cjs/actions/public/getTransactionConfirmations.js.map +1 -1
  24. package/_cjs/actions/public/multicall.js +2 -1
  25. package/_cjs/actions/public/multicall.js.map +1 -1
  26. package/_cjs/actions/public/readContract.js +2 -1
  27. package/_cjs/actions/public/readContract.js.map +1 -1
  28. package/_cjs/actions/public/simulateContract.js +2 -1
  29. package/_cjs/actions/public/simulateContract.js.map +1 -1
  30. package/_cjs/actions/public/verifyHash.js +2 -1
  31. package/_cjs/actions/public/verifyHash.js.map +1 -1
  32. package/_cjs/actions/public/waitForTransactionReceipt.js +6 -5
  33. package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  34. package/_cjs/actions/public/watchBlockNumber.js +2 -1
  35. package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
  36. package/_cjs/actions/public/watchBlocks.js +4 -3
  37. package/_cjs/actions/public/watchBlocks.js.map +1 -1
  38. package/_cjs/actions/public/watchContractEvent.js +6 -5
  39. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  40. package/_cjs/actions/public/watchEvent.js +6 -5
  41. package/_cjs/actions/public/watchEvent.js.map +1 -1
  42. package/_cjs/actions/public/watchPendingTransactions.js +4 -3
  43. package/_cjs/actions/public/watchPendingTransactions.js.map +1 -1
  44. package/_cjs/actions/wallet/getAddresses.js +2 -0
  45. package/_cjs/actions/wallet/getAddresses.js.map +1 -1
  46. package/_cjs/actions/wallet/prepareTransactionRequest.js +4 -3
  47. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  48. package/_cjs/actions/wallet/sendTransaction.js +5 -4
  49. package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
  50. package/_cjs/actions/wallet/signTransaction.js +2 -1
  51. package/_cjs/actions/wallet/signTransaction.js.map +1 -1
  52. package/_cjs/actions/wallet/writeContract.js +2 -1
  53. package/_cjs/actions/wallet/writeContract.js.map +1 -1
  54. package/_cjs/chains/definitions/arbitrumGoerli.js +2 -2
  55. package/_cjs/chains/definitions/arbitrumGoerli.js.map +1 -1
  56. package/_cjs/chains/definitions/modeTestnet.js +6 -0
  57. package/_cjs/chains/definitions/modeTestnet.js.map +1 -1
  58. package/_cjs/clients/createClient.js.map +1 -1
  59. package/_cjs/errors/node.js +11 -11
  60. package/_cjs/errors/node.js.map +1 -1
  61. package/_cjs/errors/rpc.js +18 -18
  62. package/_cjs/errors/rpc.js.map +1 -1
  63. package/_cjs/utils/getAction.js +8 -0
  64. package/_cjs/utils/getAction.js.map +1 -0
  65. package/_esm/actions/ens/getEnsAddress.js +2 -1
  66. package/_esm/actions/ens/getEnsAddress.js.map +1 -1
  67. package/_esm/actions/ens/getEnsAvatar.js +2 -1
  68. package/_esm/actions/ens/getEnsAvatar.js.map +1 -1
  69. package/_esm/actions/ens/getEnsName.js +2 -1
  70. package/_esm/actions/ens/getEnsName.js.map +1 -1
  71. package/_esm/actions/ens/getEnsResolver.js +2 -1
  72. package/_esm/actions/ens/getEnsResolver.js.map +1 -1
  73. package/_esm/actions/ens/getEnsText.js +2 -1
  74. package/_esm/actions/ens/getEnsText.js.map +1 -1
  75. package/_esm/actions/getContract.js +8 -7
  76. package/_esm/actions/getContract.js.map +1 -1
  77. package/_esm/actions/public/estimateContractGas.js +2 -1
  78. package/_esm/actions/public/estimateContractGas.js.map +1 -1
  79. package/_esm/actions/public/estimateFeesPerGas.js +3 -2
  80. package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
  81. package/_esm/actions/public/estimateMaxPriorityFeePerGas.js +4 -3
  82. package/_esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  83. package/_esm/actions/public/getContractEvents.js +2 -1
  84. package/_esm/actions/public/getContractEvents.js.map +1 -1
  85. package/_esm/actions/public/getTransactionConfirmations.js +3 -2
  86. package/_esm/actions/public/getTransactionConfirmations.js.map +1 -1
  87. package/_esm/actions/public/multicall.js +2 -1
  88. package/_esm/actions/public/multicall.js.map +1 -1
  89. package/_esm/actions/public/readContract.js +2 -1
  90. package/_esm/actions/public/readContract.js.map +1 -1
  91. package/_esm/actions/public/simulateContract.js +2 -1
  92. package/_esm/actions/public/simulateContract.js.map +1 -1
  93. package/_esm/actions/public/verifyHash.js +2 -1
  94. package/_esm/actions/public/verifyHash.js.map +1 -1
  95. package/_esm/actions/public/waitForTransactionReceipt.js +6 -5
  96. package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  97. package/_esm/actions/public/watchBlockNumber.js +2 -1
  98. package/_esm/actions/public/watchBlockNumber.js.map +1 -1
  99. package/_esm/actions/public/watchBlocks.js +4 -3
  100. package/_esm/actions/public/watchBlocks.js.map +1 -1
  101. package/_esm/actions/public/watchContractEvent.js +6 -5
  102. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  103. package/_esm/actions/public/watchEvent.js +6 -5
  104. package/_esm/actions/public/watchEvent.js.map +1 -1
  105. package/_esm/actions/public/watchPendingTransactions.js +4 -3
  106. package/_esm/actions/public/watchPendingTransactions.js.map +1 -1
  107. package/_esm/actions/wallet/getAddresses.js +2 -0
  108. package/_esm/actions/wallet/getAddresses.js.map +1 -1
  109. package/_esm/actions/wallet/prepareTransactionRequest.js +4 -3
  110. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  111. package/_esm/actions/wallet/sendTransaction.js +5 -4
  112. package/_esm/actions/wallet/sendTransaction.js.map +1 -1
  113. package/_esm/actions/wallet/signTransaction.js +2 -1
  114. package/_esm/actions/wallet/signTransaction.js.map +1 -1
  115. package/_esm/actions/wallet/writeContract.js +2 -1
  116. package/_esm/actions/wallet/writeContract.js.map +1 -1
  117. package/_esm/chains/definitions/arbitrumGoerli.js +2 -2
  118. package/_esm/chains/definitions/arbitrumGoerli.js.map +1 -1
  119. package/_esm/chains/definitions/modeTestnet.js +6 -0
  120. package/_esm/chains/definitions/modeTestnet.js.map +1 -1
  121. package/_esm/clients/createClient.js.map +1 -1
  122. package/_esm/errors/node.js +11 -22
  123. package/_esm/errors/node.js.map +1 -1
  124. package/_esm/errors/rpc.js +18 -36
  125. package/_esm/errors/rpc.js.map +1 -1
  126. package/_esm/utils/getAction.js +4 -0
  127. package/_esm/utils/getAction.js.map +1 -0
  128. package/_types/actions/ens/getEnsAddress.d.ts.map +1 -1
  129. package/_types/actions/ens/getEnsAvatar.d.ts.map +1 -1
  130. package/_types/actions/ens/getEnsName.d.ts.map +1 -1
  131. package/_types/actions/ens/getEnsResolver.d.ts.map +1 -1
  132. package/_types/actions/ens/getEnsText.d.ts.map +1 -1
  133. package/_types/actions/getContract.d.ts.map +1 -1
  134. package/_types/actions/public/estimateContractGas.d.ts.map +1 -1
  135. package/_types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
  136. package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
  137. package/_types/actions/public/getContractEvents.d.ts.map +1 -1
  138. package/_types/actions/public/getTransactionConfirmations.d.ts.map +1 -1
  139. package/_types/actions/public/multicall.d.ts.map +1 -1
  140. package/_types/actions/public/readContract.d.ts.map +1 -1
  141. package/_types/actions/public/simulateContract.d.ts.map +1 -1
  142. package/_types/actions/public/verifyHash.d.ts.map +1 -1
  143. package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  144. package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
  145. package/_types/actions/public/watchBlocks.d.ts.map +1 -1
  146. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  147. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  148. package/_types/actions/public/watchPendingTransactions.d.ts.map +1 -1
  149. package/_types/actions/wallet/getAddresses.d.ts.map +1 -1
  150. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  151. package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
  152. package/_types/actions/wallet/signTransaction.d.ts.map +1 -1
  153. package/_types/actions/wallet/writeContract.d.ts.map +1 -1
  154. package/_types/chains/definitions/arbitrumGoerli.d.ts +2 -2
  155. package/_types/chains/definitions/modeTestnet.d.ts +6 -0
  156. package/_types/chains/definitions/modeTestnet.d.ts.map +1 -1
  157. package/_types/clients/createClient.d.ts +6 -2
  158. package/_types/clients/createClient.d.ts.map +1 -1
  159. package/_types/utils/getAction.d.ts +3 -0
  160. package/_types/utils/getAction.d.ts.map +1 -0
  161. package/actions/ens/getEnsAddress.ts +5 -1
  162. package/actions/ens/getEnsAvatar.ts +5 -1
  163. package/actions/ens/getEnsName.ts +5 -1
  164. package/actions/ens/getEnsResolver.ts +5 -1
  165. package/actions/ens/getEnsText.ts +5 -1
  166. package/actions/getContract.ts +29 -7
  167. package/actions/public/estimateContractGas.ts +5 -1
  168. package/actions/public/estimateFeesPerGas.ts +4 -2
  169. package/actions/public/estimateMaxPriorityFeePerGas.ts +4 -3
  170. package/actions/public/getContractEvents.ts +5 -1
  171. package/actions/public/getTransactionConfirmations.ts +3 -2
  172. package/actions/public/multicall.ts +5 -1
  173. package/actions/public/readContract.ts +5 -1
  174. package/actions/public/simulateContract.ts +5 -1
  175. package/actions/public/verifyHash.ts +5 -1
  176. package/actions/public/waitForTransactionReceipt.ts +19 -6
  177. package/actions/public/watchBlockNumber.ts +5 -1
  178. package/actions/public/watchBlocks.ts +10 -3
  179. package/actions/public/watchContractEvent.ts +12 -5
  180. package/actions/public/watchEvent.ts +12 -5
  181. package/actions/public/watchPendingTransactions.ts +7 -3
  182. package/actions/wallet/getAddresses.ts +1 -0
  183. package/actions/wallet/prepareTransactionRequest.ts +10 -3
  184. package/actions/wallet/sendTransaction.ts +11 -4
  185. package/actions/wallet/signTransaction.ts +2 -1
  186. package/actions/wallet/writeContract.ts +5 -1
  187. package/chains/definitions/arbitrumGoerli.ts +2 -2
  188. package/chains/definitions/modeTestnet.ts +6 -0
  189. package/clients/createClient.ts +39 -2
  190. package/package.json +1 -1
  191. package/utils/getAction.ts +13 -0
@@ -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 createContractEventFilter(client, {
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 getFilterChanges(client, { filter })
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 getBlockNumber(client)
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 getContractEvents(client, {
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 uninstallFilter(client, { filter })
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 createEventFilter(client, {
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 getFilterChanges(client, { filter })
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 getBlockNumber(client)
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 getLogs(client, {
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 uninstallFilter(client, { filter })
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 createPendingTransactionFilter(client)
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 getFilterChanges(client, { filter })
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 uninstallFilter(client, { filter })
155
+ if (filter) await getAction(client, uninstallFilter)({ filter })
152
156
  unwatch()
153
157
  }
154
158
  })
@@ -44,6 +44,7 @@ export async function getAddresses<
44
44
  >(
45
45
  client: Client<Transport, TChain, TAccount>,
46
46
  ): Promise<GetAddressesReturnType> {
47
+ if (client.account?.type === 'local') return [client.account.address]
47
48
  const addresses = await client.request({ method: 'eth_accounts' })
48
49
  return addresses.map((address) => checksumAddress(address))
49
50
  }
@@ -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 getBlock(client, { blockTag: 'latest' })
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 getTransactionCount(client, {
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 estimateGas(client, {
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 getChainId(client)
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 prepareTransactionRequest(client, {
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 getChainId(client)
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 sendRawTransaction(client, {
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 getChainId(client)
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 sendTransaction(client, {
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,
@@ -26,8 +26,8 @@ export const arbitrumGoerli = /*#__PURE__*/ defineChain({
26
26
  },
27
27
  },
28
28
  blockExplorers: {
29
- etherscan: { name: 'Arbiscan', url: 'https://goerli.arbiscan.io/' },
30
- default: { name: 'Arbiscan', url: 'https://goerli.arbiscan.io/' },
29
+ etherscan: { name: 'Arbiscan', url: 'https://goerli.arbiscan.io' },
30
+ default: { name: 'Arbiscan', url: 'https://goerli.arbiscan.io' },
31
31
  },
32
32
  contracts: {
33
33
  multicall3: {
@@ -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
  })
@@ -1,8 +1,9 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
- import type { Account, JsonRpcAccount } from '../accounts/types.js'
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: <const client extends Extended>(
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "1.16.5",
4
+ "version": "1.17.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -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
+ }