viem 0.0.1-alpha.19 → 0.0.1-alpha.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 (151) hide show
  1. package/dist/{rpc-858670f1.d.ts → chain-32f56cfa.d.ts} +68 -18
  2. package/dist/chain-f12cdc7f.d.ts +5 -0
  3. package/dist/chains.d.ts +757 -170
  4. package/dist/chains.js +80 -86
  5. package/dist/chains.js.map +1 -1
  6. package/dist/chains.mjs +120 -126
  7. package/dist/chains.mjs.map +1 -1
  8. package/dist/{chunk-PHSAQQGZ.mjs → chunk-5Q6FSUU2.mjs} +75 -37
  9. package/dist/chunk-5Q6FSUU2.mjs.map +1 -0
  10. package/dist/{chunk-24EKKMUO.js → chunk-FHXXG7I6.js} +12 -12
  11. package/dist/chunk-FHXXG7I6.js.map +1 -0
  12. package/dist/{chunk-HRE6LYF3.js → chunk-IAQPMSGJ.js} +13 -13
  13. package/dist/chunk-IAQPMSGJ.js.map +1 -0
  14. package/dist/{chunk-IVWG22RQ.mjs → chunk-MYQNZSWD.mjs} +69 -12
  15. package/dist/chunk-MYQNZSWD.mjs.map +1 -0
  16. package/dist/{chunk-NYMS65YI.js → chunk-NHAKUPTF.js} +124 -67
  17. package/dist/chunk-NHAKUPTF.js.map +1 -0
  18. package/dist/{chunk-BZFF747V.js → chunk-SF4I2NKC.js} +81 -43
  19. package/dist/chunk-SF4I2NKC.js.map +1 -0
  20. package/dist/{chunk-VAT5CEF7.mjs → chunk-T7CBAKLI.mjs} +2 -2
  21. package/dist/chunk-T7CBAKLI.mjs.map +1 -0
  22. package/dist/{chunk-CTU4PQLY.js → chunk-YFKR74XG.js} +14 -14
  23. package/dist/{chunk-CTU4PQLY.js.map → chunk-YFKR74XG.js.map} +0 -0
  24. package/dist/{chunk-NSRORL3O.mjs → chunk-YODUQCHJ.mjs} +2 -2
  25. package/dist/{chunk-NSRORL3O.mjs.map → chunk-YODUQCHJ.mjs.map} +0 -0
  26. package/dist/{chunk-E7LH5H76.mjs → chunk-ZVGTYLKU.mjs} +2 -2
  27. package/dist/chunk-ZVGTYLKU.mjs.map +1 -0
  28. package/dist/clients/index.d.ts +7 -8
  29. package/dist/clients/index.js +3 -3
  30. package/dist/clients/index.mjs +2 -2
  31. package/dist/{transactionReceipt-aed524b4.d.ts → contract-9af4608b.d.ts} +30 -18
  32. package/dist/{createClient-03ba79e8.d.ts → createClient-5d316c7e.d.ts} +2 -2
  33. package/dist/{createPublicClient-818241ba.d.ts → createPublicClient-9d2b42e1.d.ts} +3 -3
  34. package/dist/{createTestClient-24eb7be8.d.ts → createTestClient-79498dab.d.ts} +3 -3
  35. package/dist/{createWalletClient-7cbd6ad1.d.ts → createWalletClient-f69a5230.d.ts} +3 -3
  36. package/dist/{eip1193-71d8e27d.d.ts → eip1193-6c485d63.d.ts} +1 -1
  37. package/dist/index.d.ts +45 -23
  38. package/dist/index.js +10 -6
  39. package/dist/index.mjs +9 -5
  40. package/dist/{parseGwei-dbd12305.d.ts → parseGwei-4308ad80.d.ts} +17 -4
  41. package/dist/public.d.ts +9 -10
  42. package/dist/public.js +4 -4
  43. package/dist/public.mjs +3 -3
  44. package/dist/{sendTransaction-d09961a7.d.ts → sendTransaction-1c8290a9.d.ts} +3 -4
  45. package/dist/{stopImpersonatingAccount-c8a00be7.d.ts → stopImpersonatingAccount-7781842a.d.ts} +2 -2
  46. package/dist/test.d.ts +5 -6
  47. package/dist/test.js +3 -3
  48. package/dist/test.mjs +2 -2
  49. package/dist/transactionRequest-341b6ed2.d.ts +15 -0
  50. package/dist/utils/index.d.ts +9 -8
  51. package/dist/utils/index.js +22 -2
  52. package/dist/utils/index.mjs +25 -5
  53. package/dist/wallet.d.ts +7 -8
  54. package/dist/wallet.js +3 -3
  55. package/dist/wallet.mjs +2 -2
  56. package/dist/{watchAsset-c39645b7.d.ts → watchAsset-afaad3c7.d.ts} +3 -4
  57. package/dist/{watchPendingTransactions-01e6be4f.d.ts → watchPendingTransactions-3b722547.d.ts} +21 -16
  58. package/dist/{webSocket-3a00015b.d.ts → webSocket-b180e679.d.ts} +2 -2
  59. package/dist/window.d.ts +3 -2
  60. package/package.json +3 -3
  61. package/src/_test/abis.ts +188 -0
  62. package/src/_test/constants.ts +0 -3
  63. package/src/_test/index.ts +5 -2
  64. package/src/actions/index.test.ts +2 -0
  65. package/src/actions/index.ts +6 -0
  66. package/src/actions/public/call.ts +2 -1
  67. package/src/actions/public/createContractEventFilter.test.ts +119 -0
  68. package/src/actions/public/createContractEventFilter.ts +69 -0
  69. package/src/actions/public/createEventFilter.ts +5 -8
  70. package/src/actions/public/deployContract.ts +1 -2
  71. package/src/actions/public/getBlock.test.ts +3 -3
  72. package/src/actions/public/getBlock.ts +1 -2
  73. package/src/actions/public/getBlockTransactionCount.ts +1 -2
  74. package/src/actions/public/getFilterChanges.test.ts +9 -7
  75. package/src/actions/public/getFilterLogs.test.ts +7 -5
  76. package/src/actions/public/getLogs.test.ts +7 -5
  77. package/src/actions/public/getLogs.ts +3 -2
  78. package/src/actions/public/getTransaction.ts +1 -2
  79. package/src/actions/public/getTransactionConfirmations.ts +1 -2
  80. package/src/actions/public/getTransactionReceipt.test.ts +24 -62
  81. package/src/actions/public/getTransactionReceipt.ts +1 -2
  82. package/src/actions/public/index.test.ts +4 -0
  83. package/src/actions/public/index.ts +18 -0
  84. package/src/actions/public/readContract.ts +1 -1
  85. package/src/actions/public/simulateContract.ts +1 -1
  86. package/src/actions/public/waitForTransactionReceipt.ts +1 -2
  87. package/src/actions/public/watchBlocks.test.ts +27 -2
  88. package/src/actions/public/watchBlocks.ts +33 -14
  89. package/src/actions/public/watchContractEvent.test.ts +301 -0
  90. package/src/actions/public/watchContractEvent.ts +108 -0
  91. package/src/actions/public/watchEvent.test.ts +190 -0
  92. package/src/actions/public/watchEvent.ts +95 -0
  93. package/src/actions/public/watchPendingTransactions.ts +1 -0
  94. package/src/actions/wallet/addChain.ts +1 -1
  95. package/src/actions/wallet/sendTransaction.ts +2 -1
  96. package/src/actions/wallet/switchChain.ts +1 -1
  97. package/src/actions/wallet/writeContract.ts +1 -1
  98. package/src/chains.test.ts +830 -52
  99. package/src/chains.ts +90 -158
  100. package/src/clients/createClient.ts +1 -1
  101. package/src/clients/createPublicClient.ts +1 -1
  102. package/src/clients/createTestClient.ts +1 -1
  103. package/src/clients/createWalletClient.ts +1 -1
  104. package/src/clients/transports/createTransport.ts +1 -1
  105. package/src/index.test.ts +2 -0
  106. package/src/index.ts +10 -2
  107. package/src/types/chain.ts +6 -0
  108. package/src/types/contract.ts +17 -2
  109. package/src/types/formatter.ts +23 -0
  110. package/src/types/index.ts +6 -0
  111. package/src/types/transaction.ts +1 -1
  112. package/src/utils/abi/decodeErrorResult.ts +2 -2
  113. package/src/utils/abi/decodeFunctionData.ts +2 -2
  114. package/src/utils/abi/encodeErrorResult.ts +2 -2
  115. package/src/utils/abi/encodeEventTopics.ts +4 -4
  116. package/src/utils/abi/encodeFunctionData.ts +2 -2
  117. package/src/utils/abi/{formatAbiItemWithParams.test.ts → formatAbiItem.test.ts} +11 -11
  118. package/src/utils/abi/{formatAbiItemWithParams.ts → formatAbiItem.ts} +1 -1
  119. package/src/utils/abi/index.test.ts +1 -1
  120. package/src/utils/abi/index.ts +1 -1
  121. package/src/utils/chain.test.ts +43 -0
  122. package/src/utils/chain.ts +8 -0
  123. package/src/utils/contract/getContractError.ts +2 -6
  124. package/src/utils/formatters/block.ts +4 -3
  125. package/src/utils/formatters/extract.ts +1 -1
  126. package/src/utils/formatters/format.ts +39 -2
  127. package/src/utils/formatters/index.test.ts +10 -0
  128. package/src/utils/formatters/index.ts +15 -5
  129. package/src/utils/formatters/transaction.ts +16 -4
  130. package/src/utils/formatters/transactionReceipt.ts +13 -4
  131. package/src/utils/formatters/transactionRequest.ts +12 -3
  132. package/src/utils/hash/getEventSignature.ts +2 -2
  133. package/src/utils/index.test.ts +24 -1
  134. package/src/utils/index.ts +12 -1
  135. package/src/{constants.test.ts → utils/unit/constants.test.ts} +0 -5
  136. package/src/{constants.ts → utils/unit/constants.ts} +0 -6
  137. package/src/utils/unit/formatEther.ts +1 -1
  138. package/src/utils/unit/formatGwei.ts +1 -1
  139. package/src/utils/unit/index.test.ts +12 -0
  140. package/src/utils/unit/index.ts +1 -0
  141. package/src/utils/unit/parseEther.ts +1 -1
  142. package/src/utils/unit/parseGwei.ts +1 -1
  143. package/dist/chunk-24EKKMUO.js.map +0 -1
  144. package/dist/chunk-BZFF747V.js.map +0 -1
  145. package/dist/chunk-E7LH5H76.mjs.map +0 -1
  146. package/dist/chunk-HRE6LYF3.js.map +0 -1
  147. package/dist/chunk-IVWG22RQ.mjs.map +0 -1
  148. package/dist/chunk-NYMS65YI.js.map +0 -1
  149. package/dist/chunk-PHSAQQGZ.mjs.map +0 -1
  150. package/dist/chunk-VAT5CEF7.mjs.map +0 -1
  151. package/dist/transactionRequest-8e970b0e.d.ts +0 -33
@@ -1,11 +1,11 @@
1
1
  import { expect, test } from 'vitest'
2
2
 
3
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
3
+ import { formatAbiItem } from './formatAbiItem'
4
4
 
5
5
  test('foo()', () => {
6
6
  expect(
7
7
  // @ts-expect-error
8
- formatAbiItemWithParams({
8
+ formatAbiItem({
9
9
  name: 'foo',
10
10
  outputs: [],
11
11
  stateMutability: 'nonpayable',
@@ -13,7 +13,7 @@ test('foo()', () => {
13
13
  }),
14
14
  ).toEqual('foo()')
15
15
  expect(
16
- formatAbiItemWithParams({
16
+ formatAbiItem({
17
17
  inputs: [],
18
18
  name: 'foo',
19
19
  outputs: [],
@@ -25,7 +25,7 @@ test('foo()', () => {
25
25
 
26
26
  test('foo(uint256)', () => {
27
27
  expect(
28
- formatAbiItemWithParams({
28
+ formatAbiItem({
29
29
  inputs: [
30
30
  {
31
31
  internalType: 'uint256',
@@ -40,7 +40,7 @@ test('foo(uint256)', () => {
40
40
  }),
41
41
  ).toEqual('foo(uint256)')
42
42
  expect(
43
- formatAbiItemWithParams(
43
+ formatAbiItem(
44
44
  {
45
45
  inputs: [
46
46
  {
@@ -61,7 +61,7 @@ test('foo(uint256)', () => {
61
61
 
62
62
  test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
63
63
  expect(
64
- formatAbiItemWithParams({
64
+ formatAbiItem({
65
65
  inputs: [
66
66
  {
67
67
  components: [
@@ -108,7 +108,7 @@ test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
108
108
  }),
109
109
  ).toEqual('getVoter((uint256,bool,address,uint256),string[],bytes)')
110
110
  expect(
111
- formatAbiItemWithParams(
111
+ formatAbiItem(
112
112
  {
113
113
  inputs: [
114
114
  {
@@ -163,7 +163,7 @@ test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
163
163
 
164
164
  test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
165
165
  expect(
166
- formatAbiItemWithParams({
166
+ formatAbiItem({
167
167
  inputs: [
168
168
  {
169
169
  components: [
@@ -210,7 +210,7 @@ test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
210
210
  }),
211
211
  ).toEqual('VoterEvent((uint256,bool,address,uint256),string[],bytes)')
212
212
  expect(
213
- formatAbiItemWithParams(
213
+ formatAbiItem(
214
214
  {
215
215
  inputs: [
216
216
  {
@@ -265,7 +265,7 @@ test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
265
265
 
266
266
  test('VoterError((uint256,bool,address,uint256),string[],bytes)', () => {
267
267
  expect(
268
- formatAbiItemWithParams({
268
+ formatAbiItem({
269
269
  inputs: [
270
270
  {
271
271
  components: [
@@ -315,7 +315,7 @@ test('VoterError((uint256,bool,address,uint256),string[],bytes)', () => {
315
315
 
316
316
  test('error: invalid type', () => {
317
317
  expect(() =>
318
- formatAbiItemWithParams({
318
+ formatAbiItem({
319
319
  inputs: [
320
320
  {
321
321
  internalType: 'bytes32[]',
@@ -3,7 +3,7 @@ import { AbiParameter } from 'abitype'
3
3
  import { InvalidDefinitionTypeError } from '../../errors'
4
4
  import { AbiItem } from '../../types'
5
5
 
6
- export function formatAbiItemWithParams(
6
+ export function formatAbiItem(
7
7
  abiItem: AbiItem,
8
8
  { includeName = false }: { includeName?: boolean } = {},
9
9
  ) {
@@ -15,8 +15,8 @@ test('exports utils', () => {
15
15
  "encodeEventTopics": [Function],
16
16
  "encodeFunctionData": [Function],
17
17
  "encodeFunctionResult": [Function],
18
+ "formatAbiItem": [Function],
18
19
  "formatAbiItemWithArgs": [Function],
19
- "formatAbiItemWithParams": [Function],
20
20
  "getAbiItem": [Function],
21
21
  }
22
22
  `)
@@ -33,6 +33,6 @@ export { encodeFunctionResult } from './encodeFunctionResult'
33
33
 
34
34
  export { formatAbiItemWithArgs } from './formatAbiItemWithArgs'
35
35
 
36
- export { formatAbiItemWithParams } from './formatAbiItemWithParams'
36
+ export { formatAbiItem } from './formatAbiItem'
37
37
 
38
38
  export { getAbiItem } from './getAbiItem'
@@ -0,0 +1,43 @@
1
+ import { describe, expect, test } from 'vitest'
2
+ import { celo } from '../chains'
3
+ import { defineChain } from './chain'
4
+
5
+ describe('defineChain', () => {
6
+ test('default', () => {
7
+ expect(
8
+ defineChain({
9
+ id: 42220,
10
+ name: 'Celo',
11
+ network: 'celo',
12
+ nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
13
+ rpcUrls: {
14
+ public: { http: ['https://rpc.ankr.com/celo'] },
15
+ default: { http: ['https://rpc.ankr.com/celo'] },
16
+ },
17
+ }),
18
+ ).toMatchInlineSnapshot(`
19
+ {
20
+ "id": 42220,
21
+ "name": "Celo",
22
+ "nativeCurrency": {
23
+ "decimals": 18,
24
+ "name": "Celo",
25
+ "symbol": "CELO",
26
+ },
27
+ "network": "celo",
28
+ "rpcUrls": {
29
+ "default": {
30
+ "http": [
31
+ "https://rpc.ankr.com/celo",
32
+ ],
33
+ },
34
+ "public": {
35
+ "http": [
36
+ "https://rpc.ankr.com/celo",
37
+ ],
38
+ },
39
+ },
40
+ }
41
+ `)
42
+ })
43
+ })
@@ -0,0 +1,8 @@
1
+ import { Chain, Formatters } from '../types'
2
+
3
+ export function defineChain<
4
+ TFormatters extends Formatters = Formatters,
5
+ TChain extends Chain<TFormatters> = Chain<TFormatters>,
6
+ >(chain: TChain) {
7
+ return chain
8
+ }
@@ -5,11 +5,7 @@ import {
5
5
  ContractMethodZeroDataError,
6
6
  } from '../../errors'
7
7
  import { Address } from '../../types'
8
- import {
9
- formatAbiItemWithArgs,
10
- formatAbiItemWithParams,
11
- getAbiItem,
12
- } from '../abi'
8
+ import { formatAbiItemWithArgs, formatAbiItem, getAbiItem } from '../abi'
13
9
 
14
10
  export function getContractError(
15
11
  err: unknown,
@@ -40,7 +36,7 @@ export function getContractError(
40
36
  })
41
37
  : undefined
42
38
  const functionWithParams = abiItem
43
- ? formatAbiItemWithParams(abiItem, { includeName: true })
39
+ ? formatAbiItem(abiItem, { includeName: true })
44
40
  : undefined
45
41
 
46
42
  if (err instanceof AbiDecodingZeroDataError) {
@@ -1,6 +1,5 @@
1
- import type { Chain, Formatter, Formatters } from '../../chains'
2
- import type { Block, RpcBlock } from '../../types'
3
- import type { ExtractFormatter, Formatted } from './format'
1
+ import type { Chain, Block, Formatter, Formatters, RpcBlock } from '../../types'
2
+ import { defineFormatter, ExtractFormatter, Formatted } from './format'
4
3
  import { formatTransaction } from './transaction'
5
4
 
6
5
  export type BlockFormatter<TChain extends Chain = Chain> = ExtractFormatter<
@@ -34,3 +33,5 @@ export function formatBlock(block: Partial<RpcBlock>) {
34
33
  : null,
35
34
  } as Block
36
35
  }
36
+
37
+ export const defineBlock = defineFormatter({ format: formatBlock })
@@ -1,4 +1,4 @@
1
- import { Formatter } from '../../chains'
1
+ import { Formatter } from '../../types'
2
2
 
3
3
  /**
4
4
  * @description Picks out the keys from `value` that exist in the formatter.
@@ -1,5 +1,4 @@
1
- import type { Chain, Formatter } from '../../chains'
2
- import type { OptionalNullable } from '../../types'
1
+ import type { Chain, Formatter, OptionalNullable } from '../../types'
3
2
 
4
3
  export type ExtractFormatter<
5
4
  TChain extends Chain,
@@ -51,3 +50,41 @@ export function format<
51
50
  >(data: TSource, { formatter }: FormatOptions<TSource, TTarget>) {
52
51
  return formatter(data) as Formatted<TFormatter, TTarget>
53
52
  }
53
+
54
+ export function defineFormatter<
55
+ TSource extends Record<string, unknown>,
56
+ TFormatted,
57
+ >({
58
+ format,
59
+ }: {
60
+ format: (data: TSource) => TFormatted
61
+ }) {
62
+ return <
63
+ TFormat extends Formatter<
64
+ TSource,
65
+ Partial<TFormatted> & { [key: string]: unknown }
66
+ >,
67
+ TExclude extends (keyof TSource)[] = [],
68
+ >({
69
+ exclude,
70
+ format: formatOverride,
71
+ }: {
72
+ exclude?: TExclude
73
+ format?: TFormat
74
+ }) =>
75
+ (data: TSource & { [key: string]: unknown }) => {
76
+ const formatted = format(data)
77
+ if (exclude) {
78
+ for (const key of exclude) {
79
+ delete (formatted as any)[key]
80
+ }
81
+ }
82
+ return {
83
+ ...formatted,
84
+ ...formatOverride?.(data),
85
+ } as TFormatted &
86
+ ReturnType<TFormat> & {
87
+ [K in TExclude[number]]: never
88
+ }
89
+ }
90
+ }
@@ -5,6 +5,11 @@ import * as formatters from './index'
5
5
  test('exports formatters', () => {
6
6
  expect(formatters).toMatchInlineSnapshot(`
7
7
  {
8
+ "defineBlock": [Function],
9
+ "defineFormatter": [Function],
10
+ "defineTransaction": [Function],
11
+ "defineTransactionReceipt": [Function],
12
+ "defineTransactionRequest": [Function],
8
13
  "extract": [Function],
9
14
  "format": [Function],
10
15
  "formatBlock": [Function],
@@ -12,6 +17,11 @@ test('exports formatters', () => {
12
17
  "formatTransaction": [Function],
13
18
  "formatTransactionReceipt": [Function],
14
19
  "formatTransactionRequest": [Function],
20
+ "transactionType": {
21
+ "0x0": "legacy",
22
+ "0x1": "eip2930",
23
+ "0x2": "eip1559",
24
+ },
15
25
  }
16
26
  `)
17
27
  })
@@ -1,24 +1,34 @@
1
1
  export type { BlockFormatter, FormattedBlock } from './block'
2
- export { formatBlock } from './block'
2
+ export { defineBlock, formatBlock } from './block'
3
3
 
4
4
  export { extract } from './extract'
5
5
 
6
6
  export { formatFeeHistory } from './feeHistory'
7
7
 
8
8
  export type { ExtractFormatter, FormatOptions, Formatted } from './format'
9
- export { format } from './format'
9
+ export { defineFormatter, format } from './format'
10
10
 
11
11
  export type { FormattedTransaction, TransactionFormatter } from './transaction'
12
- export { formatTransaction } from './transaction'
12
+ export {
13
+ defineTransaction,
14
+ formatTransaction,
15
+ transactionType,
16
+ } from './transaction'
13
17
 
14
18
  export type {
15
19
  FormattedTransactionReceipt,
16
20
  TransactionReceiptFormatter,
17
21
  } from './transactionReceipt'
18
- export { formatTransactionReceipt } from './transactionReceipt'
22
+ export {
23
+ defineTransactionReceipt,
24
+ formatTransactionReceipt,
25
+ } from './transactionReceipt'
19
26
 
20
27
  export type {
21
28
  FormattedTransactionRequest,
22
29
  TransactionRequestFormatter,
23
30
  } from './transactionRequest'
24
- export { formatTransactionRequest } from './transactionRequest'
31
+ export {
32
+ defineTransactionRequest,
33
+ formatTransactionRequest,
34
+ } from './transactionRequest'
@@ -1,8 +1,12 @@
1
- import type { Chain, Formatter, Formatters } from '../../chains'
2
- import type { RpcTransaction, Transaction } from '../../types'
3
- import { transactionType } from '../../constants'
1
+ import type {
2
+ Chain,
3
+ Formatter,
4
+ Formatters,
5
+ RpcTransaction,
6
+ Transaction,
7
+ } from '../../types'
4
8
  import { hexToNumber } from '../encoding'
5
- import type { ExtractFormatter, Formatted } from './format'
9
+ import { defineFormatter, ExtractFormatter, Formatted } from './format'
6
10
 
7
11
  export type TransactionFormatter<TChain extends Chain = Chain> =
8
12
  ExtractFormatter<
@@ -15,6 +19,12 @@ export type FormattedTransaction<
15
19
  TFormatter extends Formatter | undefined = Formatter,
16
20
  > = Formatted<TFormatter, Transaction>
17
21
 
22
+ export const transactionType = {
23
+ '0x0': 'legacy',
24
+ '0x1': 'eip2930',
25
+ '0x2': 'eip1559',
26
+ } as const
27
+
18
28
  export function formatTransaction(transaction: Partial<RpcTransaction>) {
19
29
  const transaction_ = {
20
30
  ...transaction,
@@ -49,3 +59,5 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
49
59
  }
50
60
  return transaction_ as Transaction
51
61
  }
62
+
63
+ export const defineTransaction = defineFormatter({ format: formatTransaction })
@@ -1,9 +1,14 @@
1
- import type { Chain, Formatter, Formatters } from '../../chains'
2
- import { transactionType } from '../../constants'
3
- import type { RpcTransactionReceipt, TransactionReceipt } from '../../types'
1
+ import type {
2
+ Chain,
3
+ Formatter,
4
+ Formatters,
5
+ RpcTransactionReceipt,
6
+ TransactionReceipt,
7
+ } from '../../types'
4
8
  import { hexToNumber } from '../encoding'
5
- import type { ExtractFormatter, Formatted } from './format'
9
+ import { defineFormatter, ExtractFormatter, Formatted } from './format'
6
10
  import { formatLog } from './log'
11
+ import { transactionType } from './transaction'
7
12
 
8
13
  export type TransactionReceiptFormatter<TChain extends Chain = Chain> =
9
14
  ExtractFormatter<
@@ -52,3 +57,7 @@ export function formatTransactionReceipt(
52
57
  : null,
53
58
  } as TransactionReceipt
54
59
  }
60
+
61
+ export const defineTransactionReceipt = defineFormatter({
62
+ format: formatTransactionReceipt,
63
+ })
@@ -1,6 +1,11 @@
1
- import type { Chain, Formatter, Formatters } from '../../chains'
2
- import type { RpcTransactionRequest, TransactionRequest } from '../../types'
3
- import type { ExtractFormatter, Formatted } from './format'
1
+ import type {
2
+ Chain,
3
+ Formatter,
4
+ Formatters,
5
+ RpcTransactionRequest,
6
+ TransactionRequest,
7
+ } from '../../types'
8
+ import { defineFormatter, ExtractFormatter, Formatted } from './format'
4
9
  import { numberToHex } from '../encoding'
5
10
 
6
11
  export type TransactionRequestFormatter<TChain extends Chain = Chain> =
@@ -45,3 +50,7 @@ export function formatTransactionRequest(
45
50
  : undefined,
46
51
  } as RpcTransactionRequest
47
52
  }
53
+
54
+ export const defineTransactionRequest = defineFormatter({
55
+ format: formatTransactionRequest,
56
+ })
@@ -1,4 +1,4 @@
1
+ import { EventDefinition } from '../../types'
1
2
  import { hashFunction } from './hashFunction'
2
3
 
3
- export const getEventSignature = (event: `${string}(${string})`) =>
4
- hashFunction(event)
4
+ export const getEventSignature = (event: EventDefinition) => hashFunction(event)
@@ -20,6 +20,12 @@ test('exports utils', () => {
20
20
  "decodeFunctionResult": [Function],
21
21
  "decodeHex": [Function],
22
22
  "decodeRlp": [Function],
23
+ "defineBlock": [Function],
24
+ "defineChain": [Function],
25
+ "defineFormatter": [Function],
26
+ "defineTransaction": [Function],
27
+ "defineTransactionReceipt": [Function],
28
+ "defineTransactionRequest": [Function],
23
29
  "encodeAbi": [Function],
24
30
  "encodeBytes": [Function],
25
31
  "encodeDeployData": [Function],
@@ -29,14 +35,18 @@ test('exports utils', () => {
29
35
  "encodeFunctionResult": [Function],
30
36
  "encodeHex": [Function],
31
37
  "encodeRlp": [Function],
38
+ "etherUnits": {
39
+ "gwei": 9,
40
+ "wei": 18,
41
+ },
32
42
  "extract": [Function],
33
43
  "extractFunctionName": [Function],
34
44
  "extractFunctionParams": [Function],
35
45
  "extractFunctionParts": [Function],
36
46
  "extractFunctionType": [Function],
37
47
  "format": [Function],
48
+ "formatAbiItem": [Function],
38
49
  "formatAbiItemWithArgs": [Function],
39
- "formatAbiItemWithParams": [Function],
40
50
  "formatBlock": [Function],
41
51
  "formatEther": [Function],
42
52
  "formatGwei": [Function],
@@ -51,6 +61,10 @@ test('exports utils', () => {
51
61
  "getCreateAddress": [Function],
52
62
  "getEventSignature": [Function],
53
63
  "getFunctionSignature": [Function],
64
+ "gweiUnits": {
65
+ "ether": -9,
66
+ "wei": 9,
67
+ },
54
68
  "hexToBigInt": [Function],
55
69
  "hexToBool": [Function],
56
70
  "hexToBytes": [Function],
@@ -81,7 +95,16 @@ test('exports utils', () => {
81
95
  "stringToBytes": [Function],
82
96
  "stringToHex": [Function],
83
97
  "stringify": [Function],
98
+ "transactionType": {
99
+ "0x0": "legacy",
100
+ "0x1": "eip2930",
101
+ "0x2": "eip1559",
102
+ },
84
103
  "trim": [Function],
104
+ "weiUnits": {
105
+ "ether": -18,
106
+ "gwei": -9,
107
+ },
85
108
  }
86
109
  `)
87
110
  })
@@ -23,7 +23,7 @@ export {
23
23
  encodeFunctionData,
24
24
  encodeFunctionResult,
25
25
  formatAbiItemWithArgs,
26
- formatAbiItemWithParams,
26
+ formatAbiItem,
27
27
  getAbiItem,
28
28
  } from './abi'
29
29
 
@@ -43,6 +43,8 @@ export {
43
43
 
44
44
  export { buildRequest } from './buildRequest'
45
45
 
46
+ export { defineChain } from './chain'
47
+
46
48
  export {
47
49
  extractFunctionName,
48
50
  extractFunctionParams,
@@ -77,11 +79,17 @@ export type {
77
79
  TransactionRequestFormatter,
78
80
  } from './formatters'
79
81
  export {
82
+ defineBlock,
83
+ defineFormatter,
84
+ defineTransaction,
85
+ defineTransactionReceipt,
86
+ defineTransactionRequest,
80
87
  extract,
81
88
  format,
82
89
  formatBlock,
83
90
  formatTransaction,
84
91
  formatTransactionRequest,
92
+ transactionType,
85
93
  } from './formatters'
86
94
 
87
95
  export type { EncodeRlpResponse } from './encoding'
@@ -117,10 +125,13 @@ export { rpc } from './rpc'
117
125
  export { stringify } from './stringify'
118
126
 
119
127
  export {
128
+ etherUnits,
120
129
  formatEther,
121
130
  formatGwei,
122
131
  formatUnit,
132
+ gweiUnits,
123
133
  parseUnit,
124
134
  parseEther,
125
135
  parseGwei,
136
+ weiUnits,
126
137
  } from './unit'
@@ -13,11 +13,6 @@ test('exports constants', () => {
13
13
  "ether": -9,
14
14
  "wei": 9,
15
15
  },
16
- "transactionType": {
17
- "0x0": "legacy",
18
- "0x1": "eip2930",
19
- "0x2": "eip1559",
20
- },
21
16
  "weiUnits": {
22
17
  "ether": -18,
23
18
  "gwei": -9,
@@ -10,9 +10,3 @@ export const weiUnits = {
10
10
  ether: -18,
11
11
  gwei: -9,
12
12
  }
13
-
14
- export const transactionType = {
15
- '0x0': 'legacy',
16
- '0x1': 'eip2930',
17
- '0x2': 'eip1559',
18
- } as const
@@ -1,4 +1,4 @@
1
- import { etherUnits } from '../../constants'
1
+ import { etherUnits } from '../../utils'
2
2
  import { formatUnit } from './formatUnit'
3
3
 
4
4
  export function formatEther(wei: bigint, unit: 'wei' | 'gwei' = 'wei') {
@@ -1,4 +1,4 @@
1
- import { gweiUnits } from '../../constants'
1
+ import { gweiUnits } from '../../utils'
2
2
  import { formatUnit } from './formatUnit'
3
3
 
4
4
  export function formatGwei(wei: bigint, unit: 'wei' = 'wei') {
@@ -5,12 +5,24 @@ import * as value from './index'
5
5
  test('exports value utils', () => {
6
6
  expect(value).toMatchInlineSnapshot(`
7
7
  {
8
+ "etherUnits": {
9
+ "gwei": 9,
10
+ "wei": 18,
11
+ },
8
12
  "formatEther": [Function],
9
13
  "formatGwei": [Function],
10
14
  "formatUnit": [Function],
15
+ "gweiUnits": {
16
+ "ether": -9,
17
+ "wei": 9,
18
+ },
11
19
  "parseEther": [Function],
12
20
  "parseGwei": [Function],
13
21
  "parseUnit": [Function],
22
+ "weiUnits": {
23
+ "ether": -18,
24
+ "gwei": -9,
25
+ },
14
26
  }
15
27
  `)
16
28
  })
@@ -1,3 +1,4 @@
1
+ export { etherUnits, gweiUnits, weiUnits } from './constants'
1
2
  export { formatEther } from './formatEther'
2
3
  export { formatGwei } from './formatGwei'
3
4
  export { formatUnit } from './formatUnit'
@@ -1,4 +1,4 @@
1
- import { etherUnits } from '../../constants'
1
+ import { etherUnits } from '../../utils'
2
2
  import { parseUnit } from './parseUnit'
3
3
 
4
4
  export function parseEther(ether: `${number}`, unit: 'wei' | 'gwei' = 'wei') {
@@ -1,4 +1,4 @@
1
- import { gweiUnits } from '../../constants'
1
+ import { gweiUnits } from '../../utils'
2
2
  import { parseUnit } from './parseUnit'
3
3
 
4
4
  export function parseGwei(ether: `${number}`, unit: 'wei' = 'wei') {