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.
- package/dist/{chain-32f56cfa.d.ts → chain-4b39613a.d.ts} +2 -2
- package/dist/{chain-f12cdc7f.d.ts → chain-aa4898d0.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-EC3NUIJE.js → chunk-7Y5QVLX7.js} +13 -13
- package/dist/{chunk-EC3NUIJE.js.map → chunk-7Y5QVLX7.js.map} +1 -1
- package/dist/{chunk-KEHGSYDO.js → chunk-BV5NTHUX.js} +14 -13
- package/dist/chunk-BV5NTHUX.js.map +1 -0
- package/dist/{chunk-46BO7YAQ.mjs → chunk-EGVXCZNJ.mjs} +4 -3
- package/dist/chunk-EGVXCZNJ.mjs.map +1 -0
- package/dist/{chunk-57ZOFERP.mjs → chunk-GX2KDAM3.mjs} +2 -2
- package/dist/{chunk-57ZOFERP.mjs.map → chunk-GX2KDAM3.mjs.map} +0 -0
- package/dist/{chunk-W7BWWAC4.js → chunk-NW6724MI.js} +14 -14
- package/dist/{chunk-W7BWWAC4.js.map → chunk-NW6724MI.js.map} +0 -0
- package/dist/{chunk-DGO77E2H.mjs → chunk-RJLUZTJS.mjs} +86 -3
- package/dist/chunk-RJLUZTJS.mjs.map +1 -0
- package/dist/{chunk-O2GYLJVD.js → chunk-SSPRUPGN.js} +405 -165
- package/dist/chunk-SSPRUPGN.js.map +1 -0
- package/dist/{chunk-DSPMAIDO.mjs → chunk-TXHOG6KU.mjs} +2 -2
- package/dist/{chunk-DSPMAIDO.mjs.map → chunk-TXHOG6KU.mjs.map} +1 -1
- package/dist/{chunk-62VTYU2V.mjs → chunk-XBUH66KN.mjs} +406 -166
- package/dist/chunk-XBUH66KN.mjs.map +1 -0
- package/dist/{chunk-KZMJR27B.js → chunk-ZKYGWITF.js} +147 -64
- package/dist/chunk-ZKYGWITF.js.map +1 -0
- package/dist/clients/index.d.ts +7 -7
- package/dist/clients/index.js +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/{contract-9af4608b.d.ts → contract-4c3a37b3.d.ts} +14 -3
- package/dist/{createClient-5d316c7e.d.ts → createClient-55a04188.d.ts} +2 -2
- package/dist/{createPublicClient-9d2b42e1.d.ts → createPublicClient-3b27b282.d.ts} +3 -3
- package/dist/{createTestClient-79498dab.d.ts → createTestClient-93f9eac6.d.ts} +3 -3
- package/dist/{createWalletClient-f69a5230.d.ts → createWalletClient-c10df94d.d.ts} +3 -3
- package/dist/{eip1193-6c485d63.d.ts → eip1193-4c24765a.d.ts} +1 -1
- package/dist/ens.d.ts +1 -0
- package/dist/ens.js +11 -0
- package/dist/ens.js.map +1 -0
- package/dist/ens.mjs +11 -0
- package/dist/ens.mjs.map +1 -0
- package/dist/index.d.ts +174 -113
- package/dist/index.js +16 -6
- package/dist/index.mjs +15 -5
- package/dist/normalize-ef9240c0.d.ts +33 -0
- package/dist/{parseGwei-4308ad80.d.ts → parseGwei-3411cf2d.d.ts} +101 -37
- package/dist/public.d.ts +9 -9
- package/dist/public.js +4 -4
- package/dist/public.mjs +3 -3
- package/dist/{sendTransaction-1c8290a9.d.ts → sendTransaction-f17a2389.d.ts} +3 -3
- package/dist/{stopImpersonatingAccount-7781842a.d.ts → stopImpersonatingAccount-afb26486.d.ts} +2 -2
- package/dist/test.d.ts +5 -5
- package/dist/test.js +3 -3
- package/dist/test.mjs +2 -2
- package/dist/{transactionRequest-341b6ed2.d.ts → transactionRequest-93e9f001.d.ts} +2 -2
- package/dist/utils/index.d.ts +14 -16
- package/dist/utils/index.js +8 -2
- package/dist/utils/index.mjs +7 -1
- package/dist/wallet.d.ts +7 -7
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/{watchAsset-afaad3c7.d.ts → watchAsset-efd3dd05.d.ts} +3 -3
- package/dist/{watchPendingTransactions-3b722547.d.ts → watchPendingTransactions-57df1a13.d.ts} +17 -27
- package/dist/{webSocket-b180e679.d.ts → webSocket-d2e7bd0e.d.ts} +2 -2
- package/dist/window.d.ts +2 -2
- package/package.json +8 -2
- package/src/_test/abis.ts +7 -0
- package/src/_test/bench.ts +4 -4
- package/src/_test/constants.ts +4 -3
- package/src/_test/index.ts +4 -2
- package/src/_test/utils.ts +39 -1
- package/src/actions/index.test.ts +1 -0
- package/src/actions/index.ts +2 -0
- package/src/actions/public/call.bench.ts +5 -5
- package/src/actions/public/deployContract.ts +4 -4
- package/src/actions/public/estimateGas.bench.ts +6 -6
- package/src/actions/public/getBlock.bench.ts +5 -5
- package/src/actions/public/getBlockNumber.bench.ts +5 -5
- package/src/actions/public/getFilterChanges.test.ts +9 -9
- package/src/actions/public/getFilterLogs.test.ts +7 -7
- package/src/actions/public/getGasPrice.bench.ts +1 -10
- package/src/actions/public/getLogs.test.ts +7 -7
- package/src/actions/public/getTransaction.bench.ts +5 -5
- package/src/actions/public/getTransactionReceipt.bench.ts +5 -5
- package/src/actions/public/index.test.ts +1 -0
- package/src/actions/public/index.ts +3 -0
- package/src/actions/public/multicall.test.ts +452 -0
- package/src/actions/public/multicall.ts +103 -0
- package/src/actions/public/readContract.test.ts +226 -26
- package/src/actions/public/readContract.ts +13 -27
- package/src/actions/public/simulateContract.bench.ts +10 -0
- package/src/actions/public/simulateContract.test.ts +209 -37
- package/src/actions/public/simulateContract.ts +17 -21
- package/src/actions/public/watchContractEvent.test.ts +61 -57
- package/src/actions/public/watchEvent.test.ts +42 -37
- package/src/actions/test/impersonateAccount.test.ts +4 -6
- package/src/actions/test/sendUnsignedTransaction.test.ts +2 -2
- package/src/actions/test/stopImpersonatingAccount.test.ts +5 -7
- package/src/actions/wallet/signMessage.test.ts +0 -1
- package/src/actions/wallet/switchChain.test.ts +1 -2
- package/src/actions/wallet/watchAsset.test.ts +1 -2
- package/src/actions/wallet/writeContract.test.ts +37 -7
- package/src/actions/wallet/writeContract.ts +5 -14
- package/src/clients/transports/fallback.test.ts +34 -0
- package/src/clients/transports/fallback.ts +3 -1
- package/src/clients/transports/http.test.ts +0 -1
- package/src/clients/transports/webSocket.test.ts +0 -1
- package/src/constants/abis.test.ts +53 -0
- package/src/constants/abis.ts +44 -0
- package/src/constants/index.test.ts +14 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/solidity.test.ts +41 -0
- package/src/constants/solidity.ts +35 -0
- package/src/ens.ts +5 -0
- package/src/errors/abi.test.ts +0 -2
- package/src/errors/base.test.ts +44 -2
- package/src/errors/base.ts +12 -12
- package/src/errors/block.test.ts +6 -6
- package/src/errors/contract.test.ts +233 -0
- package/src/errors/contract.ts +133 -80
- package/src/errors/index.ts +4 -2
- package/src/errors/request.test.ts +3 -4
- package/src/errors/request.ts +17 -17
- package/src/errors/rpc.test.ts +1 -2
- package/src/errors/transaction.test.ts +12 -12
- package/src/errors/transport.test.ts +0 -1
- package/src/index.test.ts +47 -0
- package/src/index.ts +10 -0
- package/src/types/contract.ts +55 -4
- package/src/types/index.ts +5 -0
- package/src/types/multicall.ts +82 -0
- package/src/utils/abi/decodeAbi.test.ts +1 -2
- package/src/utils/abi/decodeAbi.ts +11 -7
- package/src/utils/abi/decodeDeployData.test.ts +7 -15
- package/src/utils/abi/decodeDeployData.ts +10 -7
- package/src/utils/abi/decodeErrorResult.test.ts +103 -3
- package/src/utils/abi/decodeErrorResult.ts +30 -13
- package/src/utils/abi/decodeFunctionData.test.ts +0 -1
- package/src/utils/abi/decodeFunctionResult.test.ts +80 -9
- package/src/utils/abi/decodeFunctionResult.ts +15 -11
- package/src/utils/abi/encodeAbi.test.ts +3 -4
- package/src/utils/abi/encodeAbi.ts +19 -10
- package/src/utils/abi/encodeDeployData.test.ts +6 -13
- package/src/utils/abi/encodeDeployData.ts +10 -7
- package/src/utils/abi/encodeErrorResult.test.ts +2 -7
- package/src/utils/abi/encodeErrorResult.ts +18 -11
- package/src/utils/abi/encodeEventTopics.test.ts +11 -14
- package/src/utils/abi/encodeEventTopics.ts +15 -9
- package/src/utils/abi/encodeFunctionData.test.ts +5 -7
- package/src/utils/abi/encodeFunctionData.ts +16 -9
- package/src/utils/abi/encodeFunctionResult.test.ts +10 -15
- package/src/utils/abi/encodeFunctionResult.ts +9 -7
- package/src/utils/abi/getAbiItem.test.ts +547 -0
- package/src/utils/abi/getAbiItem.ts +93 -3
- package/src/utils/abi/index.ts +5 -1
- package/src/utils/address/getAddress.test.ts +6 -6
- package/src/utils/contract/getContractError.test.ts +247 -62
- package/src/utils/contract/getContractError.ts +30 -38
- package/src/utils/data/pad.bench.ts +0 -9
- package/src/utils/data/trim.bench.ts +0 -16
- package/src/utils/encoding/encodeBytes.bench.ts +0 -12
- package/src/utils/encoding/encodeHex.bench.ts +0 -11
- package/src/utils/ens/index.test.ts +13 -0
- package/src/utils/ens/index.ts +5 -0
- package/src/utils/ens/labelhash.test.ts +55 -0
- package/src/utils/ens/labelhash.ts +16 -0
- package/src/utils/ens/namehash.test.ts +65 -0
- package/src/utils/ens/namehash.ts +28 -0
- package/src/utils/ens/normalize.bench.ts +14 -0
- package/src/utils/ens/normalize.test.ts +35 -0
- package/src/utils/ens/normalize.ts +14 -0
- package/src/utils/hash/keccak256.ts +3 -5
- package/src/utils/index.test.ts +3 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/rpc.test.ts +3 -6
- package/src/utils/unit/formatUnit.bench.ts +0 -5
- package/src/utils/unit/parseUnit.bench.ts +0 -5
- package/dist/chunk-46BO7YAQ.mjs.map +0 -1
- package/dist/chunk-62VTYU2V.mjs.map +0 -1
- package/dist/chunk-DGO77E2H.mjs.map +0 -1
- package/dist/chunk-KEHGSYDO.js.map +0 -1
- package/dist/chunk-KZMJR27B.js.map +0 -1
- 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:
|
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:
|
27
|
+
address: address.vitalik,
|
27
28
|
})
|
28
29
|
})
|
29
30
|
|
30
|
-
test(
|
31
|
-
|
31
|
+
test(
|
32
|
+
'default',
|
33
|
+
async () => {
|
34
|
+
let logs: OnLogsResponse[] = []
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
const unwatch = watchEvent(publicClient, {
|
37
|
+
onLogs: (logs_) => logs.push(logs_),
|
38
|
+
})
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
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:
|
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:
|
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:
|
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:
|
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:
|
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,
|
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:
|
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:
|
17
|
+
await impersonateAccount(testClient, { address: address.vitalik })
|
20
18
|
|
21
19
|
expect(
|
22
20
|
await sendTransaction(walletClient, {
|
23
|
-
from:
|
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
|
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:
|
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,
|
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:
|
10
|
+
await impersonateAccount(testClient, { address: address.vitalik })
|
13
11
|
|
14
12
|
expect(
|
15
13
|
await sendTransaction(walletClient, {
|
16
|
-
from:
|
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:
|
20
|
+
await stopImpersonatingAccount(testClient, { address: address.vitalik })
|
23
21
|
|
24
22
|
await expect(
|
25
23
|
sendTransaction(walletClient, {
|
26
|
-
from:
|
24
|
+
from: address.vitalik,
|
27
25
|
to: accounts[0].address,
|
28
26
|
value: parseEther('1'),
|
29
27
|
}),
|
@@ -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
|
-
|
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: [
|
70
|
+
args: [69421n],
|
42
71
|
}),
|
43
72
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
44
|
-
"
|
45
|
-
|
46
|
-
|
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: (
|
78
|
+
Arguments: (69421)
|
79
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
50
80
|
|
51
|
-
|
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 =
|
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
|
-
} &
|
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
|
34
|
-
TFunctionName extends string
|
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)
|
35
|
+
if (!(err instanceof RpcError) && i < transports.length - 1)
|
36
|
+
return fetch(i + 1)
|
35
37
|
throw err
|
36
38
|
}
|
37
39
|
}
|
@@ -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,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
package/src/errors/abi.test.ts
CHANGED
@@ -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
|
})
|