viem 0.0.0-main.20240519T155930 → 0.0.0-main.20240519T233212

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 (223) hide show
  1. package/_cjs/celo/formatters.js +1 -10
  2. package/_cjs/celo/formatters.js.map +1 -1
  3. package/_cjs/celo/serializers.js +0 -25
  4. package/_cjs/celo/serializers.js.map +1 -1
  5. package/_cjs/celo/utils.js +2 -15
  6. package/_cjs/celo/utils.js.map +1 -1
  7. package/_cjs/errors/version.js +1 -1
  8. package/_cjs/zksync/actions/estimateFee.js +26 -0
  9. package/_cjs/zksync/actions/estimateFee.js.map +1 -0
  10. package/_cjs/zksync/actions/estimateGasL1ToL2.js +20 -0
  11. package/_cjs/zksync/actions/estimateGasL1ToL2.js.map +1 -0
  12. package/_cjs/zksync/actions/getAllBalances.js +19 -0
  13. package/_cjs/zksync/actions/getAllBalances.js.map +1 -0
  14. package/_cjs/zksync/actions/getBaseTokenL1Address.js +9 -0
  15. package/_cjs/zksync/actions/getBaseTokenL1Address.js.map +1 -0
  16. package/_cjs/zksync/actions/getBlockDetails.js +12 -0
  17. package/_cjs/zksync/actions/getBlockDetails.js.map +1 -0
  18. package/_cjs/zksync/actions/getBridgehubContractAddress.js +9 -0
  19. package/_cjs/zksync/actions/getBridgehubContractAddress.js.map +1 -0
  20. package/_cjs/zksync/actions/getDefaultBridgeAddresses.js +13 -0
  21. package/_cjs/zksync/actions/getDefaultBridgeAddresses.js.map +1 -0
  22. package/_cjs/zksync/actions/getL1BatchBlockRange.js +13 -0
  23. package/_cjs/zksync/actions/getL1BatchBlockRange.js.map +1 -0
  24. package/_cjs/zksync/actions/getL1BatchDetails.js +12 -0
  25. package/_cjs/zksync/actions/getL1BatchDetails.js.map +1 -0
  26. package/_cjs/zksync/actions/getL1BatchNumber.js +9 -0
  27. package/_cjs/zksync/actions/getL1BatchNumber.js.map +1 -0
  28. package/_cjs/zksync/actions/getL1ChainId.js +9 -0
  29. package/_cjs/zksync/actions/getL1ChainId.js.map +1 -0
  30. package/_cjs/zksync/actions/getLogProof.js +12 -0
  31. package/_cjs/zksync/actions/getLogProof.js.map +1 -0
  32. package/_cjs/zksync/actions/getMainContractAddress.js +9 -0
  33. package/_cjs/zksync/actions/getMainContractAddress.js.map +1 -0
  34. package/_cjs/zksync/actions/getRawBlockTransaction.js +13 -0
  35. package/_cjs/zksync/actions/getRawBlockTransaction.js.map +1 -0
  36. package/_cjs/zksync/actions/getTestnetPaymasterAddress.js +9 -0
  37. package/_cjs/zksync/actions/getTestnetPaymasterAddress.js.map +1 -0
  38. package/_cjs/zksync/actions/getTransactionDetails.js +12 -0
  39. package/_cjs/zksync/actions/getTransactionDetails.js.map +1 -0
  40. package/_cjs/zksync/decorators/publicL2.js +43 -0
  41. package/_cjs/zksync/decorators/publicL2.js.map +1 -0
  42. package/_cjs/zksync/index.js +33 -3
  43. package/_cjs/zksync/index.js.map +1 -1
  44. package/_cjs/zksync/types/eip1193.js +3 -0
  45. package/_cjs/zksync/types/eip1193.js.map +1 -0
  46. package/_cjs/zksync/types/proof.js +3 -0
  47. package/_cjs/zksync/types/proof.js.map +1 -0
  48. package/_cjs/zksync/utils/camelCaseKeys.js +17 -0
  49. package/_cjs/zksync/utils/camelCaseKeys.js.map +1 -0
  50. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +4 -3
  51. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -1
  52. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js +4 -3
  53. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -1
  54. package/_esm/celo/formatters.js +2 -11
  55. package/_esm/celo/formatters.js.map +1 -1
  56. package/_esm/celo/serializers.js +1 -29
  57. package/_esm/celo/serializers.js.map +1 -1
  58. package/_esm/celo/utils.js +1 -15
  59. package/_esm/celo/utils.js.map +1 -1
  60. package/_esm/errors/version.js +1 -1
  61. package/_esm/zksync/actions/estimateFee.js +22 -0
  62. package/_esm/zksync/actions/estimateFee.js.map +1 -0
  63. package/_esm/zksync/actions/estimateGasL1ToL2.js +16 -0
  64. package/_esm/zksync/actions/estimateGasL1ToL2.js.map +1 -0
  65. package/_esm/zksync/actions/getAllBalances.js +15 -0
  66. package/_esm/zksync/actions/getAllBalances.js.map +1 -0
  67. package/_esm/zksync/actions/getBaseTokenL1Address.js +5 -0
  68. package/_esm/zksync/actions/getBaseTokenL1Address.js.map +1 -0
  69. package/_esm/zksync/actions/getBlockDetails.js +8 -0
  70. package/_esm/zksync/actions/getBlockDetails.js.map +1 -0
  71. package/_esm/zksync/actions/getBridgehubContractAddress.js +5 -0
  72. package/_esm/zksync/actions/getBridgehubContractAddress.js.map +1 -0
  73. package/_esm/zksync/actions/getDefaultBridgeAddresses.js +9 -0
  74. package/_esm/zksync/actions/getDefaultBridgeAddresses.js.map +1 -0
  75. package/_esm/zksync/actions/getL1BatchBlockRange.js +9 -0
  76. package/_esm/zksync/actions/getL1BatchBlockRange.js.map +1 -0
  77. package/_esm/zksync/actions/getL1BatchDetails.js +8 -0
  78. package/_esm/zksync/actions/getL1BatchDetails.js.map +1 -0
  79. package/_esm/zksync/actions/getL1BatchNumber.js +5 -0
  80. package/_esm/zksync/actions/getL1BatchNumber.js.map +1 -0
  81. package/_esm/zksync/actions/getL1ChainId.js +5 -0
  82. package/_esm/zksync/actions/getL1ChainId.js.map +1 -0
  83. package/_esm/zksync/actions/getLogProof.js +8 -0
  84. package/_esm/zksync/actions/getLogProof.js.map +1 -0
  85. package/_esm/zksync/actions/getMainContractAddress.js +5 -0
  86. package/_esm/zksync/actions/getMainContractAddress.js.map +1 -0
  87. package/_esm/zksync/actions/getRawBlockTransaction.js +9 -0
  88. package/_esm/zksync/actions/getRawBlockTransaction.js.map +1 -0
  89. package/_esm/zksync/actions/getTestnetPaymasterAddress.js +5 -0
  90. package/_esm/zksync/actions/getTestnetPaymasterAddress.js.map +1 -0
  91. package/_esm/zksync/actions/getTransactionDetails.js +8 -0
  92. package/_esm/zksync/actions/getTransactionDetails.js.map +1 -0
  93. package/_esm/zksync/decorators/publicL2.js +39 -0
  94. package/_esm/zksync/decorators/publicL2.js.map +1 -0
  95. package/_esm/zksync/index.js +16 -1
  96. package/_esm/zksync/index.js.map +1 -1
  97. package/_esm/zksync/types/eip1193.js +2 -0
  98. package/_esm/zksync/types/eip1193.js.map +1 -0
  99. package/_esm/zksync/types/proof.js +2 -0
  100. package/_esm/zksync/types/proof.js.map +1 -0
  101. package/_esm/zksync/utils/camelCaseKeys.js +13 -0
  102. package/_esm/zksync/utils/camelCaseKeys.js.map +1 -0
  103. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +2 -1
  104. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -1
  105. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js +2 -1
  106. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -1
  107. package/_types/celo/chainConfig.d.ts +58 -526
  108. package/_types/celo/chainConfig.d.ts.map +1 -1
  109. package/_types/celo/formatters.d.ts +29 -263
  110. package/_types/celo/formatters.d.ts.map +1 -1
  111. package/_types/celo/index.d.ts +1 -1
  112. package/_types/celo/index.d.ts.map +1 -1
  113. package/_types/celo/serializers.d.ts +2 -3
  114. package/_types/celo/serializers.d.ts.map +1 -1
  115. package/_types/celo/types.d.ts +5 -29
  116. package/_types/celo/types.d.ts.map +1 -1
  117. package/_types/celo/utils.d.ts +1 -2
  118. package/_types/celo/utils.d.ts.map +1 -1
  119. package/_types/chains/definitions/celo.d.ts +58 -526
  120. package/_types/chains/definitions/celo.d.ts.map +1 -1
  121. package/_types/chains/definitions/celoAlfajores.d.ts +58 -526
  122. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  123. package/_types/chains/definitions/lisk.d.ts +8 -8
  124. package/_types/chains/definitions/playfiAlbireo.d.ts +8 -8
  125. package/_types/chains/definitions/zkSync.d.ts +8 -8
  126. package/_types/chains/definitions/zkSyncInMemoryNode.d.ts +8 -8
  127. package/_types/chains/definitions/zkSyncLocalNode.d.ts +8 -8
  128. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts +8 -8
  129. package/_types/chains/definitions/zkSyncTestnet.d.ts +8 -8
  130. package/_types/chains/index.d.ts +1 -1
  131. package/_types/chains/index.d.ts.map +1 -1
  132. package/_types/errors/version.d.ts +1 -1
  133. package/_types/zksync/actions/estimateFee.d.ts +11 -0
  134. package/_types/zksync/actions/estimateFee.d.ts.map +1 -0
  135. package/_types/zksync/actions/estimateGasL1ToL2.d.ts +10 -0
  136. package/_types/zksync/actions/estimateGasL1ToL2.d.ts.map +1 -0
  137. package/_types/zksync/actions/getAllBalances.d.ts +12 -0
  138. package/_types/zksync/actions/getAllBalances.d.ts.map +1 -0
  139. package/_types/zksync/actions/getBaseTokenL1Address.d.ts +9 -0
  140. package/_types/zksync/actions/getBaseTokenL1Address.d.ts.map +1 -0
  141. package/_types/zksync/actions/getBlockDetails.d.ts +10 -0
  142. package/_types/zksync/actions/getBlockDetails.d.ts.map +1 -0
  143. package/_types/zksync/actions/getBridgehubContractAddress.d.ts +9 -0
  144. package/_types/zksync/actions/getBridgehubContractAddress.d.ts.map +1 -0
  145. package/_types/zksync/actions/getDefaultBridgeAddresses.d.ts +9 -0
  146. package/_types/zksync/actions/getDefaultBridgeAddresses.d.ts.map +1 -0
  147. package/_types/zksync/actions/getL1BatchBlockRange.d.ts +11 -0
  148. package/_types/zksync/actions/getL1BatchBlockRange.d.ts.map +1 -0
  149. package/_types/zksync/actions/getL1BatchDetails.d.ts +10 -0
  150. package/_types/zksync/actions/getL1BatchDetails.d.ts.map +1 -0
  151. package/_types/zksync/actions/getL1BatchNumber.d.ts +9 -0
  152. package/_types/zksync/actions/getL1BatchNumber.d.ts.map +1 -0
  153. package/_types/zksync/actions/getL1ChainId.d.ts +9 -0
  154. package/_types/zksync/actions/getL1ChainId.d.ts.map +1 -0
  155. package/_types/zksync/actions/getLogProof.d.ts +14 -0
  156. package/_types/zksync/actions/getLogProof.d.ts.map +1 -0
  157. package/_types/zksync/actions/getMainContractAddress.d.ts +9 -0
  158. package/_types/zksync/actions/getMainContractAddress.d.ts.map +1 -0
  159. package/_types/zksync/actions/getRawBlockTransaction.d.ts +11 -0
  160. package/_types/zksync/actions/getRawBlockTransaction.d.ts.map +1 -0
  161. package/_types/zksync/actions/getTestnetPaymasterAddress.d.ts +9 -0
  162. package/_types/zksync/actions/getTestnetPaymasterAddress.d.ts.map +1 -0
  163. package/_types/zksync/actions/getTransactionDetails.d.ts +13 -0
  164. package/_types/zksync/actions/getTransactionDetails.d.ts.map +1 -0
  165. package/_types/zksync/chainConfig.d.ts +8 -8
  166. package/_types/zksync/decorators/publicL2.d.ts +318 -0
  167. package/_types/zksync/decorators/publicL2.d.ts.map +1 -0
  168. package/_types/zksync/formatters.d.ts +8 -8
  169. package/_types/zksync/index.d.ts +17 -2
  170. package/_types/zksync/index.d.ts.map +1 -1
  171. package/_types/zksync/types/block.d.ts +30 -1
  172. package/_types/zksync/types/block.d.ts.map +1 -1
  173. package/_types/zksync/types/contract.d.ts +6 -0
  174. package/_types/zksync/types/contract.d.ts.map +1 -1
  175. package/_types/zksync/types/eip1193.d.ts +152 -0
  176. package/_types/zksync/types/eip1193.d.ts.map +1 -0
  177. package/_types/zksync/types/fee.d.ts +6 -0
  178. package/_types/zksync/types/fee.d.ts.map +1 -1
  179. package/_types/zksync/types/proof.d.ts +7 -0
  180. package/_types/zksync/types/proof.d.ts.map +1 -0
  181. package/_types/zksync/types/transaction.d.ts +65 -5
  182. package/_types/zksync/types/transaction.d.ts.map +1 -1
  183. package/_types/zksync/utils/camelCaseKeys.d.ts +2 -0
  184. package/_types/zksync/utils/camelCaseKeys.d.ts.map +1 -0
  185. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts +1 -1
  186. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts.map +1 -1
  187. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts +1 -1
  188. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts.map +1 -1
  189. package/celo/formatters.ts +3 -11
  190. package/celo/index.ts +0 -2
  191. package/celo/serializers.ts +2 -50
  192. package/celo/types.ts +3 -38
  193. package/celo/utils.ts +1 -24
  194. package/chains/index.ts +0 -2
  195. package/errors/version.ts +1 -1
  196. package/package.json +1 -1
  197. package/zksync/actions/estimateFee.ts +46 -0
  198. package/zksync/actions/estimateGasL1ToL2.ts +38 -0
  199. package/zksync/actions/getAllBalances.ts +33 -0
  200. package/zksync/actions/getBaseTokenL1Address.ts +18 -0
  201. package/zksync/actions/getBlockDetails.ts +27 -0
  202. package/zksync/actions/getBridgehubContractAddress.ts +18 -0
  203. package/zksync/actions/getDefaultBridgeAddresses.ts +22 -0
  204. package/zksync/actions/getL1BatchBlockRange.ts +26 -0
  205. package/zksync/actions/getL1BatchDetails.ts +27 -0
  206. package/zksync/actions/getL1BatchNumber.ts +18 -0
  207. package/zksync/actions/getL1ChainId.ts +18 -0
  208. package/zksync/actions/getLogProof.ts +28 -0
  209. package/zksync/actions/getMainContractAddress.ts +18 -0
  210. package/zksync/actions/getRawBlockTransaction.ts +26 -0
  211. package/zksync/actions/getTestnetPaymasterAddress.ts +18 -0
  212. package/zksync/actions/getTransactionDetails.ts +27 -0
  213. package/zksync/decorators/publicL2.ts +425 -0
  214. package/zksync/index.ts +62 -6
  215. package/zksync/types/block.ts +37 -1
  216. package/zksync/types/contract.ts +8 -0
  217. package/zksync/types/eip1193.ts +155 -0
  218. package/zksync/types/fee.ts +7 -0
  219. package/zksync/types/proof.ts +7 -0
  220. package/zksync/types/transaction.ts +84 -10
  221. package/zksync/utils/camelCaseKeys.ts +11 -0
  222. package/zksync/utils/paymaster/getApprovalBasedPaymasterInput.ts +5 -2
  223. package/zksync/utils/paymaster/getGeneralPaymasterInput.ts +5 -2
@@ -0,0 +1,425 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { Account } from '../../types/account.js'
5
+ import type { Hex } from '../../types/misc.js'
6
+ import { estimateFee } from '../actions/estimateFee.js'
7
+ import type {
8
+ EstimateFeeParameters,
9
+ EstimateFeeReturnType,
10
+ } from '../actions/estimateFee.js'
11
+ import {
12
+ type EstimateGasL1ToL2Parameters,
13
+ estimateGasL1ToL2,
14
+ } from '../actions/estimateGasL1ToL2.js'
15
+ import {
16
+ type GetAllBalancesParameters,
17
+ type GetAllBalancesReturnType,
18
+ getAllBalances,
19
+ } from '../actions/getAllBalances.js'
20
+ import { getBaseTokenL1Address } from '../actions/getBaseTokenL1Address.js'
21
+ import {
22
+ type GetBlockDetailsParameters,
23
+ type GetBlockDetailsReturnType,
24
+ getBlockDetails,
25
+ } from '../actions/getBlockDetails.js'
26
+ import { getBridgehubContractAddress } from '../actions/getBridgehubContractAddress.js'
27
+ import {
28
+ type GetDefaultBridgeAddressesReturnType,
29
+ getDefaultBridgeAddresses,
30
+ } from '../actions/getDefaultBridgeAddresses.js'
31
+ import {
32
+ type GetL1BatchBlockRangeParameters,
33
+ type GetL1BatchBlockRangeReturnParameters,
34
+ getL1BatchBlockRange,
35
+ } from '../actions/getL1BatchBlockRange.js'
36
+ import {
37
+ type GetL1BatchDetailsParameters,
38
+ type GetL1BatchDetailsReturnType,
39
+ getL1BatchDetails,
40
+ } from '../actions/getL1BatchDetails.js'
41
+ import { getL1BatchNumber } from '../actions/getL1BatchNumber.js'
42
+ import { getL1ChainId } from '../actions/getL1ChainId.js'
43
+ import {
44
+ type GetLogProofParameters,
45
+ type GetLogProofReturnType,
46
+ getLogProof,
47
+ } from '../actions/getLogProof.js'
48
+ import { getMainContractAddress } from '../actions/getMainContractAddress.js'
49
+ import {
50
+ type GetRawBlockTransactionParameters,
51
+ type GetRawBlockTransactionReturnType,
52
+ getRawBlockTransactions,
53
+ } from '../actions/getRawBlockTransaction.js'
54
+ import { getTestnetPaymasterAddress } from '../actions/getTestnetPaymasterAddress.js'
55
+ import {
56
+ type GetTransactionDetailsParameters,
57
+ type GetTransactionDetailsReturnType,
58
+ getTransactionDetails,
59
+ } from '../actions/getTransactionDetails.js'
60
+ import type { ChainEIP712 } from '../types/chain.js'
61
+
62
+ export type PublicActionsL2<
63
+ TChain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
64
+ TAccount extends Account | undefined = Account | undefined,
65
+ > = {
66
+ /**
67
+ * Returns the addresses of the default zkSync Era bridge contracts on both L1 and L2.
68
+ *
69
+ * @returns The Addresses of the default zkSync Era bridge contracts on both L1 and L2. {@link DefaultBridgeAddressesReturnType}
70
+ *
71
+ * @example
72
+ * import { createPublicClient, http } from 'viem'
73
+ * import { zkSyncLocalNode } from 'viem/chains'
74
+ * import { publicActionsL2 } from 'viem/zksync'
75
+ *
76
+ * const client = createPublicClient({
77
+ * chain: zkSyncLocalNode,
78
+ * transport: http(),
79
+ * }).extend(publicActionsL2())
80
+ *
81
+ * const addresses = await client.getDefaultBridgeAddresses();
82
+ */
83
+ getDefaultBridgeAddresses: () => Promise<GetDefaultBridgeAddressesReturnType>
84
+
85
+ /**
86
+ * Returns Testnet Paymaster Address.
87
+ *
88
+ * @returns The Address. {@link Address}
89
+ *
90
+ * @example
91
+ * import { createPublicClient, http } from 'viem'
92
+ * import { zkSyncLocalNode } from 'viem/chains'
93
+ * import { publicActionsL2 } from 'viem/zksync'
94
+ *
95
+ * const client = createPublicClient({
96
+ * chain: zkSyncLocalNode,
97
+ * transport: http(),
98
+ * }).extend(publicActionsL2())
99
+ *
100
+ * const address = await client.getTestnetPaymasterAddress();
101
+ */
102
+ getTestnetPaymasterAddress: () => Promise<Address | null>
103
+
104
+ /**
105
+ * Returns the Chain Id of underlying L1 network.
106
+ *
107
+ * @returns number
108
+ *
109
+ * @example
110
+ * import { createPublicClient, http } from 'viem'
111
+ * import { zkSyncLocalNode } from 'viem/chains'
112
+ * import { publicActionsL2 } from 'viem/zksync'
113
+ *
114
+ * const client = createPublicClient({
115
+ * chain: zkSyncLocalNode,
116
+ * transport: http(),
117
+ * }).extend(publicActionsL2())
118
+ *
119
+ * const chainId = await client.getL1ChainId();
120
+ */
121
+
122
+ getL1ChainId: () => Promise<Hex>
123
+
124
+ /**
125
+ * Returns the address of a Main zkSync Contract.
126
+ *
127
+ * @returns The Address. {@link Address}
128
+ *
129
+ * @example
130
+ * import { createPublicClient, http } from 'viem'
131
+ * import { zkSyncLocalNode } from 'viem/chains'
132
+ * import { publicActionsL2 } from 'viem/zksync'
133
+ *
134
+ * const client = createPublicClient({
135
+ * chain: zkSyncLocalNode,
136
+ * transport: http(),
137
+ * }).extend(publicActionsL2())
138
+ *
139
+ * const address = await client.getMainContractAddress();
140
+ */
141
+ getMainContractAddress: () => Promise<Address>
142
+
143
+ /**
144
+ * Returns all known balances for a given account.
145
+ *
146
+ * @returns The balances for a given account. {@link GetAllBalancesReturnType}
147
+ * @param args - {@link GetAllBalancesParameters}
148
+ *
149
+ * @example
150
+ * import { createPublicClient, http } from 'viem'
151
+ * import { zkSyncLocalNode } from 'viem/chains'
152
+ * import { publicActionsL2 } from 'viem/zksync'
153
+ *
154
+ * const client = createPublicClient({
155
+ * chain: zkSyncLocalNode,
156
+ * transport: http(),
157
+ * }).extend(publicActionsL2())
158
+ *
159
+ * const balances = await client.getAllBalances({account: "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049"});
160
+ */
161
+ getAllBalances: (
162
+ args: GetAllBalancesParameters,
163
+ ) => Promise<GetAllBalancesReturnType>
164
+
165
+ /**
166
+ * Returns data of transactions in a block.
167
+ *
168
+ * @returns data of transactions {@link RawBlockTransactions}
169
+ * @param args - {@link GetRawBlockTransactionParameters}
170
+ *
171
+ * @example
172
+ * import { createPublicClient, http } from 'viem'
173
+ * import { zkSyncLocalNode } from 'viem/chains'
174
+ * import { publicActionsL2 } from 'viem/zksync'
175
+ *
176
+ * const client = createPublicClient({
177
+ * chain: zkSyncLocalNode,
178
+ * transport: http(),
179
+ * }).extend(publicActionsL2())
180
+ *
181
+ * const rawTx = await client.getRawBlockTransaction({number: 1});
182
+ */
183
+ getRawBlockTransaction: (
184
+ args: GetRawBlockTransactionParameters,
185
+ ) => Promise<GetRawBlockTransactionReturnType>
186
+
187
+ /**
188
+ * Returns additional zkSync-specific information about the L2 block.
189
+ *
190
+ * @returns zkSync-specific information about the L2 block {@link BaseBlockDetails}
191
+ * @param args - {@link GetBlockDetailsParameters}
192
+ *
193
+ * @example
194
+ * import { createPublicClient, http } from 'viem'
195
+ * import { zkSyncLocalNode } from 'viem/chains'
196
+ * import { publicActionsL2 } from 'viem/zksync'
197
+ *
198
+ * const client = createPublicClient({
199
+ * chain: zkSyncLocalNode,
200
+ * transport: http(),
201
+ * }).extend(publicActionsL2())
202
+ *
203
+ * const blockDetails = await client.getBlockDetails({number: 1});
204
+ */
205
+ getBlockDetails: (
206
+ args: GetBlockDetailsParameters,
207
+ ) => Promise<GetBlockDetailsReturnType>
208
+
209
+ /**
210
+ * Returns data pertaining to a given batch.
211
+ *
212
+ * @returns data pertaining to a given batch {@link BatchDetails}
213
+ * @param args - {@link GetL1BatchDetailsParameters}
214
+ *
215
+ * @example
216
+ * import { createPublicClient, http } from 'viem'
217
+ * import { zkSyncLocalNode } from 'viem/chains'
218
+ * import { publicActionsL2 } from 'viem/zksync'
219
+ *
220
+ * const client = createPublicClient({
221
+ * chain: zkSyncLocalNode,
222
+ * transport: http(),
223
+ * }).extend(publicActionsL2())
224
+ *
225
+ * const batchDetails = await client.getL1BatchDetails({number: 1});
226
+ */
227
+ getL1BatchDetails: (
228
+ args: GetL1BatchDetailsParameters,
229
+ ) => Promise<GetL1BatchDetailsReturnType>
230
+
231
+ /**
232
+ * Returns the range of blocks contained within a batch given by batch number.
233
+ *
234
+ * @returns range of blocks contained withing a batch {@link GetL1BatchBlockRangeReturnParameters}
235
+ * @param args - {@link GetL1BatchBlockRangeParameters}
236
+ *
237
+ * @example
238
+ * import { createPublicClient, http } from 'viem'
239
+ * import { zkSyncLocalNode } from 'viem/chains'
240
+ * import { publicActionsL2 } from 'viem/zksync'
241
+ *
242
+ * const client = createPublicClient({
243
+ * chain: zkSyncLocalNode,
244
+ * transport: http(),
245
+ * }).extend(publicActionsL2())
246
+ *
247
+ * const batchBlockRange = await client.getL1BatchBlockRange({number: 1});
248
+ */
249
+ getL1BatchBlockRange: (
250
+ args: GetL1BatchBlockRangeParameters,
251
+ ) => Promise<GetL1BatchBlockRangeReturnParameters>
252
+
253
+ /**
254
+ * Returns the latest L1 batch number
255
+ *
256
+ * @returns latest L1 batch number
257
+ *
258
+ * @example
259
+ * import { createPublicClient, http } from 'viem'
260
+ * import { zkSyncLocalNode } from 'viem/chains'
261
+ * import { publicActionsL2 } from 'viem/zksync'
262
+ *
263
+ * const client = createPublicClient({
264
+ * chain: zkSyncLocalNode,
265
+ * transport: http(),
266
+ * }).extend(publicActionsL2())
267
+ *
268
+ * const latestNumber = await client.getL1BatchNumber({number: 1});
269
+ */
270
+ getL1BatchNumber: () => Promise<Hex>
271
+
272
+ /**
273
+ * Given a transaction hash, and an index of the L2 to L1 log produced within the transaction, it returns the proof for the corresponding L2 to L1 log.
274
+ *
275
+ * @returns the proof for the corresponding L2 to L1 log.
276
+ *
277
+ * @example
278
+ * import { createPublicClient, http } from 'viem'
279
+ * import { zkSyncLocalNode } from 'viem/chains'
280
+ * import { publicActionsL2 } from 'viem/zksync'
281
+ *
282
+ * const client = createPublicClient({
283
+ * chain: zkSyncLocalNode,
284
+ * transport: http(),
285
+ * }).extend(publicActionsL2())
286
+ *
287
+ * const proof = await client.getLogProof({txHash: "0x...",index:1});
288
+ */
289
+ getLogProof: (args: GetLogProofParameters) => Promise<GetLogProofReturnType>
290
+
291
+ /**
292
+ * Returns data from a specific transaction given by the transaction hash
293
+ *
294
+ * @returns data from a specific transaction given by the transaction hash
295
+ *
296
+ *
297
+ * @example
298
+ * import { createPublicClient, http } from 'viem'
299
+ * import { zkSyncLocalNode } from 'viem/chains'
300
+ * import { publicActionsL2 } from 'viem/zksync'
301
+ *
302
+ * const client = createPublicClient({
303
+ * chain: zkSyncLocalNode,
304
+ * transport: http(),
305
+ * }).extend(publicActionsL2())
306
+ *
307
+ * const details = await client.getTransactionDetails({txHash: "0x..."});
308
+ */
309
+ getTransactionDetails: (
310
+ args: GetTransactionDetailsParameters,
311
+ ) => Promise<GetTransactionDetailsReturnType>
312
+
313
+ /**
314
+ * Returns an estimated Fee for requested transaction.
315
+ *
316
+ * @returns an estimated {@link Fee} for requested transaction.
317
+ * @param args - {@link EstimateFeeParameters}
318
+ *
319
+ * @example
320
+ * import { createPublicClient, http } from 'viem'
321
+ * import { zkSyncLocalNode } from 'viem/chains'
322
+ * import { publicActionsL2 } from 'viem/zksync'
323
+ *
324
+ * const client = createPublicClient({
325
+ * chain: zkSyncLocalNode,
326
+ * transport: http(),
327
+ * }).extend(publicActionsL2())
328
+ *
329
+ * const details = await client.estimateFee({transactionRequest: {...}}});
330
+ */
331
+ estimateFee: (
332
+ args: EstimateFeeParameters<TChain, TAccount>,
333
+ ) => Promise<EstimateFeeReturnType>
334
+
335
+ /**
336
+ * Returns an estimated gas for L1 to L2 execution.
337
+ *
338
+ * @returns an estimated gas.
339
+ * @param args - {@link EstimateGasL1ToL2Parameters}
340
+ *
341
+ * @example
342
+ * import { createPublicClient, http } from 'viem'
343
+ * import { zkSyncLocalNode } from 'viem/chains'
344
+ * import { publicActionsL2 } from 'viem/zksync'
345
+ *
346
+ * const client = createPublicClient({
347
+ * chain: zkSyncLocalNode,
348
+ * transport: http(),
349
+ * }).extend(publicActionsL2())
350
+ *
351
+ * const details = await client.estimateGasL1ToL2({transactionRequest: {...}}});
352
+ */
353
+ estimateGasL1ToL2: (
354
+ args: EstimateGasL1ToL2Parameters<TChain, TAccount>,
355
+ ) => Promise<bigint>
356
+
357
+ /**
358
+ * Returns the Bridgehub smart contract address.
359
+ *
360
+ * @returns address of the Bridgehub smart contract address.
361
+ *
362
+ *
363
+ * @example
364
+ * import { createPublicClient, http } from 'viem'
365
+ * import { zkSyncLocalNode } from 'viem/chains'
366
+ * import { publicActionsL2 } from 'viem/zksync'
367
+ *
368
+ * const client = createPublicClient({
369
+ * chain: zkSyncLocalNode,
370
+ * transport: http(),
371
+ * }).extend(publicActionsL2())
372
+ *
373
+ * const address = await client.getBridgehubContractAddress();
374
+ */
375
+ getBridgehubContractAddress: () => Promise<Address>
376
+
377
+ /**
378
+ * Returns the address of the base L1 token.
379
+ *
380
+ * @returns address of the base L1 token.
381
+ *
382
+ *
383
+ * @example
384
+ * import { createPublicClient, http } from 'viem'
385
+ * import { zkSyncLocalNode } from 'viem/chains'
386
+ * import { publicActionsL2 } from 'viem/zksync'
387
+ *
388
+ * const client = createPublicClient({
389
+ * chain: zkSyncLocalNode,
390
+ * transport: http(),
391
+ * }).extend(publicActionsL2())
392
+ *
393
+ * const address = await client.getBaseTokenL1Address();
394
+ */
395
+ getBaseTokenL1Address: () => Promise<Address>
396
+ }
397
+
398
+ export function publicActionsL2() {
399
+ return <
400
+ TTransport extends Transport = Transport,
401
+ TChain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
402
+ TAccount extends Account | undefined = Account | undefined,
403
+ >(
404
+ client: Client<TTransport, TChain, TAccount>,
405
+ ): PublicActionsL2<TChain, TAccount> => {
406
+ return {
407
+ estimateGasL1ToL2: (args) => estimateGasL1ToL2(client, args),
408
+ getDefaultBridgeAddresses: () => getDefaultBridgeAddresses(client),
409
+ getTestnetPaymasterAddress: () => getTestnetPaymasterAddress(client),
410
+ getL1ChainId: () => getL1ChainId(client),
411
+ getMainContractAddress: () => getMainContractAddress(client),
412
+ getAllBalances: (args) => getAllBalances(client, args),
413
+ getRawBlockTransaction: (args) => getRawBlockTransactions(client, args),
414
+ getBlockDetails: (args) => getBlockDetails(client, args),
415
+ getL1BatchDetails: (args) => getL1BatchDetails(client, args),
416
+ getL1BatchBlockRange: (args) => getL1BatchBlockRange(client, args),
417
+ getL1BatchNumber: () => getL1BatchNumber(client),
418
+ getLogProof: (args) => getLogProof(client, args),
419
+ getTransactionDetails: (args) => getTransactionDetails(client, args),
420
+ estimateFee: (args) => estimateFee(client, args),
421
+ getBridgehubContractAddress: () => getBridgehubContractAddress(client),
422
+ getBaseTokenL1Address: () => getBaseTokenL1Address(client),
423
+ }
424
+ }
425
+ }
package/zksync/index.ts CHANGED
@@ -1,3 +1,58 @@
1
+ export {
2
+ type DeployContractErrorType,
3
+ type DeployContractParameters,
4
+ type DeployContractReturnType,
5
+ deployContract,
6
+ } from './actions/deployContract.js'
7
+ export {
8
+ type EstimateFeeParameters,
9
+ type EstimateFeeReturnType,
10
+ estimateFee,
11
+ } from './actions/estimateFee.js'
12
+ export {
13
+ type GetAllBalancesParameters,
14
+ type GetAllBalancesReturnType,
15
+ getAllBalances,
16
+ } from './actions/getAllBalances.js'
17
+ export {
18
+ type GetBlockDetailsParameters,
19
+ type GetBlockDetailsReturnType,
20
+ getBlockDetails,
21
+ } from './actions/getBlockDetails.js'
22
+ export {
23
+ type GetDefaultBridgeAddressesReturnType,
24
+ getDefaultBridgeAddresses,
25
+ } from './actions/getDefaultBridgeAddresses.js'
26
+ export { getBridgehubContractAddress } from './actions/getBridgehubContractAddress.js'
27
+ export {
28
+ type GetL1BatchBlockRangeParameters,
29
+ type GetL1BatchBlockRangeReturnParameters,
30
+ getL1BatchBlockRange,
31
+ } from './actions/getL1BatchBlockRange.js'
32
+ export {
33
+ type GetL1BatchDetailsParameters,
34
+ type GetL1BatchDetailsReturnType,
35
+ getL1BatchDetails,
36
+ } from './actions/getL1BatchDetails.js'
37
+ export { getL1BatchNumber } from './actions/getL1BatchNumber.js'
38
+ export { getL1ChainId } from './actions/getL1ChainId.js'
39
+ export {
40
+ type GetLogProofReturnType,
41
+ type GetLogProofParameters,
42
+ getLogProof,
43
+ } from './actions/getLogProof.js'
44
+ export { getMainContractAddress } from './actions/getMainContractAddress.js'
45
+ export {
46
+ type GetRawBlockTransactionParameters,
47
+ type GetRawBlockTransactionReturnType,
48
+ getRawBlockTransactions,
49
+ } from './actions/getRawBlockTransaction.js'
50
+ export { getTestnetPaymasterAddress } from './actions/getTestnetPaymasterAddress.js'
51
+ export {
52
+ type GetTransactionDetailsParameters,
53
+ type GetTransactionDetailsReturnType,
54
+ getTransactionDetails,
55
+ } from './actions/getTransactionDetails.js'
1
56
  export {
2
57
  type SendTransactionErrorType,
3
58
  type SendTransactionParameters,
@@ -22,12 +77,6 @@ export {
22
77
  type SignTransactionReturnType,
23
78
  signTransaction,
24
79
  } from './actions/signTransaction.js'
25
- export {
26
- type DeployContractErrorType,
27
- type DeployContractParameters,
28
- type DeployContractReturnType,
29
- deployContract,
30
- } from './actions/deployContract.js'
31
80
 
32
81
  export {
33
82
  zkSync,
@@ -44,6 +93,11 @@ export {
44
93
 
45
94
  export { serializeTransaction } from './serializers.js'
46
95
 
96
+ export {
97
+ publicActionsL2,
98
+ type PublicActionsL2,
99
+ } from './decorators/publicL2.js'
100
+
47
101
  export type {
48
102
  ZkSyncBlock,
49
103
  ZkSyncBlockOverrides,
@@ -66,6 +120,7 @@ export type {
66
120
  export type {
67
121
  TransactionRequestEIP712,
68
122
  ZkSyncEIP712TransactionSignable,
123
+ ZkSyncRawBlockTransactions,
69
124
  ZkSyncRpcTransaction,
70
125
  ZkSyncRpcTransactionEIP712,
71
126
  ZkSyncRpcTransactionPriority,
@@ -83,6 +138,7 @@ export type {
83
138
  ZkSyncTransactionSerialized,
84
139
  ZkSyncTransactionSerializedEIP712,
85
140
  ZkSyncTransactionType,
141
+ ZkSyncTransactionDetails,
86
142
  } from './types/transaction.js'
87
143
 
88
144
  export {
@@ -1,8 +1,17 @@
1
+ import type { Address } from 'abitype'
1
2
  import type { Block, BlockTag } from '../../types/block.js'
2
- import type { Hex } from '../../types/misc.js'
3
+ import type { Hash, Hex } from '../../types/misc.js'
3
4
  import type { RpcBlock } from '../../types/rpc.js'
4
5
  import type { ZkSyncRpcTransaction, ZkSyncTransaction } from './transaction.js'
5
6
 
7
+ export type ZkSyncBatchDetails = Omit<
8
+ ZkSyncBlockDetails,
9
+ 'operatorAddress' | 'protocolVersion'
10
+ > & {
11
+ l1GasPrice: number
12
+ l2FairGasPrice: number
13
+ }
14
+
6
15
  export type ZkSyncBlockOverrides = {
7
16
  l1BatchNumber: bigint | null
8
17
  l1BatchTimestamp: bigint | null
@@ -19,10 +28,33 @@ export type ZkSyncBlock<
19
28
  > &
20
29
  ZkSyncBlockOverrides
21
30
 
31
+ export type ZkSyncBlockDetails = {
32
+ number: number
33
+ timestamp: number
34
+ l1BatchNumber: number
35
+ l1TxCount: number
36
+ l2TxCount: number
37
+ rootHash?: Hash
38
+ status: string
39
+ commitTxHash?: Hash
40
+ committedAt?: Date
41
+ proveTxHash?: Hash
42
+ provenAt?: Date
43
+ executeTxHash?: Hash
44
+ executedAt?: Date
45
+ baseSystemContractsHashes: {
46
+ bootloader: Hash
47
+ default_aa: Hash
48
+ }
49
+ operatorAddress: Address
50
+ protocolVersion?: string
51
+ }
52
+
22
53
  export type ZkSyncRpcBlockOverrides = {
23
54
  l1BatchNumber: Hex | null
24
55
  l1BatchTimestamp: Hex | null
25
56
  }
57
+
26
58
  export type ZkSyncRpcBlock<
27
59
  TBlockTag extends BlockTag = BlockTag,
28
60
  TIncludeTransactions extends boolean = boolean,
@@ -32,3 +64,7 @@ export type ZkSyncRpcBlock<
32
64
  ZkSyncRpcTransaction<TBlockTag extends 'pending' ? true : false>
33
65
  > &
34
66
  ZkSyncRpcBlockOverrides
67
+
68
+ export type ZkSyncNumberParameter = {
69
+ number: number
70
+ }
@@ -1,3 +1,11 @@
1
+ import type { Address } from 'abitype'
2
+
3
+ export type BridgeContractAddresses = {
4
+ erc20L1: Address
5
+ sharedL1: Address
6
+ sharedL2: Address
7
+ }
8
+
1
9
  export type ContractDeploymentType =
2
10
  | 'create'
3
11
  | 'create2'