viem 0.0.1-alpha.21 → 0.0.1-alpha.23

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 (181) hide show
  1. package/dist/{chain-32f56cfa.d.ts → chain-4b39613a.d.ts} +2 -2
  2. package/dist/{chain-f12cdc7f.d.ts → chain-aa4898d0.d.ts} +1 -1
  3. package/dist/chains.d.ts +3 -3
  4. package/dist/chains.js +46 -46
  5. package/dist/chains.mjs +1 -1
  6. package/dist/{chunk-EC3NUIJE.js → chunk-7Y5QVLX7.js} +13 -13
  7. package/dist/{chunk-EC3NUIJE.js.map → chunk-7Y5QVLX7.js.map} +1 -1
  8. package/dist/{chunk-KEHGSYDO.js → chunk-BV5NTHUX.js} +14 -13
  9. package/dist/chunk-BV5NTHUX.js.map +1 -0
  10. package/dist/{chunk-46BO7YAQ.mjs → chunk-EGVXCZNJ.mjs} +4 -3
  11. package/dist/chunk-EGVXCZNJ.mjs.map +1 -0
  12. package/dist/{chunk-57ZOFERP.mjs → chunk-GX2KDAM3.mjs} +2 -2
  13. package/dist/{chunk-57ZOFERP.mjs.map → chunk-GX2KDAM3.mjs.map} +0 -0
  14. package/dist/{chunk-W7BWWAC4.js → chunk-NW6724MI.js} +14 -14
  15. package/dist/{chunk-W7BWWAC4.js.map → chunk-NW6724MI.js.map} +0 -0
  16. package/dist/{chunk-DGO77E2H.mjs → chunk-RJLUZTJS.mjs} +86 -3
  17. package/dist/chunk-RJLUZTJS.mjs.map +1 -0
  18. package/dist/{chunk-O2GYLJVD.js → chunk-SSPRUPGN.js} +405 -165
  19. package/dist/chunk-SSPRUPGN.js.map +1 -0
  20. package/dist/{chunk-DSPMAIDO.mjs → chunk-TXHOG6KU.mjs} +2 -2
  21. package/dist/{chunk-DSPMAIDO.mjs.map → chunk-TXHOG6KU.mjs.map} +1 -1
  22. package/dist/{chunk-62VTYU2V.mjs → chunk-XBUH66KN.mjs} +406 -166
  23. package/dist/chunk-XBUH66KN.mjs.map +1 -0
  24. package/dist/{chunk-KZMJR27B.js → chunk-ZKYGWITF.js} +147 -64
  25. package/dist/chunk-ZKYGWITF.js.map +1 -0
  26. package/dist/clients/index.d.ts +7 -7
  27. package/dist/clients/index.js +3 -3
  28. package/dist/clients/index.mjs +2 -2
  29. package/dist/{contract-9af4608b.d.ts → contract-4c3a37b3.d.ts} +14 -3
  30. package/dist/{createClient-5d316c7e.d.ts → createClient-55a04188.d.ts} +2 -2
  31. package/dist/{createPublicClient-9d2b42e1.d.ts → createPublicClient-3b27b282.d.ts} +3 -3
  32. package/dist/{createTestClient-79498dab.d.ts → createTestClient-93f9eac6.d.ts} +3 -3
  33. package/dist/{createWalletClient-f69a5230.d.ts → createWalletClient-c10df94d.d.ts} +3 -3
  34. package/dist/{eip1193-6c485d63.d.ts → eip1193-4c24765a.d.ts} +1 -1
  35. package/dist/ens.d.ts +1 -0
  36. package/dist/ens.js +11 -0
  37. package/dist/ens.js.map +1 -0
  38. package/dist/ens.mjs +11 -0
  39. package/dist/ens.mjs.map +1 -0
  40. package/dist/index.d.ts +174 -113
  41. package/dist/index.js +16 -6
  42. package/dist/index.mjs +15 -5
  43. package/dist/normalize-ef9240c0.d.ts +33 -0
  44. package/dist/{parseGwei-4308ad80.d.ts → parseGwei-3411cf2d.d.ts} +101 -37
  45. package/dist/public.d.ts +9 -9
  46. package/dist/public.js +4 -4
  47. package/dist/public.mjs +3 -3
  48. package/dist/{sendTransaction-1c8290a9.d.ts → sendTransaction-f17a2389.d.ts} +3 -3
  49. package/dist/{stopImpersonatingAccount-7781842a.d.ts → stopImpersonatingAccount-afb26486.d.ts} +2 -2
  50. package/dist/test.d.ts +5 -5
  51. package/dist/test.js +3 -3
  52. package/dist/test.mjs +2 -2
  53. package/dist/{transactionRequest-341b6ed2.d.ts → transactionRequest-93e9f001.d.ts} +2 -2
  54. package/dist/utils/index.d.ts +14 -16
  55. package/dist/utils/index.js +8 -2
  56. package/dist/utils/index.mjs +7 -1
  57. package/dist/wallet.d.ts +7 -7
  58. package/dist/wallet.js +3 -3
  59. package/dist/wallet.mjs +2 -2
  60. package/dist/{watchAsset-afaad3c7.d.ts → watchAsset-efd3dd05.d.ts} +3 -3
  61. package/dist/{watchPendingTransactions-3b722547.d.ts → watchPendingTransactions-57df1a13.d.ts} +17 -27
  62. package/dist/{webSocket-b180e679.d.ts → webSocket-d2e7bd0e.d.ts} +2 -2
  63. package/dist/window.d.ts +2 -2
  64. package/package.json +8 -2
  65. package/src/_test/abis.ts +7 -0
  66. package/src/_test/bench.ts +4 -4
  67. package/src/_test/constants.ts +4 -3
  68. package/src/_test/index.ts +4 -2
  69. package/src/_test/utils.ts +39 -1
  70. package/src/actions/index.test.ts +1 -0
  71. package/src/actions/index.ts +2 -0
  72. package/src/actions/public/call.bench.ts +5 -5
  73. package/src/actions/public/deployContract.ts +4 -4
  74. package/src/actions/public/estimateGas.bench.ts +6 -6
  75. package/src/actions/public/getBlock.bench.ts +5 -5
  76. package/src/actions/public/getBlockNumber.bench.ts +5 -5
  77. package/src/actions/public/getFilterChanges.test.ts +9 -9
  78. package/src/actions/public/getFilterLogs.test.ts +7 -7
  79. package/src/actions/public/getGasPrice.bench.ts +1 -10
  80. package/src/actions/public/getLogs.test.ts +7 -7
  81. package/src/actions/public/getTransaction.bench.ts +5 -5
  82. package/src/actions/public/getTransactionReceipt.bench.ts +5 -5
  83. package/src/actions/public/index.test.ts +1 -0
  84. package/src/actions/public/index.ts +3 -0
  85. package/src/actions/public/multicall.test.ts +452 -0
  86. package/src/actions/public/multicall.ts +103 -0
  87. package/src/actions/public/readContract.test.ts +226 -26
  88. package/src/actions/public/readContract.ts +13 -27
  89. package/src/actions/public/simulateContract.bench.ts +10 -0
  90. package/src/actions/public/simulateContract.test.ts +209 -37
  91. package/src/actions/public/simulateContract.ts +17 -21
  92. package/src/actions/public/watchContractEvent.test.ts +61 -57
  93. package/src/actions/public/watchEvent.test.ts +42 -37
  94. package/src/actions/test/impersonateAccount.test.ts +4 -6
  95. package/src/actions/test/sendUnsignedTransaction.test.ts +2 -2
  96. package/src/actions/test/stopImpersonatingAccount.test.ts +5 -7
  97. package/src/actions/wallet/signMessage.test.ts +0 -1
  98. package/src/actions/wallet/switchChain.test.ts +1 -2
  99. package/src/actions/wallet/watchAsset.test.ts +1 -2
  100. package/src/actions/wallet/writeContract.test.ts +37 -7
  101. package/src/actions/wallet/writeContract.ts +5 -14
  102. package/src/clients/transports/fallback.test.ts +34 -0
  103. package/src/clients/transports/fallback.ts +3 -1
  104. package/src/clients/transports/http.test.ts +0 -1
  105. package/src/clients/transports/webSocket.test.ts +0 -1
  106. package/src/constants/abis.test.ts +53 -0
  107. package/src/constants/abis.ts +44 -0
  108. package/src/constants/index.test.ts +14 -0
  109. package/src/constants/index.ts +3 -0
  110. package/src/constants/solidity.test.ts +41 -0
  111. package/src/constants/solidity.ts +35 -0
  112. package/src/ens.ts +5 -0
  113. package/src/errors/abi.test.ts +0 -2
  114. package/src/errors/base.test.ts +44 -2
  115. package/src/errors/base.ts +12 -12
  116. package/src/errors/block.test.ts +6 -6
  117. package/src/errors/contract.test.ts +233 -0
  118. package/src/errors/contract.ts +133 -80
  119. package/src/errors/index.ts +4 -2
  120. package/src/errors/request.test.ts +3 -4
  121. package/src/errors/request.ts +17 -17
  122. package/src/errors/rpc.test.ts +1 -2
  123. package/src/errors/transaction.test.ts +12 -12
  124. package/src/errors/transport.test.ts +0 -1
  125. package/src/index.test.ts +47 -0
  126. package/src/index.ts +10 -0
  127. package/src/types/contract.ts +55 -4
  128. package/src/types/index.ts +5 -0
  129. package/src/types/multicall.ts +82 -0
  130. package/src/utils/abi/decodeAbi.test.ts +1 -2
  131. package/src/utils/abi/decodeAbi.ts +11 -7
  132. package/src/utils/abi/decodeDeployData.test.ts +7 -15
  133. package/src/utils/abi/decodeDeployData.ts +10 -7
  134. package/src/utils/abi/decodeErrorResult.test.ts +103 -3
  135. package/src/utils/abi/decodeErrorResult.ts +30 -13
  136. package/src/utils/abi/decodeFunctionData.test.ts +0 -1
  137. package/src/utils/abi/decodeFunctionResult.test.ts +80 -9
  138. package/src/utils/abi/decodeFunctionResult.ts +15 -11
  139. package/src/utils/abi/encodeAbi.test.ts +3 -4
  140. package/src/utils/abi/encodeAbi.ts +19 -10
  141. package/src/utils/abi/encodeDeployData.test.ts +6 -13
  142. package/src/utils/abi/encodeDeployData.ts +10 -7
  143. package/src/utils/abi/encodeErrorResult.test.ts +2 -7
  144. package/src/utils/abi/encodeErrorResult.ts +18 -11
  145. package/src/utils/abi/encodeEventTopics.test.ts +11 -14
  146. package/src/utils/abi/encodeEventTopics.ts +15 -9
  147. package/src/utils/abi/encodeFunctionData.test.ts +5 -7
  148. package/src/utils/abi/encodeFunctionData.ts +16 -9
  149. package/src/utils/abi/encodeFunctionResult.test.ts +10 -15
  150. package/src/utils/abi/encodeFunctionResult.ts +9 -7
  151. package/src/utils/abi/getAbiItem.test.ts +547 -0
  152. package/src/utils/abi/getAbiItem.ts +93 -3
  153. package/src/utils/abi/index.ts +5 -1
  154. package/src/utils/address/getAddress.test.ts +6 -6
  155. package/src/utils/contract/getContractError.test.ts +247 -62
  156. package/src/utils/contract/getContractError.ts +30 -38
  157. package/src/utils/data/pad.bench.ts +0 -9
  158. package/src/utils/data/trim.bench.ts +0 -16
  159. package/src/utils/encoding/encodeBytes.bench.ts +0 -12
  160. package/src/utils/encoding/encodeHex.bench.ts +0 -11
  161. package/src/utils/ens/index.test.ts +13 -0
  162. package/src/utils/ens/index.ts +5 -0
  163. package/src/utils/ens/labelhash.test.ts +55 -0
  164. package/src/utils/ens/labelhash.ts +16 -0
  165. package/src/utils/ens/namehash.test.ts +65 -0
  166. package/src/utils/ens/namehash.ts +28 -0
  167. package/src/utils/ens/normalize.bench.ts +14 -0
  168. package/src/utils/ens/normalize.test.ts +35 -0
  169. package/src/utils/ens/normalize.ts +14 -0
  170. package/src/utils/hash/keccak256.ts +3 -5
  171. package/src/utils/index.test.ts +3 -0
  172. package/src/utils/index.ts +4 -0
  173. package/src/utils/rpc.test.ts +3 -6
  174. package/src/utils/unit/formatUnit.bench.ts +0 -5
  175. package/src/utils/unit/parseUnit.bench.ts +0 -5
  176. package/dist/chunk-46BO7YAQ.mjs.map +0 -1
  177. package/dist/chunk-62VTYU2V.mjs.map +0 -1
  178. package/dist/chunk-DGO77E2H.mjs.map +0 -1
  179. package/dist/chunk-KEHGSYDO.js.map +0 -1
  180. package/dist/chunk-KZMJR27B.js.map +0 -1
  181. package/dist/chunk-O2GYLJVD.js.map +0 -1
@@ -2,14 +2,14 @@ import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
2
2
  import { wait } from '../../utils/wait'
3
3
  import {
4
4
  accounts,
5
+ address,
5
6
  publicClient,
6
7
  testClient,
7
8
  transfer1Data,
8
9
  usdcContractConfig,
9
- vitalikAddress,
10
10
  walletClient,
11
11
  } from '../../_test'
12
- import { impersonateAccount, stopImpersonatingAccount } from '../test'
12
+ import { impersonateAccount, mine, stopImpersonatingAccount } from '../test'
13
13
  import { sendTransaction } from '../wallet'
14
14
  import * as createEventFilter from './createEventFilter'
15
15
  import * as getFilterChanges from './getFilterChanges'
@@ -17,47 +17,52 @@ import { OnLogsResponse, watchEvent } from './watchEvent'
17
17
 
18
18
  beforeAll(async () => {
19
19
  await impersonateAccount(testClient, {
20
- address: vitalikAddress,
20
+ address: address.vitalik,
21
21
  })
22
+ await mine(testClient, { blocks: 1 })
22
23
  })
23
24
 
24
25
  afterAll(async () => {
25
26
  await stopImpersonatingAccount(testClient, {
26
- address: vitalikAddress,
27
+ address: address.vitalik,
27
28
  })
28
29
  })
29
30
 
30
- test('default', async () => {
31
- let logs: OnLogsResponse[] = []
31
+ test(
32
+ 'default',
33
+ async () => {
34
+ let logs: OnLogsResponse[] = []
32
35
 
33
- const unwatch = watchEvent(publicClient, {
34
- onLogs: (logs_) => logs.push(logs_),
35
- })
36
+ const unwatch = watchEvent(publicClient, {
37
+ onLogs: (logs_) => logs.push(logs_),
38
+ })
36
39
 
37
- await wait(1000)
38
- await sendTransaction(walletClient, {
39
- from: vitalikAddress,
40
- to: usdcContractConfig.address,
41
- data: transfer1Data(accounts[0].address),
42
- })
43
- await sendTransaction(walletClient, {
44
- from: vitalikAddress,
45
- to: usdcContractConfig.address,
46
- data: transfer1Data(accounts[0].address),
47
- })
48
- await wait(1000)
49
- await sendTransaction(walletClient, {
50
- from: vitalikAddress,
51
- to: usdcContractConfig.address,
52
- data: transfer1Data(accounts[1].address),
53
- })
54
- await wait(2000)
55
- unwatch()
40
+ await wait(1000)
41
+ await sendTransaction(walletClient, {
42
+ from: address.vitalik,
43
+ to: usdcContractConfig.address,
44
+ data: transfer1Data(accounts[0].address),
45
+ })
46
+ await sendTransaction(walletClient, {
47
+ from: address.vitalik,
48
+ to: usdcContractConfig.address,
49
+ data: transfer1Data(accounts[0].address),
50
+ })
51
+ await wait(1000)
52
+ await sendTransaction(walletClient, {
53
+ from: address.vitalik,
54
+ to: usdcContractConfig.address,
55
+ data: transfer1Data(accounts[1].address),
56
+ })
57
+ await wait(2000)
58
+ unwatch()
56
59
 
57
- expect(logs.length).toBe(2)
58
- expect(logs[0].length).toBe(2)
59
- expect(logs[1].length).toBe(1)
60
- })
60
+ expect(logs.length).toBe(2)
61
+ expect(logs[0].length).toBe(2)
62
+ expect(logs[1].length).toBe(1)
63
+ },
64
+ { retry: 3 },
65
+ )
61
66
 
62
67
  test('args: batch', async () => {
63
68
  let logs: OnLogsResponse[] = []
@@ -69,18 +74,18 @@ test('args: batch', async () => {
69
74
 
70
75
  await wait(1000)
71
76
  await sendTransaction(walletClient, {
72
- from: vitalikAddress,
77
+ from: address.vitalik,
73
78
  to: usdcContractConfig.address,
74
79
  data: transfer1Data(accounts[0].address),
75
80
  })
76
81
  await sendTransaction(walletClient, {
77
- from: vitalikAddress,
82
+ from: address.vitalik,
78
83
  to: usdcContractConfig.address,
79
84
  data: transfer1Data(accounts[0].address),
80
85
  })
81
86
  await wait(1000)
82
87
  await sendTransaction(walletClient, {
83
- from: vitalikAddress,
88
+ from: address.vitalik,
84
89
  to: usdcContractConfig.address,
85
90
  data: transfer1Data(accounts[1].address),
86
91
  })
@@ -108,7 +113,7 @@ test('args: address', async () => {
108
113
 
109
114
  await wait(1000)
110
115
  await sendTransaction(walletClient, {
111
- from: vitalikAddress,
116
+ from: address.vitalik,
112
117
  to: usdcContractConfig.address,
113
118
  data: transfer1Data(accounts[0].address),
114
119
  })
@@ -137,7 +142,7 @@ test('args: address + event', async () => {
137
142
 
138
143
  await wait(1000)
139
144
  await sendTransaction(walletClient, {
140
- from: vitalikAddress,
145
+ from: address.vitalik,
141
146
  to: usdcContractConfig.address,
142
147
  data: transfer1Data(accounts[0].address),
143
148
  })
@@ -1,26 +1,24 @@
1
1
  import { expect, test } from 'vitest'
2
2
 
3
- import { accounts, testClient, vitalikAddress, walletClient } from '../../_test'
3
+ import { accounts, address, testClient, walletClient } from '../../_test'
4
4
  import { parseEther } from '../../utils'
5
5
  import { sendTransaction } from '../wallet/sendTransaction'
6
6
  import { impersonateAccount } from './impersonateAccount'
7
7
 
8
- const account = vitalikAddress
9
-
10
8
  test('impersonates account', async () => {
11
9
  await expect(
12
10
  sendTransaction(walletClient, {
13
- from: account,
11
+ from: address.vitalik,
14
12
  to: accounts[0].address,
15
13
  value: parseEther('1'),
16
14
  }),
17
15
  ).rejects.toThrowError('No Signer available')
18
16
 
19
- await impersonateAccount(testClient, { address: account })
17
+ await impersonateAccount(testClient, { address: address.vitalik })
20
18
 
21
19
  expect(
22
20
  await sendTransaction(walletClient, {
23
- from: account,
21
+ from: address.vitalik,
24
22
  to: accounts[0].address,
25
23
  value: parseEther('1'),
26
24
  }),
@@ -1,6 +1,6 @@
1
1
  import { expect, test } from 'vitest'
2
2
 
3
- import { accounts, publicClient, testClient, vitalikAddress } from '../../_test'
3
+ import { accounts, address, publicClient, testClient } from '../../_test'
4
4
  import { parseEther } from '../../utils'
5
5
  import { getBalance } from '../public/getBalance'
6
6
  import { mine, setBalance } from '../test'
@@ -8,7 +8,7 @@ import { mine, setBalance } from '../test'
8
8
  import { sendUnsignedTransaction } from './sendUnsignedTransaction'
9
9
 
10
10
  const sourceAccount = {
11
- address: vitalikAddress,
11
+ address: address.vitalik,
12
12
  } as const
13
13
  const targetAccount = accounts[0]
14
14
 
@@ -1,29 +1,27 @@
1
1
  import { expect, test } from 'vitest'
2
2
 
3
- import { accounts, testClient, vitalikAddress, walletClient } from '../../_test'
3
+ import { address, accounts, testClient, walletClient } from '../../_test'
4
4
  import { parseEther } from '../../utils'
5
5
  import { sendTransaction } from '../wallet/sendTransaction'
6
6
  import { impersonateAccount } from './impersonateAccount'
7
7
  import { stopImpersonatingAccount } from './stopImpersonatingAccount'
8
8
 
9
- const account = vitalikAddress
10
-
11
9
  test('stops impersonating account', async () => {
12
- await impersonateAccount(testClient, { address: account })
10
+ await impersonateAccount(testClient, { address: address.vitalik })
13
11
 
14
12
  expect(
15
13
  await sendTransaction(walletClient, {
16
- from: account,
14
+ from: address.vitalik,
17
15
  to: accounts[0].address,
18
16
  value: parseEther('1'),
19
17
  }),
20
18
  ).toBeDefined()
21
19
 
22
- await stopImpersonatingAccount(testClient, { address: account })
20
+ await stopImpersonatingAccount(testClient, { address: address.vitalik })
23
21
 
24
22
  await expect(
25
23
  sendTransaction(walletClient, {
26
- from: account,
24
+ from: address.vitalik,
27
25
  to: accounts[0].address,
28
26
  value: parseEther('1'),
29
27
  }),
@@ -35,7 +35,6 @@ test('hex', async () => {
35
35
  "data (\\"deadbeaf\\") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.
36
36
 
37
37
  Docs: https://viem.sh/TODO
38
-
39
38
  Version: viem@1.0.2"
40
39
  `,
41
40
  )
@@ -16,7 +16,6 @@ test('unsupported chain', async () => {
16
16
  [UnknownRpcError: An unknown RPC error occurred.
17
17
 
18
18
  Details: Unrecognized chain.
19
- Version: viem@1.0.2
20
- Internal Error: {"code":-4902,"details":"Unrecognized chain."}]
19
+ Version: viem@1.0.2]
21
20
  `)
22
21
  })
@@ -35,7 +35,6 @@ test('errors: unsupported type', async () => {
35
35
  Double check you have provided the correct parameters.
36
36
 
37
37
  Details: Token type ERC721 not supported.
38
- Version: viem@1.0.2
39
- Internal Error: {\\"code\\":-32602,\\"details\\":\\"Token type ERC721 not supported.\\"}"
38
+ Version: viem@1.0.2"
40
39
  `)
41
40
  })
@@ -12,6 +12,16 @@ import { mine } from '../test'
12
12
  import { writeContract } from './writeContract'
13
13
 
14
14
  test('default', async () => {
15
+ expect(
16
+ await writeContract(walletClient, {
17
+ ...wagmiContractConfig,
18
+ from: accounts[0].address,
19
+ functionName: 'mint',
20
+ }),
21
+ ).toBeDefined()
22
+ })
23
+
24
+ test('overloaded function', async () => {
15
25
  expect(
16
26
  await writeContract(walletClient, {
17
27
  ...wagmiContractConfig,
@@ -27,7 +37,26 @@ test('w/ simulateContract', async () => {
27
37
  ...wagmiContractConfig,
28
38
  from: accounts[0].address,
29
39
  functionName: 'mint',
30
- args: [69420n],
40
+ })
41
+ expect(await writeContract(walletClient, request)).toBeDefined()
42
+
43
+ await mine(testClient, { blocks: 1 })
44
+
45
+ expect(
46
+ await simulateContract(publicClient, {
47
+ ...wagmiContractConfig,
48
+ from: accounts[0].address,
49
+ functionName: 'mint',
50
+ }),
51
+ ).toBeDefined()
52
+ })
53
+
54
+ test('w/ simulateContract (overloaded)', async () => {
55
+ const { request } = await simulateContract(publicClient, {
56
+ ...wagmiContractConfig,
57
+ from: accounts[0].address,
58
+ functionName: 'mint',
59
+ args: [69421n],
31
60
  })
32
61
  expect(await writeContract(walletClient, request)).toBeDefined()
33
62
 
@@ -38,17 +67,18 @@ test('w/ simulateContract', async () => {
38
67
  ...wagmiContractConfig,
39
68
  from: accounts[0].address,
40
69
  functionName: 'mint',
41
- args: [69420n],
70
+ args: [69421n],
42
71
  }),
43
72
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
44
- "Token ID is taken
45
-
46
- Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
73
+ "The contract function \\"mint\\" reverted with the following reason:
74
+ Token ID is taken
75
+
47
76
  Contract: 0x0000000000000000000000000000000000000000
48
77
  Function: mint(uint256 tokenId)
49
- Arguments: (69420)
78
+ Arguments: (69421)
79
+ Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
50
80
 
51
- Details: execution reverted: Token ID is taken
81
+ Docs: https://viem.sh/docs/contract/simulateContract
52
82
  Version: viem@1.0.2"
53
83
  `)
54
84
  })
@@ -1,13 +1,7 @@
1
1
  import { Abi } from 'abitype'
2
2
 
3
3
  import type { WalletClient } from '../../clients'
4
- import type {
5
- Address,
6
- Chain,
7
- ExtractArgsFromAbi,
8
- ExtractFunctionNameFromAbi,
9
- GetValue,
10
- } from '../../types'
4
+ import type { Chain, ContractConfig, GetValue } from '../../types'
11
5
  import { EncodeFunctionDataArgs, encodeFunctionData } from '../../utils'
12
6
  import {
13
7
  sendTransaction,
@@ -18,20 +12,17 @@ import {
18
12
  export type WriteContractArgs<
19
13
  TChain extends Chain = Chain,
20
14
  TAbi extends Abi | readonly unknown[] = Abi,
21
- TFunctionName extends string = any,
15
+ TFunctionName extends string = string,
22
16
  > = Omit<SendTransactionArgs<TChain>, 'to' | 'data' | 'value'> & {
23
- address: Address
24
- abi: TAbi
25
- functionName: ExtractFunctionNameFromAbi<TAbi, TFunctionName>
26
17
  value?: GetValue<TAbi, TFunctionName, SendTransactionArgs<TChain>['value']>
27
- } & ExtractArgsFromAbi<TAbi, TFunctionName>
18
+ } & ContractConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'>
28
19
 
29
20
  export type WriteContractResponse = SendTransactionResponse
30
21
 
31
22
  export async function writeContract<
32
23
  TChain extends Chain,
33
- TAbi extends Abi = Abi,
34
- TFunctionName extends string = any,
24
+ TAbi extends Abi | readonly unknown[],
25
+ TFunctionName extends string,
35
26
  >(
36
27
  client: WalletClient,
37
28
  {
@@ -126,6 +126,40 @@ describe('request', () => {
126
126
  // ensure `retryCount` on transport is adhered
127
127
  expect(count).toBe(6)
128
128
  })
129
+
130
+ test('error (rpc)', async () => {
131
+ let count = 0
132
+ const server1 = await createHttpServer((req, res) => {
133
+ count++
134
+ res.writeHead(200, {
135
+ 'Content-Type': 'application/json',
136
+ })
137
+ res.end(JSON.stringify({ error: 'ngmi' }))
138
+ })
139
+ const server2 = await createHttpServer((req, res) => {
140
+ count++
141
+ res.writeHead(500)
142
+ res.end()
143
+ })
144
+ const server3 = await createHttpServer((req, res) => {
145
+ count++
146
+ res.writeHead(200, {
147
+ 'Content-Type': 'application/json',
148
+ })
149
+ res.end(JSON.stringify({ result: '0x1' }))
150
+ })
151
+
152
+ let transport = fallback([
153
+ http(server1.url),
154
+ http(server2.url),
155
+ http(server3.url),
156
+ ])({
157
+ chain: localhost,
158
+ })
159
+ await expect(() =>
160
+ transport.config.request({ method: 'eth_blockNumber' }),
161
+ ).rejects.toThrowError()
162
+ })
129
163
  })
130
164
 
131
165
  describe('client', () => {
@@ -1,3 +1,4 @@
1
+ import { HttpRequestError, RpcError } from '../../errors'
1
2
  import type { Transport, TransportConfig } from './createTransport'
2
3
  import { createTransport } from './createTransport'
3
4
 
@@ -31,7 +32,8 @@ export function fallback(
31
32
  params,
32
33
  } as any)
33
34
  } catch (err) {
34
- if (i < transports.length - 1) return fetch(i + 1)
35
+ if (!(err instanceof RpcError) && i < transports.length - 1)
36
+ return fetch(i + 1)
35
37
  throw err
36
38
  }
37
39
  }
@@ -103,7 +103,6 @@ test('no url', () => {
103
103
  "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.
104
104
 
105
105
  Docs: https://viem.sh/docs/clients/intro
106
-
107
106
  Version: viem@1.0.2"
108
107
  `,
109
108
  )
@@ -158,7 +158,6 @@ test('no url', () => {
158
158
  "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.
159
159
 
160
160
  Docs: https://viem.sh/docs/clients/intro
161
-
162
161
  Version: viem@1.0.2"
163
162
  `)
164
163
  })
@@ -0,0 +1,53 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import * as abis from './abis'
4
+
5
+ test('exports abis', () => {
6
+ expect(abis).toMatchInlineSnapshot(`
7
+ {
8
+ "multicall3Abi": [
9
+ {
10
+ "inputs": [
11
+ {
12
+ "components": [
13
+ {
14
+ "name": "target",
15
+ "type": "address",
16
+ },
17
+ {
18
+ "name": "allowFailure",
19
+ "type": "bool",
20
+ },
21
+ {
22
+ "name": "callData",
23
+ "type": "bytes",
24
+ },
25
+ ],
26
+ "name": "calls",
27
+ "type": "tuple[]",
28
+ },
29
+ ],
30
+ "name": "aggregate3",
31
+ "outputs": [
32
+ {
33
+ "components": [
34
+ {
35
+ "name": "success",
36
+ "type": "bool",
37
+ },
38
+ {
39
+ "name": "returnData",
40
+ "type": "bytes",
41
+ },
42
+ ],
43
+ "name": "returnData",
44
+ "type": "tuple[]",
45
+ },
46
+ ],
47
+ "stateMutability": "view",
48
+ "type": "function",
49
+ },
50
+ ],
51
+ }
52
+ `)
53
+ })
@@ -0,0 +1,44 @@
1
+ /* [Multicall3](https://github.com/mds1/multicall) */
2
+ export const multicall3Abi = [
3
+ {
4
+ inputs: [
5
+ {
6
+ components: [
7
+ {
8
+ name: 'target',
9
+ type: 'address',
10
+ },
11
+ {
12
+ name: 'allowFailure',
13
+ type: 'bool',
14
+ },
15
+ {
16
+ name: 'callData',
17
+ type: 'bytes',
18
+ },
19
+ ],
20
+ name: 'calls',
21
+ type: 'tuple[]',
22
+ },
23
+ ],
24
+ name: 'aggregate3',
25
+ outputs: [
26
+ {
27
+ components: [
28
+ {
29
+ name: 'success',
30
+ type: 'bool',
31
+ },
32
+ {
33
+ name: 'returnData',
34
+ type: 'bytes',
35
+ },
36
+ ],
37
+ name: 'returnData',
38
+ type: 'tuple[]',
39
+ },
40
+ ],
41
+ stateMutability: 'view',
42
+ type: 'function',
43
+ },
44
+ ] as const
@@ -0,0 +1,14 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import * as index from './index'
4
+
5
+ test('exports index', () => {
6
+ expect(Object.keys(index)).toMatchInlineSnapshot(`
7
+ [
8
+ "multicall3Abi",
9
+ "panicReasons",
10
+ "solidityError",
11
+ "solidityPanic",
12
+ ]
13
+ `)
14
+ })
@@ -0,0 +1,3 @@
1
+ export { multicall3Abi } from './abis'
2
+
3
+ export { panicReasons, solidityError, solidityPanic } from './solidity'
@@ -0,0 +1,41 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import * as solidity from './solidity'
4
+
5
+ test('exports solidity constants', () => {
6
+ expect(solidity).toMatchInlineSnapshot(`
7
+ {
8
+ "panicReasons": {
9
+ "1": "An \`assert\` condition failed.",
10
+ "17": "Arithmic operation resulted in underflow or overflow.",
11
+ "18": "Division or modulo by zero (e.g. \`5 / 0\` or \`23 % 0\`).",
12
+ "33": "Attempted to convert to an invalid type.",
13
+ "34": "Attempted to access a storage byte array that is incorrectly encoded.",
14
+ "49": "Performed \`.pop()\` on an empty array",
15
+ "50": "Array index is out of bounds.",
16
+ "65": "Allocated too much memory or created an array which is too large.",
17
+ "81": "Attempted to call a zero-initialized variable of internal function type.",
18
+ },
19
+ "solidityError": {
20
+ "inputs": [
21
+ {
22
+ "name": "message",
23
+ "type": "string",
24
+ },
25
+ ],
26
+ "name": "Error",
27
+ "type": "error",
28
+ },
29
+ "solidityPanic": {
30
+ "inputs": [
31
+ {
32
+ "name": "reason",
33
+ "type": "uint256",
34
+ },
35
+ ],
36
+ "name": "Panic",
37
+ "type": "error",
38
+ },
39
+ }
40
+ `)
41
+ })
@@ -0,0 +1,35 @@
1
+ import { AbiError } from 'abitype'
2
+
3
+ // https://docs.soliditylang.org/en/v0.8.16/control-structures.html#panic-via-assert-and-error-via-require
4
+ export const panicReasons = {
5
+ 1: 'An `assert` condition failed.',
6
+ 17: 'Arithmic operation resulted in underflow or overflow.',
7
+ 18: 'Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).',
8
+ 33: 'Attempted to convert to an invalid type.',
9
+ 34: 'Attempted to access a storage byte array that is incorrectly encoded.',
10
+ 49: 'Performed `.pop()` on an empty array',
11
+ 50: 'Array index is out of bounds.',
12
+ 65: 'Allocated too much memory or created an array which is too large.',
13
+ 81: 'Attempted to call a zero-initialized variable of internal function type.',
14
+ } as const
15
+
16
+ export const solidityError: AbiError = {
17
+ inputs: [
18
+ {
19
+ name: 'message',
20
+ type: 'string',
21
+ },
22
+ ],
23
+ name: 'Error',
24
+ type: 'error',
25
+ }
26
+ export const solidityPanic: AbiError = {
27
+ inputs: [
28
+ {
29
+ name: 'reason',
30
+ type: 'uint256',
31
+ },
32
+ ],
33
+ name: 'Panic',
34
+ type: 'error',
35
+ }
package/src/ens.ts ADDED
@@ -0,0 +1,5 @@
1
+ export {
2
+ labelhash,
3
+ namehash,
4
+ normalize,
5
+ } from './utils'
@@ -25,7 +25,6 @@ test('InvalidAbiDecodingTypeError', () => {
25
25
  Please provide a valid ABI type.
26
26
 
27
27
  Docs: https://viem.sh/lol
28
-
29
28
  Version: viem@1.0.2]
30
29
  `)
31
30
  })
@@ -69,7 +68,6 @@ test('InvalidAbiEncodingTypeError', () => {
69
68
  Please provide a valid ABI type.
70
69
 
71
70
  Docs: https://viem.sh/lol
72
-
73
71
  Version: viem@1.0.2]
74
72
  `)
75
73
  })