viem 2.39.2 → 2.40.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 (91) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/_cjs/accounts/mnemonicToAccount.js +3 -3
  3. package/_cjs/accounts/mnemonicToAccount.js.map +1 -1
  4. package/_cjs/actions/index.js +5 -3
  5. package/_cjs/actions/index.js.map +1 -1
  6. package/_cjs/actions/public/fillTransaction.js +118 -0
  7. package/_cjs/actions/public/fillTransaction.js.map +1 -0
  8. package/_cjs/actions/wallet/prepareTransactionRequest.js +45 -11
  9. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  10. package/_cjs/chains/definitions/etherlinkShadownetTestnet.js +24 -0
  11. package/_cjs/chains/definitions/etherlinkShadownetTestnet.js.map +1 -0
  12. package/_cjs/chains/definitions/monad.js +39 -0
  13. package/_cjs/chains/definitions/monad.js.map +1 -0
  14. package/_cjs/chains/index.js +15 -11
  15. package/_cjs/chains/index.js.map +1 -1
  16. package/_cjs/clients/decorators/public.js +2 -0
  17. package/_cjs/clients/decorators/public.js.map +1 -1
  18. package/_cjs/clients/decorators/wallet.js +2 -0
  19. package/_cjs/clients/decorators/wallet.js.map +1 -1
  20. package/_cjs/errors/request.js +28 -0
  21. package/_cjs/errors/request.js.map +1 -1
  22. package/_cjs/errors/version.js +1 -1
  23. package/_cjs/index.js.map +1 -1
  24. package/_cjs/utils/transaction/assertRequest.js +1 -6
  25. package/_cjs/utils/transaction/assertRequest.js.map +1 -1
  26. package/_esm/accounts/mnemonicToAccount.js +3 -3
  27. package/_esm/accounts/mnemonicToAccount.js.map +1 -1
  28. package/_esm/actions/index.js +1 -0
  29. package/_esm/actions/index.js.map +1 -1
  30. package/_esm/actions/public/fillTransaction.js +145 -0
  31. package/_esm/actions/public/fillTransaction.js.map +1 -0
  32. package/_esm/actions/wallet/prepareTransactionRequest.js +49 -11
  33. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  34. package/_esm/chains/definitions/etherlinkShadownetTestnet.js +21 -0
  35. package/_esm/chains/definitions/etherlinkShadownetTestnet.js.map +1 -0
  36. package/_esm/chains/definitions/monad.js +36 -0
  37. package/_esm/chains/definitions/monad.js.map +1 -0
  38. package/_esm/chains/index.js +2 -0
  39. package/_esm/chains/index.js.map +1 -1
  40. package/_esm/clients/decorators/public.js +2 -0
  41. package/_esm/clients/decorators/public.js.map +1 -1
  42. package/_esm/clients/decorators/wallet.js +2 -0
  43. package/_esm/clients/decorators/wallet.js.map +1 -1
  44. package/_esm/errors/request.js +28 -0
  45. package/_esm/errors/request.js.map +1 -1
  46. package/_esm/errors/version.js +1 -1
  47. package/_esm/index.js.map +1 -1
  48. package/_esm/utils/transaction/assertRequest.js +1 -6
  49. package/_esm/utils/transaction/assertRequest.js.map +1 -1
  50. package/_types/accounts/mnemonicToAccount.d.ts +4 -2
  51. package/_types/accounts/mnemonicToAccount.d.ts.map +1 -1
  52. package/_types/actions/index.d.ts +1 -0
  53. package/_types/actions/index.d.ts.map +1 -1
  54. package/_types/actions/public/fillTransaction.d.ts +49 -0
  55. package/_types/actions/public/fillTransaction.d.ts.map +1 -0
  56. package/_types/actions/wallet/prepareTransactionRequest.d.ts +1 -1
  57. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  58. package/_types/chains/definitions/etherlinkShadownetTestnet.d.ts +39 -0
  59. package/_types/chains/definitions/etherlinkShadownetTestnet.d.ts.map +1 -0
  60. package/_types/chains/definitions/monad.d.ts +42 -0
  61. package/_types/chains/definitions/monad.d.ts.map +1 -0
  62. package/_types/chains/index.d.ts +2 -0
  63. package/_types/chains/index.d.ts.map +1 -1
  64. package/_types/clients/decorators/public.d.ts +25 -0
  65. package/_types/clients/decorators/public.d.ts.map +1 -1
  66. package/_types/clients/decorators/wallet.d.ts +25 -0
  67. package/_types/clients/decorators/wallet.d.ts.map +1 -1
  68. package/_types/errors/request.d.ts +4 -0
  69. package/_types/errors/request.d.ts.map +1 -1
  70. package/_types/errors/version.d.ts +1 -1
  71. package/_types/index.d.ts +1 -0
  72. package/_types/index.d.ts.map +1 -1
  73. package/_types/types/eip1193.d.ts +30 -0
  74. package/_types/types/eip1193.d.ts.map +1 -1
  75. package/_types/utils/transaction/assertRequest.d.ts +1 -1
  76. package/_types/utils/transaction/assertRequest.d.ts.map +1 -1
  77. package/accounts/mnemonicToAccount.ts +6 -4
  78. package/actions/index.ts +6 -0
  79. package/actions/public/fillTransaction.ts +250 -0
  80. package/actions/wallet/prepareTransactionRequest.ts +76 -10
  81. package/chains/definitions/etherlinkShadownetTestnet.ts +21 -0
  82. package/chains/definitions/monad.ts +36 -0
  83. package/chains/index.ts +2 -0
  84. package/clients/decorators/public.ts +40 -0
  85. package/clients/decorators/wallet.ts +40 -0
  86. package/errors/request.ts +8 -1
  87. package/errors/version.ts +1 -1
  88. package/index.ts +5 -0
  89. package/package.json +1 -1
  90. package/types/eip1193.ts +30 -0
  91. package/utils/transaction/assertRequest.ts +2 -17
@@ -0,0 +1,250 @@
1
+ import type { Address } from 'abitype'
2
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { BaseError } from '../../errors/base.js'
6
+ import { BaseFeeScalarError } from '../../errors/fee.js'
7
+ import type { ErrorType } from '../../errors/utils.js'
8
+ import type { Account, GetAccountParameter } from '../../types/account.js'
9
+ import type {
10
+ Chain,
11
+ ChainFeesFnParameters,
12
+ DeriveChain,
13
+ GetChainParameter,
14
+ } from '../../types/chain.js'
15
+ import type { Hex } from '../../types/misc.js'
16
+ import type { TransactionRequest } from '../../types/transaction.js'
17
+ import type { UnionOmit } from '../../types/utils.js'
18
+ import {
19
+ type GetTransactionErrorReturnType,
20
+ getTransactionError,
21
+ } from '../../utils/errors/getTransactionError.js'
22
+ import { extract } from '../../utils/formatters/extract.js'
23
+ import {
24
+ type FormattedTransaction,
25
+ formatTransaction,
26
+ } from '../../utils/formatters/transaction.js'
27
+ import {
28
+ type FormattedTransactionRequest,
29
+ formatTransactionRequest,
30
+ } from '../../utils/formatters/transactionRequest.js'
31
+ import { getAction } from '../../utils/getAction.js'
32
+ import type { NonceManager } from '../../utils/nonceManager.js'
33
+ import { assertRequest } from '../../utils/transaction/assertRequest.js'
34
+ import { getBlock } from './getBlock.js'
35
+ import { getChainId as getChainId_ } from './getChainId.js'
36
+
37
+ export type FillTransactionParameters<
38
+ chain extends Chain | undefined = Chain | undefined,
39
+ account extends Account | undefined = Account | undefined,
40
+ chainOverride extends Chain | undefined = Chain | undefined,
41
+ accountOverride extends Account | Address | undefined =
42
+ | Account
43
+ | Address
44
+ | undefined,
45
+ ///
46
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
47
+ > = UnionOmit<FormattedTransactionRequest<_derivedChain>, 'from'> &
48
+ GetAccountParameter<account, accountOverride, false, true> &
49
+ GetChainParameter<chain, chainOverride> & {
50
+ /**
51
+ * Nonce manager to use for the transaction request.
52
+ */
53
+ nonceManager?: NonceManager | undefined
54
+ }
55
+
56
+ export type FillTransactionReturnType<
57
+ chain extends Chain | undefined = Chain | undefined,
58
+ chainOverride extends Chain | undefined = Chain | undefined,
59
+ ///
60
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
61
+ > = {
62
+ raw: Hex
63
+ transaction: FormattedTransaction<_derivedChain>
64
+ }
65
+
66
+ export type FillTransactionErrorType =
67
+ | GetTransactionErrorReturnType<ErrorType>
68
+ | ErrorType
69
+
70
+ /**
71
+ * Fills a transaction request with the necessary fields to be signed over.
72
+ *
73
+ * - Docs: https://viem.sh/docs/actions/public/fillTransaction
74
+ *
75
+ * @param client - Client to use
76
+ * @param parameters - {@link FillTransactionParameters}
77
+ * @returns The filled transaction. {@link FillTransactionReturnType}
78
+ *
79
+ * @example
80
+ * import { createPublicClient, http } from 'viem'
81
+ * import { mainnet } from 'viem/chains'
82
+ * import { fillTransaction } from 'viem/public'
83
+ *
84
+ * const client = createPublicClient({
85
+ * chain: mainnet,
86
+ * transport: http(),
87
+ * })
88
+ * const result = await fillTransaction(client, {
89
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
90
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
91
+ * value: parseEther('1'),
92
+ * })
93
+ */
94
+ export async function fillTransaction<
95
+ chain extends Chain | undefined,
96
+ account extends Account | undefined,
97
+ chainOverride extends Chain | undefined = undefined,
98
+ accountOverride extends Account | Address | undefined = undefined,
99
+ >(
100
+ client: Client<Transport, chain, account>,
101
+ parameters: FillTransactionParameters<
102
+ chain,
103
+ account,
104
+ chainOverride,
105
+ accountOverride
106
+ >,
107
+ ): Promise<FillTransactionReturnType<chain, chainOverride>> {
108
+ const {
109
+ account = client.account,
110
+ accessList,
111
+ authorizationList,
112
+ chain = client.chain,
113
+ blobVersionedHashes,
114
+ blobs,
115
+ data,
116
+ gas,
117
+ gasPrice,
118
+ maxFeePerBlobGas,
119
+ maxFeePerGas,
120
+ maxPriorityFeePerGas,
121
+ nonce: nonce_,
122
+ nonceManager,
123
+ to,
124
+ type,
125
+ value,
126
+ ...rest
127
+ } = parameters
128
+
129
+ const nonce = await (async () => {
130
+ if (!account) return nonce_
131
+ if (!nonceManager) return nonce_
132
+ const account_ = parseAccount(account)
133
+ const chainId = chain
134
+ ? chain.id
135
+ : await getAction(client, getChainId_, 'getChainId')({})
136
+ return await nonceManager.consume({
137
+ address: account_.address,
138
+ chainId,
139
+ client,
140
+ })
141
+ })()
142
+
143
+ assertRequest(parameters)
144
+
145
+ const chainFormat = chain?.formatters?.transactionRequest?.format
146
+ const format = chainFormat || formatTransactionRequest
147
+
148
+ const request = format(
149
+ {
150
+ // Pick out extra data that might exist on the chain's transaction request type.
151
+ ...extract(rest, { format: chainFormat }),
152
+ account: account ? parseAccount(account) : undefined,
153
+ accessList,
154
+ authorizationList,
155
+ blobs,
156
+ blobVersionedHashes,
157
+ data,
158
+ gas,
159
+ gasPrice,
160
+ maxFeePerBlobGas,
161
+ maxFeePerGas,
162
+ maxPriorityFeePerGas,
163
+ nonce,
164
+ to,
165
+ type,
166
+ value,
167
+ } as TransactionRequest,
168
+ 'fillTransaction',
169
+ )
170
+
171
+ try {
172
+ const response = await client.request({
173
+ method: 'eth_fillTransaction',
174
+ params: [request],
175
+ })
176
+ const format = chain?.formatters?.transaction?.format || formatTransaction
177
+
178
+ const transaction = format(response.tx)
179
+
180
+ // Remove unnecessary fields.
181
+ delete transaction.blockHash
182
+ delete transaction.blockNumber
183
+ delete transaction.r
184
+ delete transaction.s
185
+ delete transaction.transactionIndex
186
+ delete transaction.v
187
+ delete transaction.yParity
188
+
189
+ // Rewrite fields.
190
+ transaction.data = transaction.input
191
+
192
+ // Preference supplied fees (some nodes do not take these preferences).
193
+ if (transaction.gas) transaction.gas = parameters.gas ?? transaction.gas
194
+ if (transaction.gasPrice)
195
+ transaction.gasPrice = parameters.gasPrice ?? transaction.gasPrice
196
+ if (transaction.maxFeePerBlobGas)
197
+ transaction.maxFeePerBlobGas =
198
+ parameters.maxFeePerBlobGas ?? transaction.maxFeePerBlobGas
199
+ if (transaction.maxFeePerGas)
200
+ transaction.maxFeePerGas =
201
+ parameters.maxFeePerGas ?? transaction.maxFeePerGas
202
+ if (transaction.maxPriorityFeePerGas)
203
+ transaction.maxPriorityFeePerGas =
204
+ parameters.maxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas
205
+ if (transaction.nonce)
206
+ transaction.nonce = parameters.nonce ?? transaction.nonce
207
+
208
+ // Build fee multiplier function.
209
+ const feeMultiplier = await (async () => {
210
+ if (typeof chain?.fees?.baseFeeMultiplier === 'function') {
211
+ const block = await getAction(client, getBlock, 'getBlock')({})
212
+ return chain.fees.baseFeeMultiplier({
213
+ block,
214
+ client,
215
+ request: parameters,
216
+ } as ChainFeesFnParameters)
217
+ }
218
+ return chain?.fees?.baseFeeMultiplier ?? 1.2
219
+ })()
220
+ if (feeMultiplier < 1) throw new BaseFeeScalarError()
221
+
222
+ const decimals = feeMultiplier.toString().split('.')[1]?.length ?? 0
223
+ const denominator = 10 ** decimals
224
+ const multiplyFee = (base: bigint) =>
225
+ (base * BigInt(Math.ceil(feeMultiplier * denominator))) /
226
+ BigInt(denominator)
227
+
228
+ // Apply fee multiplier.
229
+ if (transaction.maxFeePerGas && !parameters.maxFeePerGas)
230
+ transaction.maxFeePerGas = multiplyFee(transaction.maxFeePerGas)
231
+ if (transaction.gasPrice && !parameters.gasPrice)
232
+ transaction.gasPrice = multiplyFee(transaction.gasPrice)
233
+
234
+ return {
235
+ raw: response.raw,
236
+ transaction: {
237
+ from: request.from,
238
+ ...transaction,
239
+ },
240
+ }
241
+ } catch (err) {
242
+ throw getTransactionError(
243
+ err as BaseError,
244
+ {
245
+ ...parameters,
246
+ chain: client.chain,
247
+ } as never,
248
+ )
249
+ }
250
+ }
@@ -24,6 +24,7 @@ import {
24
24
  import type { Client } from '../../clients/createClient.js'
25
25
  import type { Transport } from '../../clients/transports/createTransport.js'
26
26
  import type { AccountNotFoundErrorType } from '../../errors/account.js'
27
+ import type { BaseError } from '../../errors/base.js'
27
28
  import {
28
29
  Eip1559FeesNotSupportedError,
29
30
  MaxFeePerGasTooLowError,
@@ -58,6 +59,7 @@ import { commitmentsToVersionedHashes } from '../../utils/blob/commitmentsToVers
58
59
  import { toBlobSidecars } from '../../utils/blob/toBlobSidecars.js'
59
60
  import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
60
61
  import { getAction } from '../../utils/getAction.js'
62
+ import { LruMap } from '../../utils/lru.js'
61
63
  import type { NonceManager } from '../../utils/nonceManager.js'
62
64
  import {
63
65
  type AssertRequestErrorType,
@@ -68,6 +70,10 @@ import {
68
70
  type GetTransactionType,
69
71
  getTransactionType,
70
72
  } from '../../utils/transaction/getTransactionType.js'
73
+ import {
74
+ type FillTransactionParameters,
75
+ fillTransaction,
76
+ } from '../public/fillTransaction.js'
71
77
  import { getChainId as getChainId_ } from '../public/getChainId.js'
72
78
 
73
79
  export const defaultParameters = [
@@ -82,6 +88,8 @@ export const defaultParameters = [
82
88
  /** @internal */
83
89
  export const eip1559NetworkCache = /*#__PURE__*/ new Map<string, boolean>()
84
90
 
91
+ const supportsFillTransaction = /*#__PURE__*/ new LruMap<boolean>(128)
92
+
85
93
  export type PrepareTransactionRequestParameterType =
86
94
  | 'blobVersionedHashes'
87
95
  | 'chainId'
@@ -241,7 +249,7 @@ export async function prepareTransactionRequest<
241
249
  chainOverride extends Chain | undefined = undefined,
242
250
  >(
243
251
  client: Client<Transport, chain, account>,
244
- args: PrepareTransactionRequestParameters<
252
+ args_: PrepareTransactionRequestParameters<
245
253
  chain,
246
254
  account,
247
255
  chainOverride,
@@ -257,6 +265,60 @@ export async function prepareTransactionRequest<
257
265
  request
258
266
  >
259
267
  > {
268
+ const attemptFill =
269
+ // Do not attempt if `eth_fillTransaction` is not supported.
270
+ supportsFillTransaction.get(client.uid) !== false &&
271
+ // Should attempt `eth_fillTransaction` if "fees" or "gas" are required to be populated,
272
+ // otherwise, can just use the other individual calls.
273
+ ['fees', 'gas'].some((parameter) =>
274
+ args_.parameters?.includes(
275
+ parameter as PrepareTransactionRequestParameterType,
276
+ ),
277
+ )
278
+
279
+ const fillResult = attemptFill
280
+ ? await getAction(
281
+ client,
282
+ fillTransaction,
283
+ 'fillTransaction',
284
+ )(args_ as FillTransactionParameters)
285
+ .then((result) => {
286
+ const {
287
+ chainId,
288
+ from,
289
+ gas,
290
+ gasPrice,
291
+ nonce,
292
+ maxFeePerBlobGas,
293
+ maxFeePerGas,
294
+ maxPriorityFeePerGas,
295
+ type,
296
+ } = result.transaction
297
+ supportsFillTransaction.set(client.uid, true)
298
+ return {
299
+ ...args_,
300
+ chainId,
301
+ from,
302
+ gas,
303
+ gasPrice,
304
+ nonce,
305
+ maxFeePerBlobGas,
306
+ maxFeePerGas,
307
+ maxPriorityFeePerGas,
308
+ type,
309
+ }
310
+ })
311
+ .catch((e) => {
312
+ const error = e as BaseError & { cause: BaseError }
313
+ if (
314
+ error.cause.name === 'MethodNotFoundRpcError' ||
315
+ error.cause.name === 'MethodNotSupportedRpcError'
316
+ )
317
+ supportsFillTransaction.set(client.uid, false)
318
+ return args_
319
+ })
320
+ : args_
321
+
260
322
  const {
261
323
  account: account_ = client.account,
262
324
  blobs,
@@ -267,10 +329,14 @@ export async function prepareTransactionRequest<
267
329
  nonceManager,
268
330
  parameters = defaultParameters,
269
331
  type,
270
- } = args
332
+ } = fillResult
333
+
271
334
  const account = account_ ? parseAccount(account_) : account_
272
335
 
273
- const request = { ...args, ...(account ? { from: account?.address } : {}) }
336
+ const request = {
337
+ ...fillResult,
338
+ ...(account ? { from: account?.address } : {}),
339
+ }
274
340
 
275
341
  let block: Block | undefined
276
342
  async function getBlock(): Promise<Block> {
@@ -287,7 +353,7 @@ export async function prepareTransactionRequest<
287
353
  async function getChainId(): Promise<number> {
288
354
  if (chainId) return chainId
289
355
  if (chain) return chain.id
290
- if (typeof args.chainId !== 'undefined') return args.chainId
356
+ if (typeof request.chainId !== 'undefined') return request.chainId
291
357
  const chainId_ = await getAction(client, getChainId_, 'getChainId')({})
292
358
  chainId = chainId_
293
359
  return chainId
@@ -379,9 +445,9 @@ export async function prepareTransactionRequest<
379
445
  })
380
446
 
381
447
  if (
382
- typeof args.maxPriorityFeePerGas === 'undefined' &&
383
- args.maxFeePerGas &&
384
- args.maxFeePerGas < maxPriorityFeePerGas
448
+ typeof request.maxPriorityFeePerGas === 'undefined' &&
449
+ request.maxFeePerGas &&
450
+ request.maxFeePerGas < maxPriorityFeePerGas
385
451
  )
386
452
  throw new MaxFeePerGasTooLowError({
387
453
  maxPriorityFeePerGas,
@@ -393,12 +459,12 @@ export async function prepareTransactionRequest<
393
459
  } else {
394
460
  // Legacy fees
395
461
  if (
396
- typeof args.maxFeePerGas !== 'undefined' ||
397
- typeof args.maxPriorityFeePerGas !== 'undefined'
462
+ typeof request.maxFeePerGas !== 'undefined' ||
463
+ typeof request.maxPriorityFeePerGas !== 'undefined'
398
464
  )
399
465
  throw new Eip1559FeesNotSupportedError()
400
466
 
401
- if (typeof args.gasPrice === 'undefined') {
467
+ if (typeof request.gasPrice === 'undefined') {
402
468
  const block = await getBlock()
403
469
  const { gasPrice: gasPrice_ } = await internal_estimateFeesPerGas(
404
470
  client,
@@ -0,0 +1,21 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const etherlinkShadownetTestnet = /*#__PURE__*/ defineChain({
4
+ id: 127823,
5
+ name: 'Etherlink Shadownet Testnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'tez',
9
+ symbol: 'XTZ',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://node.shadownet.etherlink.com'] },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'Etherlink Shadownet Testnet Explorer',
17
+ url: 'https://shadownet.explorer.etherlink.com',
18
+ },
19
+ },
20
+ testnet: true,
21
+ })
@@ -0,0 +1,36 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const monad = /*#__PURE__*/ defineChain({
4
+ id: 143,
5
+ name: 'Monad',
6
+ blockTime: 400,
7
+ nativeCurrency: {
8
+ name: 'Monad',
9
+ symbol: 'MON',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ['https://rpc.monad.xyz', 'https://rpc1.monad.xyz'],
15
+ webSocket: ['wss://rpc.monad.xyz', 'wss://rpc1.monad.xyz'],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: 'MonadVision',
21
+ url: 'https://monadvision.com',
22
+ },
23
+ monadscan: {
24
+ name: 'Monadscan',
25
+ url: 'https://monadscan.com',
26
+ apiUrl: 'https://api.monadscan.com/api',
27
+ },
28
+ },
29
+ testnet: false,
30
+ contracts: {
31
+ multicall3: {
32
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
33
+ blockCreated: 9248132,
34
+ },
35
+ },
36
+ })
package/chains/index.ts CHANGED
@@ -180,6 +180,7 @@ export { eos } from './definitions/eos.js'
180
180
  export { eosTestnet } from './definitions/eosTestnet.js'
181
181
  export { eteria } from './definitions/eteria.js'
182
182
  export { etherlink } from './definitions/etherlink.js'
183
+ export { etherlinkShadownetTestnet } from './definitions/etherlinkShadownetTestnet.js'
183
184
  export { etherlinkTestnet } from './definitions/etherlinkTestnet.js'
184
185
  export { ethernity } from './definitions/ethernity.js'
185
186
  export { etp } from './definitions/etp.js'
@@ -392,6 +393,7 @@ export { mintSepoliaTestnet } from './definitions/mintSepoliaTestnet.js'
392
393
  export { mitosisTestnet } from './definitions/mitosisTestnet.js'
393
394
  export { mode } from './definitions/mode.js'
394
395
  export { modeTestnet } from './definitions/modeTestnet.js'
396
+ export { monad } from './definitions/monad.js'
395
397
  export { monadTestnet } from './definitions/monadTestnet.js'
396
398
  export { moonbaseAlpha } from './definitions/moonbaseAlpha.js'
397
399
  export { moonbeam } from './definitions/moonbeam.js'
@@ -73,6 +73,11 @@ import {
73
73
  type EstimateMaxPriorityFeePerGasReturnType,
74
74
  estimateMaxPriorityFeePerGas,
75
75
  } from '../../actions/public/estimateMaxPriorityFeePerGas.js'
76
+ import {
77
+ type FillTransactionParameters,
78
+ type FillTransactionReturnType,
79
+ fillTransaction,
80
+ } from '../../actions/public/fillTransaction.js'
76
81
  import {
77
82
  type GetBalanceParameters,
78
83
  type GetBalanceReturnType,
@@ -543,6 +548,40 @@ export type PublicActions<
543
548
  estimateGas: (
544
549
  args: EstimateGasParameters<chain>,
545
550
  ) => Promise<EstimateGasReturnType>
551
+ /**
552
+ * Fills a transaction request with the necessary fields to be signed over.
553
+ *
554
+ * - Docs: https://viem.sh/docs/actions/public/fillTransaction
555
+ *
556
+ * @param client - Client to use
557
+ * @param parameters - {@link FillTransactionParameters}
558
+ * @returns The filled transaction. {@link FillTransactionReturnType}
559
+ *
560
+ * @example
561
+ * import { createPublicClient, http } from 'viem'
562
+ * import { mainnet } from 'viem/chains'
563
+ *
564
+ * const client = createPublicClient({
565
+ * chain: mainnet,
566
+ * transport: http(),
567
+ * })
568
+ * const result = await client.fillTransaction({
569
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
570
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
571
+ * value: parseEther('1'),
572
+ * })
573
+ */
574
+ fillTransaction: <
575
+ chainOverride extends Chain | undefined = undefined,
576
+ accountOverride extends Account | Address | undefined = undefined,
577
+ >(
578
+ args: FillTransactionParameters<
579
+ chain,
580
+ account,
581
+ chainOverride,
582
+ accountOverride
583
+ >,
584
+ ) => Promise<FillTransactionReturnType<chain, chainOverride>>
546
585
  /**
547
586
  * Returns the balance of an address in wei.
548
587
  *
@@ -2039,6 +2078,7 @@ export function publicActions<
2039
2078
  getProof: (args) => getProof(client, args),
2040
2079
  estimateMaxPriorityFeePerGas: (args) =>
2041
2080
  estimateMaxPriorityFeePerGas(client, args),
2081
+ fillTransaction: (args) => fillTransaction(client, args),
2042
2082
  getStorageAt: (args) => getStorageAt(client, args),
2043
2083
  getTransaction: (args) => getTransaction(client, args),
2044
2084
  getTransactionConfirmations: (args) =>
@@ -1,6 +1,11 @@
1
1
  import type { Abi, Address, TypedData } from 'abitype'
2
2
 
3
3
  import type { Account } from '../../accounts/types.js'
4
+ import {
5
+ type FillTransactionParameters,
6
+ type FillTransactionReturnType,
7
+ fillTransaction,
8
+ } from '../../actions/public/fillTransaction.js'
4
9
  import {
5
10
  type GetChainIdReturnType,
6
11
  getChainId,
@@ -195,6 +200,40 @@ export type WalletActions<
195
200
  >(
196
201
  args: DeployContractParameters<abi, chain, account, chainOverride>,
197
202
  ) => Promise<DeployContractReturnType>
203
+ /**
204
+ * Fills a transaction request with the necessary fields to be signed over.
205
+ *
206
+ * - Docs: https://viem.sh/docs/actions/public/fillTransaction
207
+ *
208
+ * @param client - Client to use
209
+ * @param parameters - {@link FillTransactionParameters}
210
+ * @returns The filled transaction. {@link FillTransactionReturnType}
211
+ *
212
+ * @example
213
+ * import { createWalletClient, custom } from 'viem'
214
+ * import { mainnet } from 'viem/chains'
215
+ *
216
+ * const client = createWalletClient({
217
+ * chain: mainnet,
218
+ * transport: custom(window.ethereum),
219
+ * })
220
+ * const result = await client.fillTransaction({
221
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
222
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
223
+ * value: parseEther('1'),
224
+ * })
225
+ */
226
+ fillTransaction: <
227
+ chainOverride extends Chain | undefined = undefined,
228
+ accountOverride extends Account | Address | undefined = undefined,
229
+ >(
230
+ args: FillTransactionParameters<
231
+ chain,
232
+ account,
233
+ chainOverride,
234
+ accountOverride
235
+ >,
236
+ ) => Promise<FillTransactionReturnType<chain, chainOverride>>
198
237
  /**
199
238
  * Returns a list of account addresses owned by the wallet or client.
200
239
  *
@@ -1146,6 +1185,7 @@ export function walletActions<
1146
1185
  return {
1147
1186
  addChain: (args) => addChain(client, args),
1148
1187
  deployContract: (args) => deployContract(client, args),
1188
+ fillTransaction: (args) => fillTransaction(client, args),
1149
1189
  getAddresses: () => getAddresses(client),
1150
1190
  getCallsStatus: (args) => getCallsStatus(client, args),
1151
1191
  getCapabilities: (args) => getCapabilities(client, args),
package/errors/request.ts CHANGED
@@ -48,6 +48,7 @@ export type WebSocketRequestErrorType = WebSocketRequestError & {
48
48
  name: 'WebSocketRequestError'
49
49
  }
50
50
  export class WebSocketRequestError extends BaseError {
51
+ url: string
51
52
  constructor({
52
53
  body,
53
54
  cause,
@@ -68,6 +69,7 @@ export class WebSocketRequestError extends BaseError {
68
69
  ].filter(Boolean) as string[],
69
70
  name: 'WebSocketRequestError',
70
71
  })
72
+ this.url = url
71
73
  }
72
74
  }
73
75
 
@@ -77,7 +79,7 @@ export type RpcRequestErrorType = RpcRequestError & {
77
79
  export class RpcRequestError extends BaseError {
78
80
  code: number
79
81
  data?: unknown
80
-
82
+ url: string
81
83
  constructor({
82
84
  body,
83
85
  error,
@@ -95,6 +97,7 @@ export class RpcRequestError extends BaseError {
95
97
  })
96
98
  this.code = error.code
97
99
  this.data = error.data
100
+ this.url = url
98
101
  }
99
102
  }
100
103
 
@@ -102,6 +105,7 @@ export type SocketClosedErrorType = SocketClosedError & {
102
105
  name: 'SocketClosedError'
103
106
  }
104
107
  export class SocketClosedError extends BaseError {
108
+ url: string | undefined
105
109
  constructor({
106
110
  url,
107
111
  }: {
@@ -111,6 +115,7 @@ export class SocketClosedError extends BaseError {
111
115
  metaMessages: [url && `URL: ${getUrl(url)}`].filter(Boolean) as string[],
112
116
  name: 'SocketClosedError',
113
117
  })
118
+ this.url = url
114
119
  }
115
120
  }
116
121
 
@@ -118,6 +123,7 @@ export type TimeoutErrorType = TimeoutError & {
118
123
  name: 'TimeoutError'
119
124
  }
120
125
  export class TimeoutError extends BaseError {
126
+ url: string
121
127
  constructor({
122
128
  body,
123
129
  url,
@@ -130,5 +136,6 @@ export class TimeoutError extends BaseError {
130
136
  metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`],
131
137
  name: 'TimeoutError',
132
138
  })
139
+ this.url = url
133
140
  }
134
141
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.39.2'
1
+ export const version = '2.40.0'
package/index.ts CHANGED
@@ -135,6 +135,11 @@ export type {
135
135
  EstimateMaxPriorityFeePerGasParameters,
136
136
  EstimateMaxPriorityFeePerGasReturnType,
137
137
  } from './actions/public/estimateMaxPriorityFeePerGas.js'
138
+ export type {
139
+ FillTransactionErrorType,
140
+ FillTransactionParameters,
141
+ FillTransactionReturnType,
142
+ } from './actions/public/fillTransaction.js'
138
143
  export type {
139
144
  GetBalanceErrorType,
140
145
  GetBalanceParameters,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.39.2",
4
+ "version": "2.40.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",