viem 2.6.1 → 2.7.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 (98) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/_cjs/actions/public/getTransaction.js.map +1 -1
  3. package/_cjs/errors/version.js +1 -1
  4. package/_cjs/index.js.map +1 -1
  5. package/_cjs/utils/formatters/block.js +4 -0
  6. package/_cjs/utils/formatters/block.js.map +1 -1
  7. package/_cjs/utils/formatters/transaction.js +9 -0
  8. package/_cjs/utils/formatters/transaction.js.map +1 -1
  9. package/_cjs/utils/formatters/transactionReceipt.js +6 -1
  10. package/_cjs/utils/formatters/transactionReceipt.js.map +1 -1
  11. package/_cjs/utils/formatters/transactionRequest.js +1 -0
  12. package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
  13. package/_esm/actions/public/getTransaction.js.map +1 -1
  14. package/_esm/errors/version.js +1 -1
  15. package/_esm/index.js.map +1 -1
  16. package/_esm/utils/formatters/block.js +4 -0
  17. package/_esm/utils/formatters/block.js.map +1 -1
  18. package/_esm/utils/formatters/transaction.js +9 -0
  19. package/_esm/utils/formatters/transaction.js.map +1 -1
  20. package/_esm/utils/formatters/transactionReceipt.js +6 -1
  21. package/_esm/utils/formatters/transactionReceipt.js.map +1 -1
  22. package/_esm/utils/formatters/transactionRequest.js +1 -0
  23. package/_esm/utils/formatters/transactionRequest.js.map +1 -1
  24. package/_types/actions/public/getTransaction.d.ts +2 -1
  25. package/_types/actions/public/getTransaction.d.ts.map +1 -1
  26. package/_types/chains/celo/chainConfig.d.ts +375 -65
  27. package/_types/chains/celo/chainConfig.d.ts.map +1 -1
  28. package/_types/chains/celo/formatters.d.ts +375 -65
  29. package/_types/chains/celo/formatters.d.ts.map +1 -1
  30. package/_types/chains/definitions/base.d.ts +279 -49
  31. package/_types/chains/definitions/base.d.ts.map +1 -1
  32. package/_types/chains/definitions/baseGoerli.d.ts +279 -49
  33. package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
  34. package/_types/chains/definitions/baseSepolia.d.ts +279 -49
  35. package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
  36. package/_types/chains/definitions/celo.d.ts +375 -65
  37. package/_types/chains/definitions/celo.d.ts.map +1 -1
  38. package/_types/chains/definitions/celoAlfajores.d.ts +375 -65
  39. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  40. package/_types/chains/definitions/optimism.d.ts +279 -49
  41. package/_types/chains/definitions/optimism.d.ts.map +1 -1
  42. package/_types/chains/definitions/optimismGoerli.d.ts +279 -49
  43. package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
  44. package/_types/chains/definitions/optimismSepolia.d.ts +279 -49
  45. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  46. package/_types/chains/definitions/pgn.d.ts +279 -49
  47. package/_types/chains/definitions/pgn.d.ts.map +1 -1
  48. package/_types/chains/definitions/pgnTestnet.d.ts +279 -49
  49. package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
  50. package/_types/chains/definitions/zkSync.d.ts +122 -6
  51. package/_types/chains/definitions/zkSync.d.ts.map +1 -1
  52. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts +122 -6
  53. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts.map +1 -1
  54. package/_types/chains/definitions/zkSyncTestnet.d.ts +122 -6
  55. package/_types/chains/definitions/zkSyncTestnet.d.ts.map +1 -1
  56. package/_types/chains/definitions/zora.d.ts +279 -49
  57. package/_types/chains/definitions/zora.d.ts.map +1 -1
  58. package/_types/chains/definitions/zoraSepolia.d.ts +279 -49
  59. package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
  60. package/_types/chains/definitions/zoraTestnet.d.ts +279 -49
  61. package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
  62. package/_types/chains/opStack/chainConfig.d.ts +279 -49
  63. package/_types/chains/opStack/chainConfig.d.ts.map +1 -1
  64. package/_types/chains/opStack/formatters.d.ts +279 -49
  65. package/_types/chains/opStack/formatters.d.ts.map +1 -1
  66. package/_types/chains/zksync/chainConfig.d.ts +122 -6
  67. package/_types/chains/zksync/chainConfig.d.ts.map +1 -1
  68. package/_types/chains/zksync/formatters.d.ts +122 -6
  69. package/_types/chains/zksync/formatters.d.ts.map +1 -1
  70. package/_types/errors/version.d.ts +1 -1
  71. package/_types/index.d.ts +2 -2
  72. package/_types/index.d.ts.map +1 -1
  73. package/_types/types/block.d.ts +4 -0
  74. package/_types/types/block.d.ts.map +1 -1
  75. package/_types/types/fee.d.ts +9 -3
  76. package/_types/types/fee.d.ts.map +1 -1
  77. package/_types/types/rpc.d.ts +2 -2
  78. package/_types/types/rpc.d.ts.map +1 -1
  79. package/_types/types/transaction.d.ts +20 -5
  80. package/_types/types/transaction.d.ts.map +1 -1
  81. package/_types/utils/formatters/block.d.ts.map +1 -1
  82. package/_types/utils/formatters/transaction.d.ts +387 -2
  83. package/_types/utils/formatters/transaction.d.ts.map +1 -1
  84. package/_types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  85. package/_types/utils/formatters/transactionRequest.d.ts +2 -1
  86. package/_types/utils/formatters/transactionRequest.d.ts.map +1 -1
  87. package/actions/public/getTransaction.ts +2 -1
  88. package/errors/version.ts +1 -1
  89. package/index.ts +2 -0
  90. package/package.json +1 -1
  91. package/types/block.ts +4 -0
  92. package/types/fee.ts +14 -2
  93. package/types/rpc.ts +3 -1
  94. package/types/transaction.ts +37 -6
  95. package/utils/formatters/block.ts +4 -0
  96. package/utils/formatters/transaction.ts +9 -0
  97. package/utils/formatters/transactionReceipt.ts +8 -1
  98. package/utils/formatters/transactionRequest.ts +1 -0
package/types/rpc.ts CHANGED
@@ -11,6 +11,7 @@ import type { Proof } from './proof.js'
11
11
  import type {
12
12
  TransactionEIP1559,
13
13
  TransactionEIP2930,
14
+ TransactionEIP4844,
14
15
  TransactionLegacy,
15
16
  TransactionReceipt,
16
17
  TransactionRequestEIP1559,
@@ -50,7 +51,8 @@ export type RpcTransaction<TPending extends boolean = boolean> = UnionOmit<
50
51
  UnionPartialBy<
51
52
  | TransactionLegacy<Quantity, Index, TPending, '0x0'>
52
53
  | TransactionEIP2930<Quantity, Index, TPending, '0x1'>
53
- | TransactionEIP1559<Quantity, Index, TPending, '0x2'>,
54
+ | TransactionEIP1559<Quantity, Index, TPending, '0x2'>
55
+ | TransactionEIP4844<Quantity, Index, TPending, '0x3'>,
54
56
  // `yParity` is optional on the RPC type as some nodes do not return it
55
57
  // for 1559 & 2930 transactions (they should!).
56
58
  'yParity'
@@ -1,15 +1,22 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
- import type { transactionType } from '../utils/formatters/transaction.js'
4
-
5
- import type { FeeValuesEIP1559, FeeValuesLegacy } from './fee.js'
3
+ import type {
4
+ FeeValuesEIP1559,
5
+ FeeValuesEIP4844,
6
+ FeeValuesLegacy,
7
+ } from './fee.js'
6
8
  import type { Log } from './log.js'
7
9
  import type { Hash, Hex, Signature } from './misc.js'
8
- import type { ValueOf } from './utils.js'
10
+ import type { OneOf } from './utils.js'
9
11
 
10
12
  export type AccessList = { address: Address; storageKeys: Hex[] }[]
11
13
 
12
- export type TransactionType = ValueOf<typeof transactionType> | (string & {})
14
+ export type TransactionType =
15
+ | 'legacy'
16
+ | 'eip1559'
17
+ | 'eip2930'
18
+ | 'eip4844'
19
+ | (string & {})
13
20
 
14
21
  export type TransactionReceipt<
15
22
  TQuantity = bigint,
@@ -17,6 +24,10 @@ export type TransactionReceipt<
17
24
  TStatus = 'success' | 'reverted',
18
25
  TType = TransactionType,
19
26
  > = {
27
+ /** The actual value per gas deducted from the sender's account for blob gas. Only specified for blob transactions as defined by EIP-4844. */
28
+ blobGasPrice?: TQuantity
29
+ /** The amount of blob gas used. Only specified for blob transactions as defined by EIP-4844. */
30
+ blobGasUsed?: TQuantity
20
31
  /** Hash of block containing this transaction */
21
32
  blockHash: Hash
22
33
  /** Number of block containing this transaction */
@@ -94,6 +105,7 @@ export type TransactionLegacy<
94
105
  FeeValuesLegacy<TQuantity> & {
95
106
  /** EIP-2930 Access List. */
96
107
  accessList?: never
108
+ blobVersionedHashes?: never
97
109
  /** Chain ID that this transaction is valid on. */
98
110
  chainId?: TIndex
99
111
  yParity?: never
@@ -108,6 +120,7 @@ export type TransactionEIP2930<
108
120
  FeeValuesLegacy<TQuantity> & {
109
121
  /** EIP-2930 Access List. */
110
122
  accessList: AccessList
123
+ blobVersionedHashes?: never
111
124
  /** Chain ID that this transaction is valid on. */
112
125
  chainId: TIndex
113
126
  type: TType
@@ -121,6 +134,22 @@ export type TransactionEIP1559<
121
134
  FeeValuesEIP1559<TQuantity> & {
122
135
  /** EIP-2930 Access List. */
123
136
  accessList: AccessList
137
+ blobVersionedHashes?: never
138
+ /** Chain ID that this transaction is valid on. */
139
+ chainId: TIndex
140
+ type: TType
141
+ }
142
+ export type TransactionEIP4844<
143
+ TQuantity = bigint,
144
+ TIndex = number,
145
+ TPending extends boolean = boolean,
146
+ TType = 'eip4844',
147
+ > = TransactionBase<TQuantity, TIndex, TPending> &
148
+ FeeValuesEIP4844<TQuantity> & {
149
+ /** EIP-2930 Access List. */
150
+ accessList: AccessList
151
+ /** List of versioned blob hashes associated with the transaction's blobs. */
152
+ blobVersionedHashes: Hex[]
124
153
  /** Chain ID that this transaction is valid on. */
125
154
  chainId: TIndex
126
155
  type: TType
@@ -129,10 +158,12 @@ export type Transaction<
129
158
  TQuantity = bigint,
130
159
  TIndex = number,
131
160
  TPending extends boolean = boolean,
132
- > =
161
+ > = OneOf<
133
162
  | TransactionLegacy<TQuantity, TIndex, TPending>
134
163
  | TransactionEIP2930<TQuantity, TIndex, TPending>
135
164
  | TransactionEIP1559<TQuantity, TIndex, TPending>
165
+ | TransactionEIP4844<TQuantity, TIndex, TPending>
166
+ >
136
167
 
137
168
  export type TransactionRequestBase<TQuantity = bigint, TIndex = number> = {
138
169
  /** Contract code or a hashed method call with encoded args */
@@ -48,7 +48,11 @@ export function formatBlock(block: Partial<RpcBlock>) {
48
48
  return {
49
49
  ...block,
50
50
  baseFeePerGas: block.baseFeePerGas ? BigInt(block.baseFeePerGas) : null,
51
+ blobGasUsed: block.blobGasUsed ? BigInt(block.blobGasUsed) : undefined,
51
52
  difficulty: block.difficulty ? BigInt(block.difficulty) : undefined,
53
+ excessBlobGas: block.excessBlobGas
54
+ ? BigInt(block.excessBlobGas)
55
+ : undefined,
52
56
  gasLimit: block.gasLimit ? BigInt(block.gasLimit) : undefined,
53
57
  gasUsed: block.gasUsed ? BigInt(block.gasUsed) : undefined,
54
58
  hash: block.hash ? block.hash : null,
@@ -37,6 +37,7 @@ export const transactionType = {
37
37
  '0x0': 'legacy',
38
38
  '0x1': 'eip2930',
39
39
  '0x2': 'eip1559',
40
+ '0x3': 'eip4844',
40
41
  } as const
41
42
 
42
43
  export type FormatTransactionErrorType = ErrorType
@@ -51,6 +52,9 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
51
52
  chainId: transaction.chainId ? hexToNumber(transaction.chainId) : undefined,
52
53
  gas: transaction.gas ? BigInt(transaction.gas) : undefined,
53
54
  gasPrice: transaction.gasPrice ? BigInt(transaction.gasPrice) : undefined,
55
+ maxFeePerBlobGas: transaction.maxFeePerBlobGas
56
+ ? BigInt(transaction.maxFeePerBlobGas)
57
+ : undefined,
54
58
  maxFeePerGas: transaction.maxFeePerGas
55
59
  ? BigInt(transaction.maxFeePerGas)
56
60
  : undefined,
@@ -86,14 +90,19 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
86
90
 
87
91
  if (transaction_.type === 'legacy') {
88
92
  delete transaction_.accessList
93
+ delete transaction_.maxFeePerBlobGas
89
94
  delete transaction_.maxFeePerGas
90
95
  delete transaction_.maxPriorityFeePerGas
91
96
  delete transaction_.yParity
92
97
  }
93
98
  if (transaction_.type === 'eip2930') {
99
+ delete transaction_.maxFeePerBlobGas
94
100
  delete transaction_.maxFeePerGas
95
101
  delete transaction_.maxPriorityFeePerGas
96
102
  }
103
+ if (transaction_.type === 'eip1559') {
104
+ delete transaction_.maxFeePerBlobGas
105
+ }
97
106
  return transaction_
98
107
  }
99
108
 
@@ -29,7 +29,7 @@ export type FormatTransactionReceiptErrorType = ErrorType
29
29
  export function formatTransactionReceipt(
30
30
  transactionReceipt: Partial<RpcTransactionReceipt>,
31
31
  ) {
32
- return {
32
+ const receipt = {
33
33
  ...transactionReceipt,
34
34
  blockNumber: transactionReceipt.blockNumber
35
35
  ? BigInt(transactionReceipt.blockNumber)
@@ -62,6 +62,13 @@ export function formatTransactionReceipt(
62
62
  ] || transactionReceipt.type
63
63
  : null,
64
64
  } as TransactionReceipt
65
+
66
+ if (transactionReceipt.blobGasPrice)
67
+ receipt.blobGasPrice = BigInt(transactionReceipt.blobGasPrice)
68
+ if (transactionReceipt.blobGasUsed)
69
+ receipt.blobGasUsed = BigInt(transactionReceipt.blobGasUsed)
70
+
71
+ return receipt
65
72
  }
66
73
 
67
74
  export type DefineTransactionReceiptErrorType =
@@ -20,6 +20,7 @@ export const rpcTransactionType = {
20
20
  legacy: '0x0',
21
21
  eip2930: '0x1',
22
22
  eip1559: '0x2',
23
+ eip4844: '0x3',
23
24
  } as const
24
25
 
25
26
  export type FormatTransactionRequestErrorType = ErrorType