viem 2.38.1 → 2.38.3

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 (104) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/_cjs/actions/wallet/sendRawTransactionSync.js +6 -2
  3. package/_cjs/actions/wallet/sendRawTransactionSync.js.map +1 -1
  4. package/_cjs/actions/wallet/sendTransactionSync.js +7 -2
  5. package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
  6. package/_cjs/actions/wallet/writeContractSync.js.map +1 -1
  7. package/_cjs/chains/definitions/kiiTestnet.js +27 -0
  8. package/_cjs/chains/definitions/kiiTestnet.js.map +1 -0
  9. package/_cjs/chains/definitions/linea.js +1 -0
  10. package/_cjs/chains/definitions/linea.js.map +1 -1
  11. package/_cjs/chains/definitions/plasma.js +1 -0
  12. package/_cjs/chains/definitions/plasma.js.map +1 -1
  13. package/_cjs/chains/definitions/polygon.js +1 -0
  14. package/_cjs/chains/definitions/polygon.js.map +1 -1
  15. package/_cjs/chains/definitions/scroll.js +1 -0
  16. package/_cjs/chains/definitions/scroll.js.map +1 -1
  17. package/_cjs/chains/definitions/surgeTestnet.js +23 -0
  18. package/_cjs/chains/definitions/surgeTestnet.js.map +1 -0
  19. package/_cjs/chains/definitions/swanProximaTestnet.js +1 -1
  20. package/_cjs/chains/definitions/swanProximaTestnet.js.map +1 -1
  21. package/_cjs/chains/definitions/vana.js +31 -0
  22. package/_cjs/chains/definitions/vana.js.map +1 -0
  23. package/_cjs/chains/definitions/vanaMoksha.js +32 -0
  24. package/_cjs/chains/definitions/vanaMoksha.js.map +1 -0
  25. package/_cjs/chains/index.js +15 -7
  26. package/_cjs/chains/index.js.map +1 -1
  27. package/_cjs/errors/transaction.js +23 -1
  28. package/_cjs/errors/transaction.js.map +1 -1
  29. package/_cjs/errors/version.js +1 -1
  30. package/_esm/actions/wallet/sendRawTransactionSync.js +6 -2
  31. package/_esm/actions/wallet/sendRawTransactionSync.js.map +1 -1
  32. package/_esm/actions/wallet/sendTransactionSync.js +7 -2
  33. package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
  34. package/_esm/actions/wallet/writeContractSync.js.map +1 -1
  35. package/_esm/chains/definitions/kiiTestnet.js +24 -0
  36. package/_esm/chains/definitions/kiiTestnet.js.map +1 -0
  37. package/_esm/chains/definitions/linea.js +1 -0
  38. package/_esm/chains/definitions/linea.js.map +1 -1
  39. package/_esm/chains/definitions/plasma.js +1 -0
  40. package/_esm/chains/definitions/plasma.js.map +1 -1
  41. package/_esm/chains/definitions/polygon.js +1 -0
  42. package/_esm/chains/definitions/polygon.js.map +1 -1
  43. package/_esm/chains/definitions/scroll.js +1 -0
  44. package/_esm/chains/definitions/scroll.js.map +1 -1
  45. package/_esm/chains/definitions/surgeTestnet.js +20 -0
  46. package/_esm/chains/definitions/surgeTestnet.js.map +1 -0
  47. package/_esm/chains/definitions/swanProximaTestnet.js +1 -1
  48. package/_esm/chains/definitions/swanProximaTestnet.js.map +1 -1
  49. package/_esm/chains/definitions/vana.js +28 -0
  50. package/_esm/chains/definitions/vana.js.map +1 -0
  51. package/_esm/chains/definitions/vanaMoksha.js +29 -0
  52. package/_esm/chains/definitions/vanaMoksha.js.map +1 -0
  53. package/_esm/chains/index.js +4 -0
  54. package/_esm/chains/index.js.map +1 -1
  55. package/_esm/errors/transaction.js +21 -0
  56. package/_esm/errors/transaction.js.map +1 -1
  57. package/_esm/errors/version.js +1 -1
  58. package/_types/actions/wallet/sendRawTransactionSync.d.ts +3 -1
  59. package/_types/actions/wallet/sendRawTransactionSync.d.ts.map +1 -1
  60. package/_types/actions/wallet/sendTransactionSync.d.ts +4 -1
  61. package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
  62. package/_types/actions/wallet/writeContractSync.d.ts +1 -1
  63. package/_types/actions/wallet/writeContractSync.d.ts.map +1 -1
  64. package/_types/chains/definitions/kiiTestnet.d.ts +40 -0
  65. package/_types/chains/definitions/kiiTestnet.d.ts.map +1 -0
  66. package/_types/chains/definitions/linea.d.ts +1 -1
  67. package/_types/chains/definitions/linea.d.ts.map +1 -1
  68. package/_types/chains/definitions/plasma.d.ts +1 -1
  69. package/_types/chains/definitions/plasma.d.ts.map +1 -1
  70. package/_types/chains/definitions/polygon.d.ts +1 -1
  71. package/_types/chains/definitions/polygon.d.ts.map +1 -1
  72. package/_types/chains/definitions/scroll.d.ts +1 -1
  73. package/_types/chains/definitions/scroll.d.ts.map +1 -1
  74. package/_types/chains/definitions/surgeTestnet.d.ts +40 -0
  75. package/_types/chains/definitions/surgeTestnet.d.ts.map +1 -0
  76. package/_types/chains/definitions/swanProximaTestnet.d.ts +1 -1
  77. package/_types/chains/definitions/vana.d.ts +37 -0
  78. package/_types/chains/definitions/vana.d.ts.map +1 -0
  79. package/_types/chains/definitions/vanaMoksha.d.ts +37 -0
  80. package/_types/chains/definitions/vanaMoksha.d.ts.map +1 -0
  81. package/_types/chains/index.d.ts +4 -0
  82. package/_types/chains/index.d.ts.map +1 -1
  83. package/_types/errors/transaction.d.ts +10 -1
  84. package/_types/errors/transaction.d.ts.map +1 -1
  85. package/_types/errors/version.d.ts +1 -1
  86. package/_types/types/calls.d.ts +2 -1
  87. package/_types/types/calls.d.ts.map +1 -1
  88. package/actions/wallet/sendRawTransactionSync.ts +13 -2
  89. package/actions/wallet/sendTransactionSync.ts +13 -1
  90. package/actions/wallet/writeContractSync.ts +4 -1
  91. package/chains/definitions/kiiTestnet.ts +24 -0
  92. package/chains/definitions/linea.ts +1 -0
  93. package/chains/definitions/plasma.ts +1 -0
  94. package/chains/definitions/polygon.ts +1 -0
  95. package/chains/definitions/scroll.ts +1 -0
  96. package/chains/definitions/surgeTestnet.ts +20 -0
  97. package/chains/definitions/swanProximaTestnet.ts +1 -1
  98. package/chains/definitions/vana.ts +28 -0
  99. package/chains/definitions/vanaMoksha.ts +29 -0
  100. package/chains/index.ts +4 -0
  101. package/errors/transaction.ts +27 -1
  102. package/errors/version.ts +1 -1
  103. package/package.json +1 -1
  104. package/types/calls.ts +2 -1
@@ -15,6 +15,10 @@ import {
15
15
  type AccountTypeNotSupportedErrorType,
16
16
  } from '../../errors/account.js'
17
17
  import { BaseError } from '../../errors/base.js'
18
+ import {
19
+ TransactionReceiptRevertedError,
20
+ type TransactionReceiptRevertedErrorType,
21
+ } from '../../errors/transaction.js'
18
22
  import type { ErrorType } from '../../errors/utils.js'
19
23
  import type { GetAccountParameter } from '../../types/account.js'
20
24
  import type {
@@ -91,6 +95,8 @@ export type SendTransactionSyncParameters<
91
95
  GetTransactionRequestKzgParameter<request> & {
92
96
  /** Polling interval (ms) to poll for the transaction receipt. @default client.pollingInterval */
93
97
  pollingInterval?: number | undefined
98
+ /** Whether to throw an error if the transaction was detected as reverted. @default true */
99
+ throwOnReceiptRevert?: boolean | undefined
94
100
  /** Timeout (ms) to wait for a response. @default Math.max(chain.blockTime * 3, 5_000) */
95
101
  timeout?: number | undefined
96
102
  }
@@ -111,6 +117,7 @@ export type SendTransactionSyncErrorType =
111
117
  | SendRawTransactionSyncErrorType
112
118
  | RecoverAuthorizationAddressErrorType
113
119
  | SignTransactionErrorType
120
+ | TransactionReceiptRevertedErrorType
114
121
  | RequestErrorType
115
122
  >
116
123
  | WaitForTransactionReceiptErrorType
@@ -184,6 +191,7 @@ export async function sendTransactionSync<
184
191
  maxPriorityFeePerGas,
185
192
  nonce,
186
193
  pollingInterval,
194
+ throwOnReceiptRevert,
187
195
  type,
188
196
  value,
189
197
  ...rest
@@ -314,7 +322,7 @@ export async function sendTransactionSync<
314
322
  }
315
323
  })()
316
324
 
317
- return getAction(
325
+ const receipt = await getAction(
318
326
  client,
319
327
  waitForTransactionReceipt,
320
328
  'waitForTransactionReceipt',
@@ -324,6 +332,9 @@ export async function sendTransactionSync<
324
332
  pollingInterval,
325
333
  timeout,
326
334
  })
335
+ if (throwOnReceiptRevert && receipt.status === 'reverted')
336
+ throw new TransactionReceiptRevertedError({ receipt })
337
+ return receipt
327
338
  }
328
339
 
329
340
  if (account?.type === 'local') {
@@ -363,6 +374,7 @@ export async function sendTransactionSync<
363
374
  'sendRawTransactionSync',
364
375
  )({
365
376
  serializedTransaction,
377
+ throwOnReceiptRevert,
366
378
  })) as never
367
379
  }
368
380
 
@@ -39,7 +39,10 @@ export type WriteContractSyncParameters<
39
39
  account,
40
40
  chainOverride
41
41
  > &
42
- Pick<SendTransactionSyncParameters<chain>, 'pollingInterval' | 'timeout'>
42
+ Pick<
43
+ SendTransactionSyncParameters<chain>,
44
+ 'pollingInterval' | 'throwOnReceiptRevert' | 'timeout'
45
+ >
43
46
 
44
47
  export type WriteContractSyncReturnType<
45
48
  chain extends Chain | undefined = Chain | undefined,
@@ -0,0 +1,24 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kiiTestnetOro = /*#__PURE__*/ defineChain({
4
+ id: 1336,
5
+ name: 'Kii Testnet Oro',
6
+ network: 'kii-testnet-oro',
7
+ nativeCurrency: {
8
+ name: 'Kii',
9
+ symbol: 'KII',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ['https://json-rpc.uno.sentry.testnet.v3.kiivalidator.com'],
15
+ },
16
+ },
17
+ blockExplorers: {
18
+ default: {
19
+ name: 'KiiExplorer',
20
+ url: 'https://explorer.kiichain.io/testnet',
21
+ },
22
+ },
23
+ testnet: true,
24
+ })
@@ -5,6 +5,7 @@ export const linea = /*#__PURE__*/ defineChain({
5
5
  ...chainConfig,
6
6
  id: 59_144,
7
7
  name: 'Linea Mainnet',
8
+ blockTime: 2000,
8
9
  nativeCurrency: { name: 'Linea Ether', symbol: 'ETH', decimals: 18 },
9
10
  rpcUrls: {
10
11
  default: {
@@ -3,6 +3,7 @@ import { defineChain } from '../../utils/chain/defineChain.js'
3
3
  export const plasma = /*#__PURE__*/ defineChain({
4
4
  id: 9745,
5
5
  name: 'Plasma',
6
+ blockTime: 1000,
6
7
  nativeCurrency: {
7
8
  name: 'Plasma',
8
9
  symbol: 'XPL',
@@ -3,6 +3,7 @@ import { defineChain } from '../../utils/chain/defineChain.js'
3
3
  export const polygon = /*#__PURE__*/ defineChain({
4
4
  id: 137,
5
5
  name: 'Polygon',
6
+ blockTime: 2000,
6
7
  nativeCurrency: { name: 'POL', symbol: 'POL', decimals: 18 },
7
8
  rpcUrls: {
8
9
  default: {
@@ -3,6 +3,7 @@ import { defineChain } from '../../utils/chain/defineChain.js'
3
3
  export const scroll = /*#__PURE__*/ defineChain({
4
4
  id: 534_352,
5
5
  name: 'Scroll',
6
+ blockTime: 3000,
6
7
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
7
8
  rpcUrls: {
8
9
  default: {
@@ -0,0 +1,20 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const surgeTestnet = /*#__PURE__*/ defineChain({
4
+ id: 763_375,
5
+ name: 'Surge Testnet',
6
+ nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://l2-rpc.hoodi.surge.wtf'],
10
+ webSocket: ['wss://l2-ws.hoodi.surge.wtf'],
11
+ },
12
+ },
13
+ blockExplorers: {
14
+ default: {
15
+ name: 'Surge Testnet Blockscout',
16
+ url: 'https://explorer.hoodi.surge.wtf',
17
+ },
18
+ },
19
+ testnet: true,
20
+ })
@@ -5,7 +5,7 @@ export const swanProximaTestnet = /*#__PURE__*/ defineChain({
5
5
  name: 'Swan Proxima Testnet',
6
6
  nativeCurrency: { name: 'Swan Ether', symbol: 'sETH', decimals: 18 },
7
7
  rpcUrls: {
8
- default: { http: ['https://rpc-proxima.swanchain.io '] },
8
+ default: { http: ['https://rpc-proxima.swanchain.io'] },
9
9
  },
10
10
  blockExplorers: {
11
11
  default: {
@@ -0,0 +1,28 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const vana = /*#__PURE__*/ defineChain({
4
+ id: 1480,
5
+ name: 'Vana',
6
+ blockTime: 6_000,
7
+ nativeCurrency: {
8
+ decimals: 18,
9
+ name: 'Vana',
10
+ symbol: 'VANA',
11
+ },
12
+ rpcUrls: {
13
+ default: { http: ['https://rpc.vana.org/'] },
14
+ },
15
+ blockExplorers: {
16
+ default: {
17
+ name: 'Vana Block Explorer',
18
+ url: 'https://vanascan.io',
19
+ apiUrl: 'https://vanascan.io/api',
20
+ },
21
+ },
22
+ contracts: {
23
+ multicall3: {
24
+ address: '0xD8d2dFca27E8797fd779F8547166A2d3B29d360E',
25
+ blockCreated: 716763,
26
+ },
27
+ },
28
+ })
@@ -0,0 +1,29 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const vanaMoksha = /*#__PURE__*/ defineChain({
4
+ id: 14800,
5
+ name: 'Vana Moksha Testnet',
6
+ blockTime: 6_000,
7
+ nativeCurrency: {
8
+ decimals: 18,
9
+ name: 'Vana',
10
+ symbol: 'VANA',
11
+ },
12
+ rpcUrls: {
13
+ default: { http: ['https://rpc.moksha.vana.org'] },
14
+ },
15
+ blockExplorers: {
16
+ default: {
17
+ name: 'Vana Moksha Testnet',
18
+ url: 'https://moksha.vanascan.io',
19
+ apiUrl: 'https://moksha.vanascan.io/api',
20
+ },
21
+ },
22
+ contracts: {
23
+ multicall3: {
24
+ address: '0xD8d2dFca27E8797fd779F8547166A2d3B29d360E',
25
+ blockCreated: 732283,
26
+ },
27
+ },
28
+ testnet: true,
29
+ })
package/chains/index.ts CHANGED
@@ -311,6 +311,7 @@ export { katana } from './definitions/katana.js'
311
311
  export { kava } from './definitions/kava.js'
312
312
  export { kavaTestnet } from './definitions/kavaTestnet.js'
313
313
  export { kcc } from './definitions/kcc.js'
314
+ export { kiiTestnetOro } from './definitions/kiiTestnet.js'
314
315
  export { kinto } from './definitions/kinto.js'
315
316
  /** @deprecated Use `kaia` instead. */
316
317
  export { klaytn } from './definitions/klaytn.js'
@@ -560,6 +561,7 @@ export { superlumio } from './definitions/superlumio.js'
560
561
  export { superposition } from './definitions/superposition.js'
561
562
  export { superseed } from './definitions/superseed.js'
562
563
  export { superseedSepolia } from './definitions/superseedSepolia.js'
564
+ export { surgeTestnet } from './definitions/surgeTestnet.js'
563
565
  export { swan } from './definitions/swan.js'
564
566
  export { swanProximaTestnet } from './definitions/swanProximaTestnet.js'
565
567
  export { swanSaturnTestnet } from './definitions/swanSaturnTestnet.js'
@@ -607,6 +609,8 @@ export { unique } from './definitions/unique.js'
607
609
  export { uniqueOpal } from './definitions/uniqueOpal.js'
608
610
  export { uniqueQuartz } from './definitions/uniqueQuartz.js'
609
611
  export { unreal } from './definitions/unreal.js'
612
+ export { vana } from './definitions/vana.js'
613
+ export { vanaMoksha } from './definitions/vanaMoksha.js'
610
614
  export { vanar } from './definitions/vanar.js'
611
615
  export { vechain } from './definitions/vechain.js'
612
616
  export { velas } from './definitions/velas.js'
@@ -3,7 +3,10 @@ import type { SendTransactionParameters } from '../actions/wallet/sendTransactio
3
3
  import type { BlockTag } from '../types/block.js'
4
4
  import type { Chain } from '../types/chain.js'
5
5
  import type { Hash, Hex } from '../types/misc.js'
6
- import type { TransactionType } from '../types/transaction.js'
6
+ import type {
7
+ TransactionReceipt,
8
+ TransactionType,
9
+ } from '../types/transaction.js'
7
10
  import { formatEther } from '../utils/unit/formatEther.js'
8
11
  import { formatGwei } from '../utils/unit/formatGwei.js'
9
12
 
@@ -245,6 +248,29 @@ export class TransactionReceiptNotFoundError extends BaseError {
245
248
  }
246
249
  }
247
250
 
251
+ export type TransactionReceiptRevertedErrorType =
252
+ TransactionReceiptRevertedError & {
253
+ name: 'TransactionReceiptRevertedError'
254
+ }
255
+ export class TransactionReceiptRevertedError extends BaseError {
256
+ receipt: TransactionReceipt
257
+
258
+ constructor({ receipt }: { receipt: TransactionReceipt }) {
259
+ super(`Transaction with hash "${receipt.transactionHash}" reverted.`, {
260
+ metaMessages: [
261
+ 'The receipt marked the transaction as "reverted". This could mean that the function on the contract you are trying to call threw an error.',
262
+ ' ',
263
+ 'You can attempt to extract the revert reason by:',
264
+ '- calling the `simulateContract` or `simulateCalls` Action with the `abi` and `functionName` of the contract',
265
+ '- using the `call` Action with raw `data`',
266
+ ],
267
+ name: 'TransactionReceiptRevertedError',
268
+ })
269
+
270
+ this.receipt = receipt
271
+ }
272
+ }
273
+
248
274
  export type WaitForTransactionReceiptTimeoutErrorType =
249
275
  WaitForTransactionReceiptTimeoutError & {
250
276
  name: 'WaitForTransactionReceiptTimeoutError'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.38.1'
1
+ export const version = '2.38.3'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.38.1",
4
+ "version": "2.38.3",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/calls.ts CHANGED
@@ -21,9 +21,10 @@ export type Call<
21
21
  GetMulticallContractParameters<call, AbiStateMutability>,
22
22
  'address'
23
23
  > & {
24
+ data?: Hex | undefined
25
+ dataSuffix?: Hex | undefined
24
26
  to: Address
25
27
  value?: bigint | undefined
26
- dataSuffix?: Hex | undefined
27
28
  },
28
29
  extraProperties
29
30
  >