viem 2.57.18 → 2.57.20

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 (222) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/_cjs/accounts/index.js +2 -1
  3. package/_cjs/accounts/index.js.map +1 -1
  4. package/_cjs/accounts/utils/publicKeyToAddress.js +15 -0
  5. package/_cjs/accounts/utils/publicKeyToAddress.js.map +1 -1
  6. package/_cjs/actions/ens/getEnsText.js.map +1 -1
  7. package/_cjs/actions/public/call.js +19 -3
  8. package/_cjs/actions/public/call.js.map +1 -1
  9. package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js +1 -1
  10. package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  11. package/_cjs/actions/public/getDelegation.js +2 -1
  12. package/_cjs/actions/public/getDelegation.js.map +1 -1
  13. package/_cjs/actions/public/getFeeHistory.js.map +1 -1
  14. package/_cjs/actions/token/internal.js +2 -10
  15. package/_cjs/actions/token/internal.js.map +1 -1
  16. package/_cjs/actions/wallet/deployContract.js +2 -1
  17. package/_cjs/actions/wallet/deployContract.js.map +1 -1
  18. package/_cjs/actions/wallet/prepareTransactionRequest.js +99 -76
  19. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  20. package/_cjs/actions/wallet/sendCalls.js +2 -1
  21. package/_cjs/actions/wallet/sendCalls.js.map +1 -1
  22. package/_cjs/actions/wallet/signAuthorization.js +2 -1
  23. package/_cjs/actions/wallet/signAuthorization.js.map +1 -1
  24. package/_cjs/chains/definitions/darwinia.js +1 -1
  25. package/_cjs/chains/definitions/darwinia.js.map +1 -1
  26. package/_cjs/chains/definitions/flowMainnet.js +1 -1
  27. package/_cjs/chains/definitions/flowMainnet.js.map +1 -1
  28. package/_cjs/chains/definitions/kinetiqElysium.js +30 -0
  29. package/_cjs/chains/definitions/kinetiqElysium.js.map +1 -0
  30. package/_cjs/chains/definitions/kinetiqElysiumTestnet.js +31 -0
  31. package/_cjs/chains/definitions/kinetiqElysiumTestnet.js.map +1 -0
  32. package/_cjs/chains/index.js +14 -9
  33. package/_cjs/chains/index.js.map +1 -1
  34. package/_cjs/errors/encoding.js +9 -1
  35. package/_cjs/errors/encoding.js.map +1 -1
  36. package/_cjs/errors/typedData.js +2 -0
  37. package/_cjs/errors/typedData.js.map +1 -1
  38. package/_cjs/errors/version.js +1 -1
  39. package/_cjs/index.js +6 -5
  40. package/_cjs/index.js.map +1 -1
  41. package/_cjs/tempo/actions/accounts.js +14 -4
  42. package/_cjs/tempo/actions/accounts.js.map +1 -1
  43. package/_cjs/tempo/chainConfig.js +23 -1
  44. package/_cjs/tempo/chainConfig.js.map +1 -1
  45. package/_cjs/tempo/internal/relay.js +2 -2
  46. package/_cjs/tempo/internal/relay.js.map +1 -1
  47. package/_cjs/tempo/internal/utils.js +2 -10
  48. package/_cjs/tempo/internal/utils.js.map +1 -1
  49. package/_cjs/tokens/defineToken.js +1 -1
  50. package/_cjs/tokens/defineToken.js.map +1 -1
  51. package/_cjs/tokens/definitions/ousd.js +1 -0
  52. package/_cjs/tokens/definitions/ousd.js.map +1 -1
  53. package/_cjs/utils/address/getAddress.js +7 -6
  54. package/_cjs/utils/address/getAddress.js.map +1 -1
  55. package/_cjs/utils/address/isAddress.js +8 -12
  56. package/_cjs/utils/address/isAddress.js.map +1 -1
  57. package/_cjs/utils/encoding/fromRlp.js +33 -8
  58. package/_cjs/utils/encoding/fromRlp.js.map +1 -1
  59. package/_cjs/utils/index.js +5 -4
  60. package/_cjs/utils/index.js.map +1 -1
  61. package/_cjs/utils/promise/createBatchScheduler.js +7 -2
  62. package/_cjs/utils/promise/createBatchScheduler.js.map +1 -1
  63. package/_cjs/utils/typedData.js +5 -9
  64. package/_cjs/utils/typedData.js.map +1 -1
  65. package/_esm/accounts/index.js +1 -1
  66. package/_esm/accounts/index.js.map +1 -1
  67. package/_esm/accounts/utils/publicKeyToAddress.js +20 -1
  68. package/_esm/accounts/utils/publicKeyToAddress.js.map +1 -1
  69. package/_esm/actions/ens/getEnsText.js.map +1 -1
  70. package/_esm/actions/public/call.js +19 -3
  71. package/_esm/actions/public/call.js.map +1 -1
  72. package/_esm/actions/public/estimateMaxPriorityFeePerGas.js +1 -1
  73. package/_esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  74. package/_esm/actions/public/getDelegation.js +2 -1
  75. package/_esm/actions/public/getDelegation.js.map +1 -1
  76. package/_esm/actions/public/getFeeHistory.js.map +1 -1
  77. package/_esm/actions/token/internal.js +2 -10
  78. package/_esm/actions/token/internal.js.map +1 -1
  79. package/_esm/actions/wallet/deployContract.js +2 -1
  80. package/_esm/actions/wallet/deployContract.js.map +1 -1
  81. package/_esm/actions/wallet/prepareTransactionRequest.js +111 -79
  82. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  83. package/_esm/actions/wallet/sendCalls.js +2 -1
  84. package/_esm/actions/wallet/sendCalls.js.map +1 -1
  85. package/_esm/actions/wallet/signAuthorization.js +2 -1
  86. package/_esm/actions/wallet/signAuthorization.js.map +1 -1
  87. package/_esm/chains/definitions/darwinia.js +1 -1
  88. package/_esm/chains/definitions/darwinia.js.map +1 -1
  89. package/_esm/chains/definitions/flowMainnet.js +1 -1
  90. package/_esm/chains/definitions/flowMainnet.js.map +1 -1
  91. package/_esm/chains/definitions/kinetiqElysium.js +27 -0
  92. package/_esm/chains/definitions/kinetiqElysium.js.map +1 -0
  93. package/_esm/chains/definitions/kinetiqElysiumTestnet.js +28 -0
  94. package/_esm/chains/definitions/kinetiqElysiumTestnet.js.map +1 -0
  95. package/_esm/chains/index.js +2 -0
  96. package/_esm/chains/index.js.map +1 -1
  97. package/_esm/errors/encoding.js +8 -0
  98. package/_esm/errors/encoding.js.map +1 -1
  99. package/_esm/errors/typedData.js +2 -0
  100. package/_esm/errors/typedData.js.map +1 -1
  101. package/_esm/errors/version.js +1 -1
  102. package/_esm/index.js +1 -1
  103. package/_esm/index.js.map +1 -1
  104. package/_esm/tempo/actions/accounts.js +19 -5
  105. package/_esm/tempo/actions/accounts.js.map +1 -1
  106. package/_esm/tempo/chainConfig.js +25 -1
  107. package/_esm/tempo/chainConfig.js.map +1 -1
  108. package/_esm/tempo/internal/relay/feePayer.js +1 -1
  109. package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
  110. package/_esm/tempo/internal/relay.js +8 -3
  111. package/_esm/tempo/internal/relay.js.map +1 -1
  112. package/_esm/tempo/internal/utils.js +2 -10
  113. package/_esm/tempo/internal/utils.js.map +1 -1
  114. package/_esm/tokens/defineToken.js +2 -1
  115. package/_esm/tokens/defineToken.js.map +1 -1
  116. package/_esm/tokens/definitions/ousd.js +2 -1
  117. package/_esm/tokens/definitions/ousd.js.map +1 -1
  118. package/_esm/utils/address/getAddress.js +32 -6
  119. package/_esm/utils/address/getAddress.js.map +1 -1
  120. package/_esm/utils/address/isAddress.js +32 -12
  121. package/_esm/utils/address/isAddress.js.map +1 -1
  122. package/_esm/utils/encoding/fromRlp.js +37 -9
  123. package/_esm/utils/encoding/fromRlp.js.map +1 -1
  124. package/_esm/utils/index.js +1 -1
  125. package/_esm/utils/index.js.map +1 -1
  126. package/_esm/utils/promise/createBatchScheduler.js +7 -2
  127. package/_esm/utils/promise/createBatchScheduler.js.map +1 -1
  128. package/_esm/utils/typedData.js +7 -9
  129. package/_esm/utils/typedData.js.map +1 -1
  130. package/_types/accounts/index.d.ts +1 -1
  131. package/_types/accounts/index.d.ts.map +1 -1
  132. package/_types/accounts/utils/publicKeyToAddress.d.ts +16 -2
  133. package/_types/accounts/utils/publicKeyToAddress.d.ts.map +1 -1
  134. package/_types/actions/ens/getEnsText.d.ts +2 -1
  135. package/_types/actions/ens/getEnsText.d.ts.map +1 -1
  136. package/_types/actions/public/call.d.ts +1 -1
  137. package/_types/actions/public/call.d.ts.map +1 -1
  138. package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts +1 -1
  139. package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
  140. package/_types/actions/public/getDelegation.d.ts.map +1 -1
  141. package/_types/actions/public/getFeeHistory.d.ts +2 -1
  142. package/_types/actions/public/getFeeHistory.d.ts.map +1 -1
  143. package/_types/actions/token/internal.d.ts.map +1 -1
  144. package/_types/actions/wallet/deployContract.d.ts.map +1 -1
  145. package/_types/actions/wallet/prepareTransactionRequest.d.ts +2 -1
  146. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  147. package/_types/actions/wallet/sendCalls.d.ts.map +1 -1
  148. package/_types/actions/wallet/signAuthorization.d.ts.map +1 -1
  149. package/_types/chains/definitions/darwinia.d.ts +1 -1
  150. package/_types/chains/definitions/darwinia.d.ts.map +1 -1
  151. package/_types/chains/definitions/flowMainnet.d.ts +1 -1
  152. package/_types/chains/definitions/flowMainnet.d.ts.map +1 -1
  153. package/_types/chains/definitions/kinetiqElysium.d.ts +52 -0
  154. package/_types/chains/definitions/kinetiqElysium.d.ts.map +1 -0
  155. package/_types/chains/definitions/kinetiqElysiumTestnet.d.ts +52 -0
  156. package/_types/chains/definitions/kinetiqElysiumTestnet.d.ts.map +1 -0
  157. package/_types/chains/index.d.ts +2 -0
  158. package/_types/chains/index.d.ts.map +1 -1
  159. package/_types/errors/encoding.d.ts +9 -0
  160. package/_types/errors/encoding.d.ts.map +1 -1
  161. package/_types/errors/typedData.d.ts.map +1 -1
  162. package/_types/errors/version.d.ts +1 -1
  163. package/_types/index.d.ts +1 -1
  164. package/_types/index.d.ts.map +1 -1
  165. package/_types/tempo/actions/accounts.d.ts +4 -1
  166. package/_types/tempo/actions/accounts.d.ts.map +1 -1
  167. package/_types/tempo/chainConfig.d.ts.map +1 -1
  168. package/_types/tempo/internal/utils.d.ts.map +1 -1
  169. package/_types/tokens/defineToken.d.ts +5 -1
  170. package/_types/tokens/defineToken.d.ts.map +1 -1
  171. package/_types/tokens/definitions/ousd.d.ts +2 -1
  172. package/_types/tokens/definitions/ousd.d.ts.map +1 -1
  173. package/_types/tokens/sets.d.ts +3 -0
  174. package/_types/tokens/sets.d.ts.map +1 -1
  175. package/_types/utils/address/getAddress.d.ts +23 -0
  176. package/_types/utils/address/getAddress.d.ts.map +1 -1
  177. package/_types/utils/address/isAddress.d.ts +22 -0
  178. package/_types/utils/address/isAddress.d.ts.map +1 -1
  179. package/_types/utils/encoding/fromRlp.d.ts +3 -3
  180. package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
  181. package/_types/utils/index.d.ts +1 -1
  182. package/_types/utils/index.d.ts.map +1 -1
  183. package/_types/utils/promise/createBatchScheduler.d.ts.map +1 -1
  184. package/_types/utils/typedData.d.ts.map +1 -1
  185. package/_types/zksync/errors/bridge.d.ts +1 -1
  186. package/_types/zksync/errors/bridge.d.ts.map +1 -1
  187. package/accounts/index.ts +2 -0
  188. package/accounts/utils/publicKeyToAddress.ts +27 -1
  189. package/actions/ens/getEnsText.ts +2 -0
  190. package/actions/public/call.ts +20 -3
  191. package/actions/public/estimateMaxPriorityFeePerGas.ts +2 -2
  192. package/actions/public/getDelegation.ts +6 -1
  193. package/actions/public/getFeeHistory.ts +2 -0
  194. package/actions/token/internal.ts +2 -10
  195. package/actions/wallet/deployContract.ts +6 -1
  196. package/actions/wallet/prepareTransactionRequest.ts +138 -107
  197. package/actions/wallet/sendCalls.ts +6 -1
  198. package/actions/wallet/signAuthorization.ts +6 -1
  199. package/chains/definitions/darwinia.ts +1 -1
  200. package/chains/definitions/flowMainnet.ts +1 -1
  201. package/chains/definitions/kinetiqElysium.ts +27 -0
  202. package/chains/definitions/kinetiqElysiumTestnet.ts +28 -0
  203. package/chains/index.ts +2 -0
  204. package/errors/encoding.ts +12 -0
  205. package/errors/typedData.ts +2 -0
  206. package/errors/version.ts +1 -1
  207. package/index.ts +2 -0
  208. package/package.json +2 -2
  209. package/tempo/actions/accounts.ts +24 -6
  210. package/tempo/chainConfig.ts +33 -5
  211. package/tempo/internal/relay/feePayer.ts +1 -1
  212. package/tempo/internal/relay.ts +8 -3
  213. package/tempo/internal/utils.ts +2 -10
  214. package/tokens/defineToken.ts +6 -2
  215. package/tokens/definitions/ousd.ts +2 -1
  216. package/utils/address/getAddress.ts +31 -6
  217. package/utils/address/isAddress.ts +31 -10
  218. package/utils/encoding/fromRlp.ts +37 -5
  219. package/utils/index.ts +2 -0
  220. package/utils/promise/createBatchScheduler.ts +10 -2
  221. package/utils/typedData.ts +7 -9
  222. package/zksync/errors/bridge.ts +1 -1
@@ -13,6 +13,7 @@ import {
13
13
  type EstimateGasParameters,
14
14
  estimateGas,
15
15
  } from '../../actions/public/estimateGas.js'
16
+ import { internal_estimateMaxPriorityFeePerGas } from '../../actions/public/estimateMaxPriorityFeePerGas.js'
16
17
  import {
17
18
  type GetBlockErrorType,
18
19
  getBlock as getBlock_,
@@ -34,6 +35,7 @@ import {
34
35
  MaxFeePerGasTooLowError,
35
36
  } from '../../errors/fee.js'
36
37
  import { FeePayerNonceMismatchError } from '../../errors/transaction.js'
38
+ import type { ErrorType } from '../../errors/utils.js'
37
39
  import type { DeriveAccount, GetAccountParameter } from '../../types/account.js'
38
40
  import type { Block } from '../../types/block.js'
39
41
  import type { ExtractCapabilities } from '../../types/capabilities.js'
@@ -242,6 +244,7 @@ export type PrepareTransactionRequestErrorType =
242
244
  | GetTransactionCountErrorType
243
245
  | EstimateGasErrorType
244
246
  | EstimateFeesPerGasErrorType
247
+ | ErrorType
245
248
 
246
249
  /**
247
250
  * Prepares a transaction request for signing.
@@ -608,133 +611,161 @@ export async function prepareTransactionRequest<
608
611
  )) ?? request
609
612
  }
610
613
 
611
- let block: Block | undefined
612
- async function getBlock(): Promise<Block> {
613
- if (block) return block
614
- block = await getAction(
615
- client,
616
- getBlock_,
617
- 'getBlock',
618
- )({ blockTag: 'latest' })
614
+ let block: Promise<Block> | undefined
615
+ function getBlock(): Promise<Block> {
616
+ block ??= getAction(client, getBlock_, 'getBlock')({ blockTag: 'latest' })
619
617
  return block
620
618
  }
621
619
 
622
- if (
620
+ // Chain fee hooks receive the block and the request, so the requests they
621
+ // depend on are made in sequence.
622
+ const hasFeeHooks = Object.values(chain?.fees ?? {}).some(
623
+ (fee) => typeof fee === 'function',
624
+ )
625
+
626
+ // The nonce does not depend on the type or the fees, so it is fetched
627
+ // concurrently with them.
628
+ const noncePromise =
623
629
  parameters.includes('nonce') &&
624
630
  typeof nonce === 'undefined' &&
625
631
  account &&
626
632
  !nonceManager
627
- )
628
- request.nonce = await getAction(
629
- client,
630
- getTransactionCount,
631
- 'getTransactionCount',
632
- )({
633
- address: account.address,
634
- blockTag: 'pending',
635
- })
636
-
637
- if (
638
- (parameters.includes('blobVersionedHashes') ||
639
- parameters.includes('sidecars')) &&
640
- blobs &&
641
- kzg
642
- ) {
643
- const commitments = blobsToCommitments({ blobs, kzg })
644
-
645
- if (parameters.includes('blobVersionedHashes')) {
646
- const versionedHashes = commitmentsToVersionedHashes({
647
- commitments,
648
- to: 'hex',
649
- })
650
- request.blobVersionedHashes = versionedHashes
651
- }
652
- if (parameters.includes('sidecars')) {
653
- const proofs = blobsToProofs({ blobs, commitments, kzg })
654
- const sidecars = toBlobSidecars({
655
- blobs,
656
- commitments,
657
- proofs,
658
- to: 'hex',
659
- })
660
- request.sidecars = sidecars
633
+ ? getAction(
634
+ client,
635
+ getTransactionCount,
636
+ 'getTransactionCount',
637
+ )({
638
+ address: account.address,
639
+ blockTag: 'pending',
640
+ })
641
+ : undefined
642
+ // A rejection is thrown when the nonce is awaited.
643
+ noncePromise?.catch(() => {})
644
+ if (noncePromise && hasFeeHooks) request.nonce = await noncePromise
645
+
646
+ try {
647
+ if (
648
+ (parameters.includes('blobVersionedHashes') ||
649
+ parameters.includes('sidecars')) &&
650
+ blobs &&
651
+ kzg
652
+ ) {
653
+ const commitments = blobsToCommitments({ blobs, kzg })
654
+
655
+ if (parameters.includes('blobVersionedHashes')) {
656
+ const versionedHashes = commitmentsToVersionedHashes({
657
+ commitments,
658
+ to: 'hex',
659
+ })
660
+ request.blobVersionedHashes = versionedHashes
661
+ }
662
+ if (parameters.includes('sidecars')) {
663
+ const proofs = blobsToProofs({ blobs, commitments, kzg })
664
+ const sidecars = toBlobSidecars({
665
+ blobs,
666
+ commitments,
667
+ proofs,
668
+ to: 'hex',
669
+ })
670
+ request.sidecars = sidecars
671
+ }
661
672
  }
662
- }
663
673
 
664
- if (parameters.includes('chainId')) request.chainId = await getChainId()
674
+ if (parameters.includes('chainId')) request.chainId = await getChainId()
665
675
 
666
- if (
667
- (parameters.includes('fees') || parameters.includes('type')) &&
668
- typeof type === 'undefined'
669
- ) {
670
- try {
671
- request.type = getTransactionType(
672
- request as TransactionSerializable,
673
- ) as any
674
- } catch {
675
- let isEip1559Network = eip1559NetworkCache.get(client.uid)
676
- if (typeof isEip1559Network === 'undefined') {
677
- const block = await getBlock()
678
- isEip1559Network = typeof block?.baseFeePerGas === 'bigint'
679
- eip1559NetworkCache.set(client.uid, isEip1559Network)
676
+ if (
677
+ (parameters.includes('fees') || parameters.includes('type')) &&
678
+ typeof type === 'undefined'
679
+ ) {
680
+ try {
681
+ request.type = getTransactionType(
682
+ request as TransactionSerializable,
683
+ ) as any
684
+ } catch {
685
+ let isEip1559Network = eip1559NetworkCache.get(client.uid)
686
+ if (typeof isEip1559Network === 'undefined') {
687
+ const block = await getBlock()
688
+ isEip1559Network = typeof block?.baseFeePerGas === 'bigint'
689
+ eip1559NetworkCache.set(client.uid, isEip1559Network)
690
+ }
691
+ request.type = isEip1559Network ? 'eip1559' : 'legacy'
680
692
  }
681
- request.type = isEip1559Network ? 'eip1559' : 'legacy'
682
693
  }
683
- }
684
694
 
685
- if (parameters.includes('fees')) {
686
- // TODO(4844): derive blob base fees once https://github.com/ethereum/execution-apis/pull/486 is merged.
687
-
688
- if (request.type !== 'legacy' && request.type !== 'eip2930') {
689
- // EIP-1559 fees
690
- if (
691
- typeof request.maxFeePerGas === 'undefined' ||
692
- typeof request.maxPriorityFeePerGas === 'undefined'
693
- ) {
694
- const block = await getBlock()
695
- const { maxFeePerGas, maxPriorityFeePerGas } =
696
- await internal_estimateFeesPerGas(client, {
697
- block: block as Block,
698
- chain,
699
- request: request as PrepareTransactionRequestParameters,
700
- })
695
+ if (parameters.includes('fees')) {
696
+ // TODO(4844): derive blob base fees once https://github.com/ethereum/execution-apis/pull/486 is merged.
701
697
 
698
+ if (request.type !== 'legacy' && request.type !== 'eip2930') {
699
+ // EIP-1559 fees
702
700
  if (
703
- typeof request.maxPriorityFeePerGas === 'undefined' &&
704
- typeof request.maxFeePerGas === 'bigint' &&
705
- request.maxFeePerGas < maxPriorityFeePerGas
706
- )
707
- throw new MaxFeePerGasTooLowError({
708
- maxPriorityFeePerGas,
709
- })
710
-
711
- request.maxPriorityFeePerGas = maxPriorityFeePerGas
712
- request.maxFeePerGas = maxFeePerGas
713
- }
714
- } else {
715
- // Legacy fees
716
- if (
717
- typeof request.maxFeePerGas !== 'undefined' ||
718
- typeof request.maxPriorityFeePerGas !== 'undefined'
719
- )
720
- throw new Eip1559FeesNotSupportedError()
721
-
722
- if (typeof request.gasPrice === 'undefined') {
723
- const block = await getBlock()
724
- const { gasPrice: gasPrice_ } = await internal_estimateFeesPerGas(
725
- client,
726
- {
727
- block: block as Block,
728
- chain,
729
- request: request as PrepareTransactionRequestParameters,
730
- type: 'legacy',
731
- },
701
+ typeof request.maxFeePerGas === 'undefined' ||
702
+ typeof request.maxPriorityFeePerGas === 'undefined'
703
+ ) {
704
+ // Without chain fee hooks, the priority fee does not depend on the
705
+ // block, so it is estimated concurrently with the block request.
706
+ const [block, priorityFee] = await Promise.all([
707
+ getBlock(),
708
+ hasFeeHooks || typeof request.maxPriorityFeePerGas === 'bigint'
709
+ ? undefined
710
+ : internal_estimateMaxPriorityFeePerGas(client, {
711
+ block: getBlock(),
712
+ chain,
713
+ request: request as PrepareTransactionRequestParameters,
714
+ }),
715
+ ])
716
+ const { maxFeePerGas, maxPriorityFeePerGas } =
717
+ await internal_estimateFeesPerGas(client, {
718
+ block,
719
+ chain,
720
+ request: (typeof priorityFee === 'bigint'
721
+ ? { ...request, maxPriorityFeePerGas: priorityFee }
722
+ : request) as PrepareTransactionRequestParameters,
723
+ })
724
+
725
+ if (
726
+ typeof request.maxPriorityFeePerGas === 'undefined' &&
727
+ typeof request.maxFeePerGas === 'bigint' &&
728
+ request.maxFeePerGas < maxPriorityFeePerGas
729
+ )
730
+ throw new MaxFeePerGasTooLowError({
731
+ maxPriorityFeePerGas,
732
+ })
733
+
734
+ request.maxPriorityFeePerGas = maxPriorityFeePerGas
735
+ request.maxFeePerGas = maxFeePerGas
736
+ }
737
+ } else {
738
+ // Legacy fees
739
+ if (
740
+ typeof request.maxFeePerGas !== 'undefined' ||
741
+ typeof request.maxPriorityFeePerGas !== 'undefined'
732
742
  )
733
- request.gasPrice = gasPrice_
743
+ throw new Eip1559FeesNotSupportedError()
744
+
745
+ if (typeof request.gasPrice === 'undefined') {
746
+ const block = await getBlock()
747
+ const { gasPrice: gasPrice_ } = await internal_estimateFeesPerGas(
748
+ client,
749
+ {
750
+ block: block as Block,
751
+ chain,
752
+ request: request as PrepareTransactionRequestParameters,
753
+ type: 'legacy',
754
+ },
755
+ )
756
+ request.gasPrice = gasPrice_
757
+ }
734
758
  }
735
759
  }
760
+ } catch (error) {
761
+ // A failed nonce request takes precedence over errors from the other
762
+ // parameters.
763
+ await noncePromise
764
+ throw error
736
765
  }
737
766
 
767
+ if (noncePromise) request.nonce = await noncePromise
768
+
738
769
  if (parameters.includes('gas') && typeof gas === 'undefined')
739
770
  request.gas = await getAction(
740
771
  client,
@@ -21,6 +21,7 @@ import { concat } from '../../utils/data/concat.js'
21
21
  import { hexToBigInt } from '../../utils/encoding/fromHex.js'
22
22
  import { numberToHex } from '../../utils/encoding/toHex.js'
23
23
  import { getTransactionError } from '../../utils/errors/getTransactionError.js'
24
+ import { getAction } from '../../utils/getAction.js'
24
25
  import { sendTransaction } from './sendTransaction.js'
25
26
 
26
27
  export const fallbackMagicIdentifier =
@@ -225,7 +226,11 @@ export async function sendCalls<
225
226
  const results: PromiseSettledResult<Hex>[] = []
226
227
  for (const call of calls) {
227
228
  try {
228
- const value = await sendTransaction(client, {
229
+ const value = await getAction(
230
+ client,
231
+ sendTransaction,
232
+ 'sendTransaction',
233
+ )({
229
234
  account,
230
235
  chain,
231
236
  data: call.data,
@@ -17,6 +17,7 @@ import {
17
17
  } from '../../errors/account.js'
18
18
  import type { ErrorType } from '../../errors/utils.js'
19
19
  import type { Chain } from '../../types/chain.js'
20
+ import { getAction } from '../../utils/getAction.js'
20
21
  import {
21
22
  type PrepareAuthorizationErrorType,
22
23
  type PrepareAuthorizationParameters,
@@ -103,6 +104,10 @@ export async function signAuthorization<
103
104
  type: account.type,
104
105
  })
105
106
 
106
- const authorization = await prepareAuthorization(client, parameters)
107
+ const authorization = await getAction(
108
+ client,
109
+ prepareAuthorization,
110
+ 'prepareAuthorization',
111
+ )(parameters)
107
112
  return account.signAuthorization(authorization)
108
113
  }
@@ -20,7 +20,7 @@ export const darwinia = /*#__PURE__*/ defineChain({
20
20
  contracts: {
21
21
  multicall3: {
22
22
  address: '0xca11bde05977b3631167028862be2a173976ca11',
23
- blockCreated: 69420,
23
+ blockCreated: 251739,
24
24
  },
25
25
  },
26
26
  })
@@ -22,7 +22,7 @@ export const flowMainnet = /*#__PURE__*/ defineChain({
22
22
  contracts: {
23
23
  multicall3: {
24
24
  address: '0xca11bde05977b3631167028862be2a173976ca11',
25
- blockCreated: 6205,
25
+ blockCreated: 968659,
26
26
  },
27
27
  },
28
28
  blockTime: 800,
@@ -0,0 +1,27 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kinetiqElysium = /*#__PURE__*/ defineChain({
4
+ id: 99_901,
5
+ name: 'Elysium',
6
+ blockTime: 100,
7
+ nativeCurrency: { name: 'HYPE', symbol: 'HYPE', decimals: 18 },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ['https://rpc.elysium.kinetiq.xyz'],
11
+ },
12
+ },
13
+ blockExplorers: {
14
+ default: {
15
+ name: 'Elysium Explorer',
16
+ url: 'https://elysium.kinetiq.xyz',
17
+ apiUrl: 'https://elysium.kinetiq.xyz/api',
18
+ },
19
+ },
20
+ contracts: {
21
+ multicall3: {
22
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
23
+ blockCreated: 1343,
24
+ },
25
+ },
26
+ sourceId: 999,
27
+ })
@@ -0,0 +1,28 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kinetiqElysiumTestnet = /*#__PURE__*/ defineChain({
4
+ id: 99_801,
5
+ name: 'Kinetiq Elysium Testnet',
6
+ blockTime: 100,
7
+ nativeCurrency: { name: 'HYPE', symbol: 'HYPE', decimals: 18 },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ['https://testnet-rpc.elysium.kinetiq.xyz'],
11
+ },
12
+ },
13
+ blockExplorers: {
14
+ default: {
15
+ name: 'Elysium Testnet Explorer',
16
+ url: 'https://testnet.elysium.kinetiq.xyz',
17
+ apiUrl: 'https://testnet.elysium.kinetiq.xyz/api',
18
+ },
19
+ },
20
+ contracts: {
21
+ multicall3: {
22
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
23
+ blockCreated: 91163,
24
+ },
25
+ },
26
+ sourceId: 998,
27
+ testnet: true,
28
+ })
package/chains/index.ts CHANGED
@@ -351,6 +351,8 @@ export { kavaTestnet } from './definitions/kavaTestnet.js'
351
351
  export { kcc } from './definitions/kcc.js'
352
352
  export { kii } from './definitions/kii.js'
353
353
  export { kiiTestnetOro } from './definitions/kiiTestnet.js'
354
+ export { kinetiqElysium } from './definitions/kinetiqElysium.js'
355
+ export { kinetiqElysiumTestnet } from './definitions/kinetiqElysiumTestnet.js'
354
356
  export { kinto } from './definitions/kinto.js'
355
357
  /** @deprecated Use `kaia` instead. */
356
358
  export { klaytn } from './definitions/klaytn.js'
@@ -89,6 +89,18 @@ export class RlpListBoundaryExceededError extends BaseError {
89
89
  }
90
90
  }
91
91
 
92
+ export type RlpNonCanonicalErrorType = RlpNonCanonicalError & {
93
+ name: 'RlpNonCanonicalError'
94
+ }
95
+ /** Thrown when an RLP payload uses a non-minimal length prefix or wraps a single byte below `0x80` in a length prefix. */
96
+ export class RlpNonCanonicalError extends BaseError {
97
+ constructor({ reason }: { reason: string }) {
98
+ super(`RLP payload is not canonically encoded: ${reason}.`, {
99
+ name: 'RlpNonCanonicalError',
100
+ })
101
+ }
102
+ }
103
+
92
104
  export type RlpTrailingBytesErrorType = RlpTrailingBytesError & {
93
105
  name: 'RlpTrailingBytesError'
94
106
  }
@@ -10,6 +10,7 @@ export class InvalidDomainError extends BaseError {
10
10
  constructor({ domain }: { domain: unknown }) {
11
11
  super(`Invalid domain "${stringify(domain)}".`, {
12
12
  metaMessages: ['Must be a valid EIP-712 domain.'],
13
+ name: 'InvalidDomainError',
13
14
  })
14
15
  }
15
16
  }
@@ -27,6 +28,7 @@ export class InvalidPrimaryTypeError extends BaseError {
27
28
  {
28
29
  docsPath: '/api/glossary/Errors#typeddatainvalidprimarytypeerror',
29
30
  metaMessages: ['Check that the primary type is a key in `types`.'],
31
+ name: 'InvalidPrimaryTypeError',
30
32
  },
31
33
  )
32
34
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.57.18'
1
+ export const version = '2.57.20'
package/index.ts CHANGED
@@ -911,6 +911,8 @@ export {
911
911
  type RlpDepthLimitExceededErrorType,
912
912
  RlpListBoundaryExceededError,
913
913
  type RlpListBoundaryExceededErrorType,
914
+ RlpNonCanonicalError,
915
+ type RlpNonCanonicalErrorType,
914
916
  RlpTrailingBytesError,
915
917
  type RlpTrailingBytesErrorType,
916
918
  SizeOverflowError,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.57.18",
4
+ "version": "2.57.20",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -233,7 +233,7 @@
233
233
  "@scure/bip39": "1.6.0",
234
234
  "abitype": "1.2.3",
235
235
  "isows": "1.0.7",
236
- "ox": "0.14.65",
236
+ "ox": "0.14.67",
237
237
  "ws": "8.21.0"
238
238
  },
239
239
  "license": "MIT",
@@ -3,13 +3,17 @@ import type * as Hex from 'ox/Hex'
3
3
  import type * as RpcSchema from 'ox/RpcSchema'
4
4
  import { AccountConfig, AccountOperation, type RpcSchemaTempo } from 'ox/tempo'
5
5
  import type { Account } from '../../accounts/types.js'
6
- import type { ReadContractReturnType } from '../../actions/public/readContract.js'
6
+ import type {
7
+ ReadContractErrorType,
8
+ ReadContractReturnType,
9
+ } from '../../actions/public/readContract.js'
7
10
  import { readContract } from '../../actions/public/readContract.js'
8
11
  import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
9
12
  import { writeContract } from '../../actions/wallet/writeContract.js'
10
13
  import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
11
14
  import type { Client } from '../../clients/createClient.js'
12
15
  import type { Transport } from '../../clients/transports/createTransport.js'
16
+ import { zeroHash } from '../../constants/bytes.js'
13
17
  import type { BaseErrorType } from '../../errors/base.js'
14
18
  import type { Chain } from '../../types/chain.js'
15
19
  import type { Log } from '../../types/log.js'
@@ -156,6 +160,9 @@ export declare namespace getConfig {
156
160
  /**
157
161
  * Gets the current configuration commitment for a configurable account.
158
162
  *
163
+ * A chain without the configurable account precompile holds no commitments,
164
+ * so the commitment of every account on it is zero.
165
+ *
159
166
  * @example
160
167
  * ```ts
161
168
  * import { createClient, http } from 'viem'
@@ -175,7 +182,7 @@ export declare namespace getConfig {
175
182
  * @param client - Client.
176
183
  * @param parameters - Parameters.
177
184
  * @returns The current configuration commitment, or zero when no config has
178
- * been committed.
185
+ * been committed or the chain has no configurable account precompile.
179
186
  */
180
187
  export async function getConfigCommitment<
181
188
  chain extends Chain | undefined,
@@ -185,10 +192,21 @@ export async function getConfigCommitment<
185
192
  parameters: getConfigCommitment.Parameters,
186
193
  ): Promise<getConfigCommitment.ReturnValue> {
187
194
  const { account, ...rest } = parameters
188
- return withExecutionError(readContract)(client, {
189
- ...rest,
190
- ...getConfigCommitment.call({ account }),
191
- })
195
+ try {
196
+ return await withExecutionError(readContract)(client, {
197
+ ...rest,
198
+ ...getConfigCommitment.call({ account }),
199
+ })
200
+ } catch (e) {
201
+ const error = e as ReadContractErrorType
202
+ // A chain without the precompile answers no data, and holds no commitments.
203
+ if (
204
+ error.name === 'ContractFunctionExecutionError' &&
205
+ error.cause.name === 'ContractFunctionZeroDataError'
206
+ )
207
+ return zeroHash
208
+ throw error
209
+ }
192
210
  }
193
211
 
194
212
  export namespace getConfigCommitment {
@@ -25,6 +25,7 @@ import { defineTransactionReceipt } from '../utils/formatters/transactionReceipt
25
25
  import { defineTransactionRequest } from '../utils/formatters/transactionRequest.js'
26
26
  import { getAction } from '../utils/getAction.js'
27
27
  import { keccak256 } from '../utils/hash/keccak256.js'
28
+ import { recoverAddress } from '../utils/signature/recoverAddress.js'
28
29
  import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
29
30
  import type { Account, ConfigurableAccount } from './Account.js'
30
31
  import {
@@ -578,11 +579,38 @@ export const chainConfig = {
578
579
  }
579
580
  }
580
581
 
581
- return await getAction(
582
- client,
583
- verifyHash,
584
- 'verifyHash',
585
- )({ ...parameters, chain: null })
582
+ const verify = () =>
583
+ getAction(
584
+ client,
585
+ verifyHash,
586
+ 'verifyHash',
587
+ )({ ...parameters, chain: null })
588
+
589
+ const root = await (async () => {
590
+ try {
591
+ return isAddressEqual(
592
+ address,
593
+ await recoverAddress({ hash, signature }),
594
+ )
595
+ } catch {
596
+ return false
597
+ }
598
+ })()
599
+ if (!root) return await verify()
600
+
601
+ // A config commitment retires the root key (TIP-1113), whose signature still recovers
602
+ // to the account. Only the chain knows the commitment, so this reads it in every mode.
603
+ const [commitment, valid] = await Promise.all([
604
+ getConfigCommitment(client, {
605
+ account: address,
606
+ blockHash: parameters.blockHash,
607
+ blockNumber: parameters.blockNumber,
608
+ blockTag: parameters.blockTag,
609
+ requireCanonical: parameters.requireCanonical,
610
+ } as never),
611
+ verify(),
612
+ ])
613
+ return valid && BigInt(commitment) === 0n
586
614
  },
587
615
  } as const satisfies viem_ChainConfig & { blockTime: number }
588
616
 
@@ -652,7 +652,7 @@ function isCanonical(serialized: `0x76${string}` | `0x78${string}`) {
652
652
  : TxEnvelopeTempo.serialize(envelope)
653
653
  return serialized_parsed === serialized.toLowerCase()
654
654
  } catch {
655
- // Serialization refuses parsed values outside the safe integer range.
655
+ // An envelope that cannot be parsed or serialized has no canonical encoding.
656
656
  return false
657
657
  }
658
658
  }
@@ -174,10 +174,15 @@ export async function fetch(
174
174
  : Response.json(response)
175
175
  }
176
176
 
177
- /** Reads a request body, returning `undefined` once its declared or streamed size exceeds {@link maxBodySize}. */
177
+ /**
178
+ * Reads a request body, returning `undefined` once its declared or streamed size exceeds {@link maxBodySize}.
179
+ *
180
+ * The cancel of an oversized body is not awaited: a cloned request's body settles its cancel only once
181
+ * the clone's body ends too.
182
+ */
178
183
  async function readBody(request: Request) {
179
184
  if (Number(request.headers.get('content-length')) > maxBodySize) {
180
- await request.body?.cancel()
185
+ void request.body?.cancel().catch(() => {})
181
186
  return undefined
182
187
  }
183
188
  const chunks: Uint8Array<ArrayBuffer>[] = []
@@ -189,7 +194,7 @@ async function readBody(request: Request) {
189
194
  if (done) return chunks
190
195
  size += value.byteLength
191
196
  if (size > maxBodySize) {
192
- await reader.cancel()
197
+ void reader.cancel().catch(() => {})
193
198
  return undefined
194
199
  }
195
200
  chunks.push(value)
@@ -126,16 +126,8 @@ function resolveTokenForChain(
126
126
  token: Token,
127
127
  chainId: number,
128
128
  ): ResolvedToken | undefined {
129
- const address = (token.addresses as Record<number, Address>)[chainId]
130
- if (!address) return undefined
131
- return {
132
- address,
133
- currency: token.currency,
134
- decimals: token.decimals,
135
- name: token.name,
136
- popular: token.popular,
137
- symbol: token.symbol,
138
- }
129
+ if (!(token.addresses as Record<number, Address>)[chainId]) return undefined
130
+ return token(chainId as never)
139
131
  }
140
132
 
141
133
  /**