viem 0.0.0-w-20230821171049 → 0.0.0-w-20230828183856

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 (244) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/actions/ens/getEnsAddress.js +2 -2
  3. package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
  4. package/dist/cjs/actions/index.js +8 -2
  5. package/dist/cjs/actions/index.js.map +1 -1
  6. package/dist/cjs/actions/public/estimateFeesPerGas.js +60 -0
  7. package/dist/cjs/actions/public/estimateFeesPerGas.js.map +1 -0
  8. package/dist/cjs/actions/public/estimateGas.js +2 -2
  9. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  10. package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js +44 -0
  11. package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
  12. package/dist/cjs/actions/public/verifyHash.js.map +1 -1
  13. package/dist/cjs/actions/public/verifyMessage.js.map +1 -1
  14. package/dist/cjs/actions/public/verifyTypedData.js.map +1 -1
  15. package/dist/cjs/actions/public/waitForTransactionReceipt.js +35 -30
  16. package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  17. package/dist/cjs/actions/public/watchContractEvent.js +10 -7
  18. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  19. package/dist/cjs/actions/wallet/deployContract.js.map +1 -1
  20. package/dist/cjs/actions/wallet/prepareTransactionRequest.js +70 -0
  21. package/dist/cjs/actions/wallet/prepareTransactionRequest.js.map +1 -0
  22. package/dist/cjs/actions/wallet/sendRawTransaction.js +11 -0
  23. package/dist/cjs/actions/wallet/sendRawTransaction.js.map +1 -0
  24. package/dist/cjs/actions/wallet/sendTransaction.js +6 -6
  25. package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
  26. package/dist/cjs/actions/wallet/signTransaction.js +47 -0
  27. package/dist/cjs/actions/wallet/signTransaction.js.map +1 -0
  28. package/dist/cjs/chains/celo/formatters.js +4 -1
  29. package/dist/cjs/chains/celo/formatters.js.map +1 -1
  30. package/dist/cjs/chains/celo/parsers.js +76 -0
  31. package/dist/cjs/chains/celo/parsers.js.map +1 -0
  32. package/dist/cjs/chains/celo/serializers.js +2 -1
  33. package/dist/cjs/chains/celo/serializers.js.map +1 -1
  34. package/dist/cjs/chains/index.js +3 -2
  35. package/dist/cjs/chains/index.js.map +1 -1
  36. package/dist/cjs/chains/utils.js +3 -1
  37. package/dist/cjs/chains/utils.js.map +1 -1
  38. package/dist/cjs/clients/createTestClient.js.map +1 -1
  39. package/dist/cjs/clients/decorators/public.js +8 -0
  40. package/dist/cjs/clients/decorators/public.js.map +1 -1
  41. package/dist/cjs/clients/decorators/wallet.js +6 -0
  42. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  43. package/dist/cjs/errors/fee.js +42 -0
  44. package/dist/cjs/errors/fee.js.map +1 -0
  45. package/dist/cjs/index.js +9 -6
  46. package/dist/cjs/index.js.map +1 -1
  47. package/dist/cjs/public.js +5 -1
  48. package/dist/cjs/public.js.map +1 -1
  49. package/dist/cjs/utils/data/isBytesEqual.js +4 -3
  50. package/dist/cjs/utils/data/isBytesEqual.js.map +1 -1
  51. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +2 -2
  52. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -1
  53. package/dist/cjs/utils/formatters/transactionRequest.js +9 -1
  54. package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
  55. package/dist/cjs/utils/index.js +3 -3
  56. package/dist/cjs/utils/index.js.map +1 -1
  57. package/dist/cjs/utils/rpc.js +5 -7
  58. package/dist/cjs/utils/rpc.js.map +1 -1
  59. package/dist/cjs/utils/transaction/parseTransaction.js +8 -3
  60. package/dist/cjs/utils/transaction/parseTransaction.js.map +1 -1
  61. package/dist/cjs/version.js +1 -1
  62. package/dist/esm/actions/ens/getEnsAddress.js +2 -2
  63. package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
  64. package/dist/esm/actions/index.js +3 -0
  65. package/dist/esm/actions/index.js.map +1 -1
  66. package/dist/esm/actions/public/estimateFeesPerGas.js +78 -0
  67. package/dist/esm/actions/public/estimateFeesPerGas.js.map +1 -0
  68. package/dist/esm/actions/public/estimateGas.js +2 -2
  69. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  70. package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js +64 -0
  71. package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
  72. package/dist/esm/actions/public/verifyHash.js.map +1 -1
  73. package/dist/esm/actions/public/verifyMessage.js.map +1 -1
  74. package/dist/esm/actions/public/verifyTypedData.js.map +1 -1
  75. package/dist/esm/actions/public/waitForTransactionReceipt.js +39 -34
  76. package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  77. package/dist/esm/actions/public/watchContractEvent.js +5 -2
  78. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  79. package/dist/esm/actions/wallet/deployContract.js.map +1 -1
  80. package/dist/esm/actions/wallet/prepareTransactionRequest.js +109 -0
  81. package/dist/esm/actions/wallet/prepareTransactionRequest.js.map +1 -0
  82. package/dist/esm/actions/wallet/sendRawTransaction.js +31 -0
  83. package/dist/esm/actions/wallet/sendRawTransaction.js.map +1 -0
  84. package/dist/esm/actions/wallet/sendTransaction.js +6 -6
  85. package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
  86. package/dist/esm/actions/wallet/signTransaction.js +87 -0
  87. package/dist/esm/actions/wallet/signTransaction.js.map +1 -0
  88. package/dist/esm/chains/celo/formatters.js +4 -1
  89. package/dist/esm/chains/celo/formatters.js.map +1 -1
  90. package/dist/esm/chains/celo/parsers.js +72 -0
  91. package/dist/esm/chains/celo/parsers.js.map +1 -0
  92. package/dist/esm/chains/celo/serializers.js +1 -3
  93. package/dist/esm/chains/celo/serializers.js.map +1 -1
  94. package/dist/esm/chains/index.js +1 -0
  95. package/dist/esm/chains/index.js.map +1 -1
  96. package/dist/esm/chains/utils.js +1 -0
  97. package/dist/esm/chains/utils.js.map +1 -1
  98. package/dist/esm/clients/createTestClient.js.map +1 -1
  99. package/dist/esm/clients/decorators/public.js +8 -0
  100. package/dist/esm/clients/decorators/public.js.map +1 -1
  101. package/dist/esm/clients/decorators/wallet.js +6 -0
  102. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  103. package/dist/esm/errors/fee.js +36 -0
  104. package/dist/esm/errors/fee.js.map +1 -0
  105. package/dist/esm/index.js +2 -2
  106. package/dist/esm/index.js.map +1 -1
  107. package/dist/esm/public.js +2 -0
  108. package/dist/esm/public.js.map +1 -1
  109. package/dist/esm/utils/data/isBytesEqual.js +2 -1
  110. package/dist/esm/utils/data/isBytesEqual.js.map +1 -1
  111. package/dist/esm/utils/ens/encodedLabelToLabelhash.js +1 -1
  112. package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -1
  113. package/dist/esm/utils/formatters/transactionRequest.js +8 -0
  114. package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
  115. package/dist/esm/utils/index.js +3 -1
  116. package/dist/esm/utils/index.js.map +1 -1
  117. package/dist/esm/utils/rpc.js +5 -7
  118. package/dist/esm/utils/rpc.js.map +1 -1
  119. package/dist/esm/utils/transaction/parseTransaction.js +6 -3
  120. package/dist/esm/utils/transaction/parseTransaction.js.map +1 -1
  121. package/dist/esm/version.js +1 -1
  122. package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
  123. package/dist/types/actions/index.d.ts +3 -0
  124. package/dist/types/actions/index.d.ts.map +1 -1
  125. package/dist/types/actions/public/estimateFeesPerGas.d.ts +48 -0
  126. package/dist/types/actions/public/estimateFeesPerGas.d.ts.map +1 -0
  127. package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts +37 -0
  128. package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -0
  129. package/dist/types/actions/public/verifyHash.d.ts +1 -1
  130. package/dist/types/actions/public/verifyHash.d.ts.map +1 -1
  131. package/dist/types/actions/public/verifyMessage.d.ts +2 -2
  132. package/dist/types/actions/public/verifyMessage.d.ts.map +1 -1
  133. package/dist/types/actions/public/verifyTypedData.d.ts +2 -2
  134. package/dist/types/actions/public/verifyTypedData.d.ts.map +1 -1
  135. package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  136. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  137. package/dist/types/actions/wallet/deployContract.d.ts +2 -1
  138. package/dist/types/actions/wallet/deployContract.d.ts.map +1 -1
  139. package/dist/types/actions/wallet/prepareTransactionRequest.d.ts +52 -0
  140. package/dist/types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -0
  141. package/dist/types/actions/wallet/sendRawTransaction.d.ts +38 -0
  142. package/dist/types/actions/wallet/sendRawTransaction.d.ts.map +1 -0
  143. package/dist/types/actions/wallet/sendTransaction.d.ts +2 -1
  144. package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
  145. package/dist/types/actions/wallet/signTransaction.d.ts +55 -0
  146. package/dist/types/actions/wallet/signTransaction.d.ts.map +1 -0
  147. package/dist/types/chains/celo/formatters.d.ts +503 -5
  148. package/dist/types/chains/celo/formatters.d.ts.map +1 -1
  149. package/dist/types/chains/celo/parsers.d.ts +6 -0
  150. package/dist/types/chains/celo/parsers.d.ts.map +1 -0
  151. package/dist/types/chains/celo/serializers.d.ts +3 -14
  152. package/dist/types/chains/celo/serializers.d.ts.map +1 -1
  153. package/dist/types/chains/celo/types.d.ts +54 -14
  154. package/dist/types/chains/celo/types.d.ts.map +1 -1
  155. package/dist/types/chains/index.d.ts +15876 -3730
  156. package/dist/types/chains/index.d.ts.map +1 -1
  157. package/dist/types/chains/utils.d.ts +3 -2
  158. package/dist/types/chains/utils.d.ts.map +1 -1
  159. package/dist/types/clients/createTestClient.d.ts +1 -1
  160. package/dist/types/clients/createTestClient.d.ts.map +1 -1
  161. package/dist/types/clients/decorators/public.d.ts +112 -0
  162. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  163. package/dist/types/clients/decorators/wallet.d.ts +111 -0
  164. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  165. package/dist/types/errors/fee.d.ts +16 -0
  166. package/dist/types/errors/fee.d.ts.map +1 -0
  167. package/dist/types/index.d.ts +23 -17
  168. package/dist/types/index.d.ts.map +1 -1
  169. package/dist/types/public.d.ts +2 -0
  170. package/dist/types/public.d.ts.map +1 -1
  171. package/dist/types/types/chain.d.ts +64 -11
  172. package/dist/types/types/chain.d.ts.map +1 -1
  173. package/dist/types/types/contract.d.ts +2 -2
  174. package/dist/types/types/contract.d.ts.map +1 -1
  175. package/dist/types/types/eip1193.d.ts +14 -2
  176. package/dist/types/types/eip1193.d.ts.map +1 -1
  177. package/dist/types/types/fee.d.ts +1 -0
  178. package/dist/types/types/fee.d.ts.map +1 -1
  179. package/dist/types/utils/chain.d.ts +2 -2
  180. package/dist/types/utils/chain.d.ts.map +1 -1
  181. package/dist/types/utils/data/isBytesEqual.d.ts +1 -1
  182. package/dist/types/utils/data/isBytesEqual.d.ts.map +1 -1
  183. package/dist/types/utils/ens/encodeLabelhash.d.ts +1 -1
  184. package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -1
  185. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +1 -1
  186. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -1
  187. package/dist/types/utils/formatters/transactionRequest.d.ts +5 -0
  188. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  189. package/dist/types/utils/index.d.ts +3 -1
  190. package/dist/types/utils/index.d.ts.map +1 -1
  191. package/dist/types/utils/rpc.d.ts +1 -1
  192. package/dist/types/utils/rpc.d.ts.map +1 -1
  193. package/dist/types/utils/transaction/parseTransaction.d.ts +5 -1
  194. package/dist/types/utils/transaction/parseTransaction.d.ts.map +1 -1
  195. package/dist/types/version.d.ts +1 -1
  196. package/package.json +1 -1
  197. package/src/actions/ens/getEnsAddress.ts +6 -8
  198. package/src/actions/index.ts +15 -0
  199. package/src/actions/public/estimateFeesPerGas.ts +154 -0
  200. package/src/actions/public/estimateGas.ts +5 -5
  201. package/src/actions/public/estimateMaxPriorityFeePerGas.ts +98 -0
  202. package/src/actions/public/verifyHash.ts +1 -1
  203. package/src/actions/public/verifyMessage.ts +3 -2
  204. package/src/actions/public/verifyTypedData.ts +3 -2
  205. package/src/actions/public/waitForTransactionReceipt.ts +48 -44
  206. package/src/actions/public/watchContractEvent.ts +9 -6
  207. package/src/actions/wallet/deployContract.ts +2 -1
  208. package/src/actions/wallet/prepareTransactionRequest.ts +179 -0
  209. package/src/actions/wallet/sendRawTransaction.ts +48 -0
  210. package/src/actions/wallet/sendTransaction.ts +8 -7
  211. package/src/actions/wallet/signTransaction.ts +137 -0
  212. package/src/chains/celo/formatters.ts +11 -12
  213. package/src/chains/celo/parsers.ts +123 -0
  214. package/src/chains/celo/serializers.ts +13 -34
  215. package/src/chains/celo/types.ts +114 -26
  216. package/src/chains/index.ts +1 -0
  217. package/src/chains/utils.ts +10 -6
  218. package/src/clients/createTestClient.ts +2 -1
  219. package/src/clients/decorators/public.ts +145 -0
  220. package/src/clients/decorators/wallet.ts +133 -0
  221. package/src/errors/fee.ts +27 -0
  222. package/src/errors/rpc.ts +1 -1
  223. package/src/index.ts +46 -25
  224. package/src/public.ts +10 -0
  225. package/src/types/chain.ts +80 -12
  226. package/src/types/contract.ts +2 -2
  227. package/src/types/eip1193.ts +14 -2
  228. package/src/types/fee.ts +2 -0
  229. package/src/utils/chain.ts +2 -2
  230. package/src/utils/data/isBytesEqual.ts +4 -1
  231. package/src/utils/ens/encodeLabelhash.ts +1 -1
  232. package/src/utils/ens/encodedLabelToLabelhash.ts +2 -2
  233. package/src/utils/formatters/transactionRequest.ts +10 -0
  234. package/src/utils/index.ts +4 -1
  235. package/src/utils/rpc.ts +5 -8
  236. package/src/utils/transaction/parseTransaction.ts +7 -9
  237. package/src/version.ts +1 -1
  238. package/dist/cjs/utils/transaction/prepareRequest.js +0 -64
  239. package/dist/cjs/utils/transaction/prepareRequest.js.map +0 -1
  240. package/dist/esm/utils/transaction/prepareRequest.js +0 -64
  241. package/dist/esm/utils/transaction/prepareRequest.js.map +0 -1
  242. package/dist/types/utils/transaction/prepareRequest.d.ts +0 -20
  243. package/dist/types/utils/transaction/prepareRequest.d.ts.map +0 -1
  244. package/src/utils/transaction/prepareRequest.ts +0 -143
@@ -1,5 +1,9 @@
1
- import type { TransactionSerializableEIP1559, TransactionSerializableEIP2930, TransactionSerializableLegacy, TransactionSerialized, TransactionType } from '../../types/transaction.js';
1
+ import type { Hex } from '../../types/misc.js';
2
+ import type { AccessList, TransactionSerializableEIP1559, TransactionSerializableEIP2930, TransactionSerializableLegacy, TransactionSerialized, TransactionType } from '../../types/transaction.js';
3
+ import type { RecursiveArray } from '../encoding/toRlp.js';
2
4
  import { type GetSerializedTransactionType } from './getSerializedTransactionType.js';
3
5
  export type ParseTransactionReturnType<TSerialized extends TransactionSerialized = TransactionSerialized, TType extends TransactionType = GetSerializedTransactionType<TSerialized>> = (TType extends 'eip1559' ? TransactionSerializableEIP1559 : never) | (TType extends 'eip2930' ? TransactionSerializableEIP2930 : never) | (TType extends 'legacy' ? TransactionSerializableLegacy : never);
4
6
  export declare function parseTransaction<TSerialized extends TransactionSerialized>(serializedTransaction: TSerialized): ParseTransactionReturnType<TSerialized>;
7
+ export declare function toTransactionArray(serializedTransaction: string): RecursiveArray<`0x${string}`>;
8
+ export declare function parseAccessList(accessList_: RecursiveArray<Hex>): AccessList;
5
9
  //# sourceMappingURL=parseTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseTransaction.d.ts","sourceRoot":"","sources":["../../../../src/utils/transaction/parseTransaction.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAIV,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,EAC7B,qBAAqB,EAGrB,eAAe,EAChB,MAAM,4BAA4B,CAAA;AAenC,OAAO,EACL,KAAK,4BAA4B,EAElC,MAAM,mCAAmC,CAAA;AAE1C,MAAM,MAAM,0BAA0B,CACpC,WAAW,SAAS,qBAAqB,GAAG,qBAAqB,EACjE,KAAK,SAAS,eAAe,GAAG,4BAA4B,CAAC,WAAW,CAAC,IAEvE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,QAAQ,GAAG,6BAA6B,GAAG,KAAK,CAAC,CAAA;AAEpE,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,qBAAqB,EACxE,qBAAqB,EAAE,WAAW,GACjC,0BAA0B,CAAC,WAAW,CAAC,CAgBzC"}
1
+ {"version":3,"file":"parseTransaction.d.ts","sourceRoot":"","sources":["../../../../src/utils/transaction/parseTransaction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EACV,UAAU,EAGV,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,EAC7B,qBAAqB,EAGrB,eAAe,EAChB,MAAM,4BAA4B,CAAA;AAOnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQ1D,OAAO,EACL,KAAK,4BAA4B,EAElC,MAAM,mCAAmC,CAAA;AAE1C,MAAM,MAAM,0BAA0B,CACpC,WAAW,SAAS,qBAAqB,GAAG,qBAAqB,EACjE,KAAK,SAAS,eAAe,GAAG,4BAA4B,CAAC,WAAW,CAAC,IAEvE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,QAAQ,GAAG,6BAA6B,GAAG,KAAK,CAAC,CAAA;AAEpE,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,qBAAqB,EACxE,qBAAqB,EAAE,WAAW,GACjC,0BAA0B,CAAC,WAAW,CAAC,CAgBzC;AAoMD,wBAAgB,kBAAkB,CAAC,qBAAqB,EAAE,MAAM,iCAE/D;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,UAAU,CAa5E"}
@@ -1,2 +1,2 @@
1
- export declare const version = "1.6.2";
1
+ export declare const version = "1.8.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "optional": true
22
22
  }
23
23
  },
24
- "version": "0.0.0-w-20230821171049",
24
+ "version": "0.0.0-w-20230828183856",
25
25
  "files": [
26
26
  "dist",
27
27
  "!dist/**/*.tsbuildinfo",
@@ -106,14 +106,12 @@ export async function getEnsAddress<TChain extends Chain | undefined,>(
106
106
 
107
107
  if (res[0] === '0x') return null
108
108
 
109
- const address = trim(
110
- decodeFunctionResult({
111
- abi: addressResolverAbi,
112
- args: coinType != null ? [namehash(name), BigInt(coinType)] : undefined,
113
- functionName: 'addr',
114
- data: res[0],
115
- }),
116
- )
109
+ const address = decodeFunctionResult({
110
+ abi: addressResolverAbi,
111
+ args: coinType != null ? [namehash(name), BigInt(coinType)] : undefined,
112
+ functionName: 'addr',
113
+ data: res[0],
114
+ })
117
115
 
118
116
  if (address === '0x') return null
119
117
  if (trim(address) === '0x00') return null
@@ -224,11 +224,26 @@ export {
224
224
  } from './test/inspectTxpool.js'
225
225
  export { type ResetParameters, reset } from './test/reset.js'
226
226
  export { type RevertParameters, revert } from './test/revert.js'
227
+ export {
228
+ type PrepareTransactionRequestParameters,
229
+ type PrepareTransactionRequestReturnType,
230
+ prepareTransactionRequest,
231
+ } from './wallet/prepareTransactionRequest.js'
227
232
  export {
228
233
  type SendTransactionParameters,
229
234
  type SendTransactionReturnType,
230
235
  sendTransaction,
231
236
  } from './wallet/sendTransaction.js'
237
+ export {
238
+ type SignTransactionParameters,
239
+ type SignTransactionReturnType,
240
+ signTransaction,
241
+ } from './wallet/signTransaction.js'
242
+ export {
243
+ type SendRawTransactionParameters,
244
+ type SendRawTransactionReturnType,
245
+ sendRawTransaction,
246
+ } from './wallet/sendRawTransaction.js'
232
247
  export {
233
248
  type SendUnsignedTransactionParameters,
234
249
  type SendUnsignedTransactionReturnType,
@@ -0,0 +1,154 @@
1
+ import type { Client } from '../../clients/createClient.js'
2
+ import type { Transport } from '../../clients/transports/createTransport.js'
3
+ import {
4
+ BaseFeeScalarError,
5
+ Eip1559FeesNotSupportedError,
6
+ } from '../../errors/fee.js'
7
+ import type { Block } from '../../types/block.js'
8
+ import type {
9
+ Chain,
10
+ ChainEstimateFeesPerGasFnParameters,
11
+ ChainFeesFnParameters,
12
+ } from '../../types/chain.js'
13
+ import type { GetChain } from '../../types/chain.js'
14
+ import type {
15
+ FeeValuesEIP1559,
16
+ FeeValuesLegacy,
17
+ FeeValuesType,
18
+ } from '../../types/fee.js'
19
+ import type { PrepareTransactionRequestParameters } from '../wallet/prepareTransactionRequest.js'
20
+ import { internal_estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js'
21
+ import { getBlock } from './getBlock.js'
22
+ import { getGasPrice } from './getGasPrice.js'
23
+
24
+ export type EstimateFeesPerGasParameters<
25
+ chain extends Chain | undefined = Chain | undefined,
26
+ chainOverride extends Chain | undefined = Chain | undefined,
27
+ type extends FeeValuesType = FeeValuesType,
28
+ > = {
29
+ /**
30
+ * The type of fee values to return.
31
+ *
32
+ * - `legacy`: Returns the legacy gas price.
33
+ * - `eip1559`: Returns the max fee per gas and max priority fee per gas.
34
+ *
35
+ * @default 'eip1559'
36
+ */
37
+ type?: type | FeeValuesType
38
+ } & GetChain<chain, chainOverride>
39
+
40
+ export type EstimateFeesPerGasReturnType<
41
+ type extends FeeValuesType = FeeValuesType,
42
+ > =
43
+ | (type extends 'legacy' ? FeeValuesLegacy : never)
44
+ | (type extends 'eip1559' ? FeeValuesEIP1559 : never)
45
+
46
+ /**
47
+ * Returns an estimate for the fees per gas (in wei) for a
48
+ * transaction to be likely included in the next block.
49
+ * Defaults to [`chain.fees.estimateFeesPerGas`](/docs/clients/chains.html#fees-estimatefeespergas) if set.
50
+ *
51
+ * - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas.html
52
+ *
53
+ * @param client - Client to use
54
+ * @param parameters - {@link EstimateFeesPerGasParameters}
55
+ * @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType}
56
+ *
57
+ * @example
58
+ * import { createPublicClient, http } from 'viem'
59
+ * import { mainnet } from 'viem/chains'
60
+ * import { estimateFeesPerGas } from 'viem/actions'
61
+ *
62
+ * const client = createPublicClient({
63
+ * chain: mainnet,
64
+ * transport: http(),
65
+ * })
66
+ * const maxPriorityFeePerGas = await estimateFeesPerGas(client)
67
+ * // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
68
+ */
69
+ export async function estimateFeesPerGas<
70
+ chain extends Chain | undefined,
71
+ chainOverride extends Chain | undefined,
72
+ type extends FeeValuesType = 'eip1559',
73
+ >(
74
+ client: Client<Transport, chain>,
75
+ args?: EstimateFeesPerGasParameters<chain, chainOverride, type>,
76
+ ): Promise<EstimateFeesPerGasReturnType<type>> {
77
+ return internal_estimateFeesPerGas(client, args as any)
78
+ }
79
+
80
+ export async function internal_estimateFeesPerGas<
81
+ chain extends Chain | undefined,
82
+ chainOverride extends Chain | undefined,
83
+ type extends FeeValuesType = 'eip1559',
84
+ >(
85
+ client: Client<Transport, chain>,
86
+ args: EstimateFeesPerGasParameters<chain, chainOverride, type> & {
87
+ block?: Block
88
+ request?: PrepareTransactionRequestParameters
89
+ },
90
+ ): Promise<EstimateFeesPerGasReturnType<type>> {
91
+ const {
92
+ block: block_,
93
+ chain = client.chain,
94
+ request,
95
+ type = 'eip1559',
96
+ } = args || {}
97
+
98
+ const baseFeeMultiplier = await (async () => {
99
+ if (typeof chain?.fees?.baseFeeMultiplier === 'function')
100
+ return chain.fees.baseFeeMultiplier({
101
+ block: block_ as Block,
102
+ client,
103
+ request,
104
+ } as ChainFeesFnParameters)
105
+ return chain?.fees?.baseFeeMultiplier ?? 1.2
106
+ })()
107
+ if (baseFeeMultiplier < 1) throw new BaseFeeScalarError()
108
+
109
+ const decimals = baseFeeMultiplier.toString().split('.')[1].length
110
+ const denominator = 10 ** decimals
111
+ const multiply = (base: bigint) =>
112
+ (base * BigInt(baseFeeMultiplier * denominator)) / BigInt(denominator)
113
+
114
+ const block = block_ ? block_ : await getBlock(client)
115
+
116
+ if (typeof chain?.fees?.estimateFeesPerGas === 'function')
117
+ return chain.fees.estimateFeesPerGas({
118
+ block: block_ as Block,
119
+ client,
120
+ multiply,
121
+ request,
122
+ type,
123
+ } as ChainEstimateFeesPerGasFnParameters) as unknown as EstimateFeesPerGasReturnType<type>
124
+
125
+ if (type === 'eip1559') {
126
+ if (typeof block.baseFeePerGas !== 'bigint')
127
+ throw new Eip1559FeesNotSupportedError()
128
+
129
+ const maxPriorityFeePerGas = request?.maxPriorityFeePerGas
130
+ ? request.maxPriorityFeePerGas
131
+ : await internal_estimateMaxPriorityFeePerGas(
132
+ client as Client<Transport, Chain>,
133
+ {
134
+ block,
135
+ chain,
136
+ request,
137
+ },
138
+ )
139
+
140
+ const baseFeePerGas = multiply(block.baseFeePerGas)
141
+ const maxFeePerGas =
142
+ request?.maxFeePerGas ?? baseFeePerGas + maxPriorityFeePerGas
143
+
144
+ return {
145
+ maxFeePerGas,
146
+ maxPriorityFeePerGas,
147
+ } as EstimateFeesPerGasReturnType<type>
148
+ }
149
+
150
+ const gasPrice = request?.gasPrice ?? multiply(await getGasPrice(client))
151
+ return {
152
+ gasPrice,
153
+ } as EstimateFeesPerGasReturnType<type>
154
+ }
@@ -21,9 +21,9 @@ import {
21
21
  assertRequest,
22
22
  } from '../../utils/transaction/assertRequest.js'
23
23
  import {
24
- type PrepareRequestParameters,
25
- prepareRequest,
26
- } from '../../utils/transaction/prepareRequest.js'
24
+ type PrepareTransactionRequestParameters,
25
+ prepareTransactionRequest,
26
+ } from '../wallet/prepareTransactionRequest.js'
27
27
 
28
28
  export type FormattedEstimateGas<
29
29
  TChain extends Chain | undefined = Chain | undefined,
@@ -107,9 +107,9 @@ export async function estimateGas<
107
107
  ...rest
108
108
  } =
109
109
  account.type === 'local'
110
- ? ((await prepareRequest(
110
+ ? ((await prepareTransactionRequest(
111
111
  client,
112
- args as PrepareRequestParameters,
112
+ args as PrepareTransactionRequestParameters,
113
113
  )) as EstimateGasParameters)
114
114
  : args
115
115
 
@@ -0,0 +1,98 @@
1
+ import type { Client } from '../../clients/createClient.js'
2
+ import type { Transport } from '../../clients/transports/createTransport.js'
3
+ import { Eip1559FeesNotSupportedError } from '../../errors/fee.js'
4
+ import type { Account } from '../../types/account.js'
5
+ import type { Block } from '../../types/block.js'
6
+ import type { Chain, ChainFeesFnParameters } from '../../types/chain.js'
7
+ import type { GetChain } from '../../types/chain.js'
8
+ import { hexToBigInt } from '../../utils/encoding/fromHex.js'
9
+ import type { PrepareTransactionRequestParameters } from '../wallet/prepareTransactionRequest.js'
10
+ import { getBlock } from './getBlock.js'
11
+ import { getGasPrice } from './getGasPrice.js'
12
+
13
+ export type EstimateMaxPriorityFeePerGasParameters<
14
+ chain extends Chain | undefined = Chain | undefined,
15
+ chainOverride extends Chain | undefined = Chain | undefined,
16
+ > = GetChain<chain, chainOverride>
17
+ export type EstimateMaxPriorityFeePerGasReturnType = bigint
18
+
19
+ /**
20
+ * Returns an estimate for the max priority fee per gas (in wei) for a
21
+ * transaction to be likely included in the next block.
22
+ * Defaults to [`chain.fees.defaultPriorityFee`](/docs/clients/chains.html#fees-defaultpriorityfee) if set.
23
+ *
24
+ * - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas.html
25
+ *
26
+ * @param client - Client to use
27
+ * @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType}
28
+ *
29
+ * @example
30
+ * import { createPublicClient, http } from 'viem'
31
+ * import { mainnet } from 'viem/chains'
32
+ * import { estimateMaxPriorityFeePerGas } from 'viem/actions'
33
+ *
34
+ * const client = createPublicClient({
35
+ * chain: mainnet,
36
+ * transport: http(),
37
+ * })
38
+ * const maxPriorityFeePerGas = await estimateMaxPriorityFeePerGas(client)
39
+ * // 10000000n
40
+ */
41
+ export async function estimateMaxPriorityFeePerGas<
42
+ chain extends Chain | undefined,
43
+ chainOverride extends Chain | undefined,
44
+ >(
45
+ client: Client<Transport, chain>,
46
+ args?: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride>,
47
+ ): Promise<EstimateMaxPriorityFeePerGasReturnType> {
48
+ return internal_estimateMaxPriorityFeePerGas(client, args as any)
49
+ }
50
+
51
+ export async function internal_estimateMaxPriorityFeePerGas<
52
+ chain extends Chain | undefined,
53
+ chainOverride extends Chain | undefined,
54
+ >(
55
+ client: Client<Transport, chain>,
56
+ args: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride> & {
57
+ block?: Block
58
+ request?: PrepareTransactionRequestParameters<
59
+ chain,
60
+ Account | undefined,
61
+ chainOverride
62
+ >
63
+ },
64
+ ): Promise<EstimateMaxPriorityFeePerGasReturnType> {
65
+ const { block: block_, chain = client.chain, request } = args || {}
66
+ if (typeof chain?.fees?.defaultPriorityFee === 'function') {
67
+ const block = block_ || (await getBlock(client))
68
+ return chain.fees.defaultPriorityFee({
69
+ block,
70
+ client,
71
+ request,
72
+ } as ChainFeesFnParameters)
73
+ } else if (chain?.fees?.defaultPriorityFee)
74
+ return chain?.fees?.defaultPriorityFee
75
+
76
+ try {
77
+ const maxPriorityFeePerGasHex = await client.request({
78
+ method: 'eth_maxPriorityFeePerGas',
79
+ })
80
+ return hexToBigInt(maxPriorityFeePerGasHex)
81
+ } catch {
82
+ // If the RPC Provider does not support `eth_maxPriorityFeePerGas`
83
+ // fall back to calculating it manually via `gasPrice - baseFeePerGas`.
84
+ // See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
85
+ const [block, gasPrice] = await Promise.all([
86
+ block_ ? Promise.resolve(block_) : getBlock(client),
87
+ getGasPrice(client),
88
+ ])
89
+
90
+ if (typeof block.baseFeePerGas !== 'bigint')
91
+ throw new Eip1559FeesNotSupportedError()
92
+
93
+ const maxPriorityFeePerGas = gasPrice - block.baseFeePerGas
94
+
95
+ if (maxPriorityFeePerGas < 0n) return 0n
96
+ return maxPriorityFeePerGas
97
+ }
98
+ }
@@ -1,11 +1,11 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
- import type { Chain } from '../../chains/index.js'
4
3
  import type { Client } from '../../clients/createClient.js'
5
4
  import type { Transport } from '../../clients/transports/createTransport.js'
6
5
  import { universalSignatureValidatorAbi } from '../../constants/abis.js'
7
6
  import { universalSignatureValidatorByteCode } from '../../constants/contracts.js'
8
7
  import { CallExecutionError } from '../../errors/contract.js'
8
+ import type { Chain } from '../../types/chain.js'
9
9
  import type { ByteArray, Hex } from '../../types/misc.js'
10
10
  import { isBytesEqual } from '../../utils/data/isBytesEqual.js'
11
11
  import { encodeDeployData, isHex, toHex } from '../../utils/index.js'
@@ -1,10 +1,11 @@
1
- import type { Chain } from '../../chains/index.js'
1
+ import type { Address } from 'abitype'
2
+
2
3
  import type { Client } from '../../clients/createClient.js'
3
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { Chain } from '../../types/chain.js'
4
6
  import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js'
5
7
  import { hashMessage } from '../../utils/index.js'
6
8
  import { type VerifyHashParameters, verifyHash } from './verifyHash.js'
7
- import type { Address } from 'abitype'
8
9
 
9
10
  export type VerifyMessageParameters = Omit<VerifyHashParameters, 'hash'> & {
10
11
  /** The address that signed the original message. */
@@ -1,11 +1,12 @@
1
- import type { Chain } from '../../chains/index.js'
1
+ import type { Address, TypedData } from 'abitype'
2
+
2
3
  import type { Client } from '../../clients/createClient.js'
3
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { Chain } from '../../types/chain.js'
4
6
  import type { ByteArray, Hex } from '../../types/misc.js'
5
7
  import type { TypedDataDefinition } from '../../types/typedData.js'
6
8
  import { hashTypedData } from '../../utils/signature/hashTypedData.js'
7
9
  import { type VerifyHashParameters, verifyHash } from './verifyHash.js'
8
- import type { Address, TypedData } from 'abitype'
9
10
 
10
11
  export type VerifyTypedDataParameters<
11
12
  TTypedData extends TypedData | { [key: string]: unknown } = TypedData,
@@ -192,56 +192,60 @@ export async function waitForTransactionReceipt<
192
192
  (err instanceof TransactionNotFoundError ||
193
193
  err instanceof TransactionReceiptNotFoundError)
194
194
  ) {
195
- replacedTransaction = transaction
196
-
197
- // Let's retrieve the transactions from the current block.
198
- const block = await getBlock(client, {
199
- blockNumber,
200
- includeTransactions: true,
201
- })
202
-
203
- const replacementTransaction = (
204
- block.transactions as Transaction[]
205
- ).find(
206
- ({ from, nonce }) =>
207
- from === replacedTransaction!.from &&
208
- nonce === replacedTransaction!.nonce,
209
- )
195
+ try {
196
+ replacedTransaction = transaction
210
197
 
211
- // If we couldn't find a replacement transaction, continue polling.
212
- if (!replacementTransaction) return
198
+ // Let's retrieve the transactions from the current block.
199
+ const block = await getBlock(client, {
200
+ blockNumber,
201
+ includeTransactions: true,
202
+ })
213
203
 
214
- // If we found a replacement transaction, return it's receipt.
215
- receipt = await getTransactionReceipt(client, {
216
- hash: replacementTransaction.hash,
217
- })
204
+ const replacementTransaction = (
205
+ block.transactions as Transaction[]
206
+ ).find(
207
+ ({ from, nonce }) =>
208
+ from === replacedTransaction!.from &&
209
+ nonce === replacedTransaction!.nonce,
210
+ )
218
211
 
219
- // Check if we have enough confirmations. If not, continue polling.
220
- if (blockNumber - receipt.blockNumber + 1n < confirmations)
221
- return
212
+ // If we couldn't find a replacement transaction, continue polling.
213
+ if (!replacementTransaction) return
222
214
 
223
- let reason: ReplacementReason = 'replaced'
224
- if (
225
- replacementTransaction.to === replacedTransaction.to &&
226
- replacementTransaction.value === replacedTransaction.value
227
- ) {
228
- reason = 'repriced'
229
- } else if (
230
- replacementTransaction.from === replacementTransaction.to &&
231
- replacementTransaction.value === 0n
232
- ) {
233
- reason = 'cancelled'
234
- }
215
+ // If we found a replacement transaction, return it's receipt.
216
+ receipt = await getTransactionReceipt(client, {
217
+ hash: replacementTransaction.hash,
218
+ })
219
+
220
+ // Check if we have enough confirmations. If not, continue polling.
221
+ if (blockNumber - receipt.blockNumber + 1n < confirmations)
222
+ return
235
223
 
236
- done(() => {
237
- emit.onReplaced?.({
238
- reason,
239
- replacedTransaction: replacedTransaction!,
240
- transaction: replacementTransaction,
241
- transactionReceipt: receipt,
224
+ let reason: ReplacementReason = 'replaced'
225
+ if (
226
+ replacementTransaction.to === replacedTransaction.to &&
227
+ replacementTransaction.value === replacedTransaction.value
228
+ ) {
229
+ reason = 'repriced'
230
+ } else if (
231
+ replacementTransaction.from === replacementTransaction.to &&
232
+ replacementTransaction.value === 0n
233
+ ) {
234
+ reason = 'cancelled'
235
+ }
236
+
237
+ done(() => {
238
+ emit.onReplaced?.({
239
+ reason,
240
+ replacedTransaction: replacedTransaction!,
241
+ transaction: replacementTransaction,
242
+ transactionReceipt: receipt,
243
+ })
244
+ emit.resolve(receipt)
242
245
  })
243
- emit.resolve(receipt)
244
- })
246
+ } catch (err_) {
247
+ done(() => emit.reject(err_))
248
+ }
245
249
  } else {
246
250
  done(() => emit.reject(err))
247
251
  }
@@ -2,7 +2,6 @@ import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
- import type { EncodeEventTopicsParameters, LogTopic } from '../../index.js'
6
5
  import type { Chain } from '../../types/chain.js'
7
6
  import type { GetEventArgs, InferEventName } from '../../types/contract.js'
8
7
  import type { Filter } from '../../types/filter.js'
@@ -17,14 +16,18 @@ import { observe } from '../../utils/observe.js'
17
16
  import { poll } from '../../utils/poll.js'
18
17
  import { stringify } from '../../utils/stringify.js'
19
18
 
20
- import { DecodeLogDataMismatch } from '../../errors/abi.js'
21
19
  import {
20
+ DecodeLogDataMismatch,
22
21
  DecodeLogTopicsMismatch,
23
- InvalidInputRpcError,
24
- decodeEventLog,
22
+ } from '../../errors/abi.js'
23
+ import { InvalidInputRpcError } from '../../errors/rpc.js'
24
+ import type { LogTopic } from '../../types/misc.js'
25
+ import { decodeEventLog } from '../../utils/abi/decodeEventLog.js'
26
+ import {
27
+ type EncodeEventTopicsParameters,
25
28
  encodeEventTopics,
26
- formatLog,
27
- } from '../../index.js'
29
+ } from '../../utils/abi/encodeEventTopics.js'
30
+ import { formatLog } from '../../utils/formatters/log.js'
28
31
  import {
29
32
  type CreateContractEventFilterParameters,
30
33
  createContractEventFilter,
@@ -3,7 +3,8 @@ import type { Abi } from 'abitype'
3
3
  import type { Account } from '../../accounts/types.js'
4
4
  import type { Client } from '../../clients/createClient.js'
5
5
  import type { Transport } from '../../clients/transports/createTransport.js'
6
- import type { Chain, GetChain } from '../../types/chain.js'
6
+ import type { Chain } from '../../types/chain.js'
7
+ import type { GetChain } from '../../types/chain.js'
7
8
  import type { GetConstructorArgs } from '../../types/contract.js'
8
9
  import type { Hex } from '../../types/misc.js'
9
10
  import type { UnionOmit } from '../../types/utils.js'