viem 0.0.1-alpha.23 → 0.0.1-alpha.25
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/contract/package.json +4 -0
- package/dist/call-ac509982.d.ts +23 -0
- package/dist/{chain-aa4898d0.d.ts → chain-c4ccb458.d.ts} +1 -1
- package/dist/{chain-4b39613a.d.ts → chain-f16512e8.d.ts} +20 -1
- package/dist/chains.d.ts +20 -8
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-RJLUZTJS.mjs → chunk-2Y3UZMSP.mjs} +203 -84
- package/dist/chunk-2Y3UZMSP.mjs.map +1 -0
- package/dist/{chunk-ZKYGWITF.js → chunk-CD2XJOBJ.js} +261 -142
- package/dist/chunk-CD2XJOBJ.js.map +1 -0
- package/dist/{chunk-XBUH66KN.mjs → chunk-KSAO4Y4Q.mjs} +133 -54
- package/dist/chunk-KSAO4Y4Q.mjs.map +1 -0
- package/dist/{chunk-TXHOG6KU.mjs → chunk-LEPQJNVO.mjs} +18 -2
- package/dist/chunk-LEPQJNVO.mjs.map +1 -0
- package/dist/{chunk-7Y5QVLX7.js → chunk-NUXMGPMK.js} +30 -14
- package/dist/chunk-NUXMGPMK.js.map +1 -0
- package/dist/{chunk-SSPRUPGN.js → chunk-THMRUG4D.js} +148 -69
- package/dist/chunk-THMRUG4D.js.map +1 -0
- package/dist/{contract-4c3a37b3.d.ts → contract-9e76e561.d.ts} +44 -31
- package/dist/contract.d.ts +123 -0
- package/dist/contract.js +53 -0
- package/dist/{clients/index.js.map → contract.js.map} +0 -0
- package/dist/contract.mjs +53 -0
- package/dist/{clients/index.mjs.map → contract.mjs.map} +0 -0
- package/dist/{createClient-55a04188.d.ts → createClient-68ee4bb4.d.ts} +3 -3
- package/dist/{createPublicClient-3b27b282.d.ts → createPublicClient-b732194e.d.ts} +3 -3
- package/dist/{createTestClient-93f9eac6.d.ts → createTestClient-dedf321e.d.ts} +3 -3
- package/dist/{createWalletClient-c10df94d.d.ts → createWalletClient-75813d83.d.ts} +3 -3
- package/dist/decodeErrorResult-0b934d23.d.ts +16 -0
- package/dist/{eip1193-4c24765a.d.ts → eip1193-6f9ba163.d.ts} +1 -1
- package/dist/ens.d.ts +82 -1
- package/dist/ens.js +208 -3
- package/dist/ens.js.map +1 -1
- package/dist/ens.mjs +209 -4
- package/dist/ens.mjs.map +1 -1
- package/dist/getAbiItem-c8e6e7d4.d.ts +97 -0
- package/dist/index.d.ts +85 -133
- package/dist/index.js +237 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +245 -283
- package/dist/index.mjs.map +1 -1
- package/dist/public.d.ts +352 -10
- package/dist/public.js +3 -4
- package/dist/public.mjs +6 -7
- package/dist/readContract-4f6e2692.d.ts +10 -0
- package/dist/rpc-a5a7f376.d.ts +121 -0
- package/dist/{sendTransaction-f17a2389.d.ts → sendTransaction-e713f90c.d.ts} +3 -3
- package/dist/test.d.ts +160 -5
- package/dist/test.js +222 -18
- package/dist/test.js.map +1 -1
- package/dist/test.mjs +233 -29
- package/dist/test.mjs.map +1 -1
- package/dist/transactionReceipt-2a86c7c7.d.ts +26 -0
- package/dist/{transactionRequest-93e9f001.d.ts → transactionRequest-c7794f5e.d.ts} +1 -1
- package/dist/utils/index.d.ts +224 -20
- package/dist/utils/index.js +2 -6
- package/dist/utils/index.mjs +3 -7
- package/dist/wallet.d.ts +41 -7
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/watchEvent-c346c12d.d.ts +41 -0
- package/dist/window.d.ts +2 -2
- package/ens/package.json +4 -0
- package/package.json +13 -9
- package/src/_test/constants.ts +2 -0
- package/src/_test/utils.ts +10 -5
- package/src/actions/ens/getEnsAddress.bench.ts +26 -0
- package/src/actions/ens/getEnsAddress.test.ts +97 -0
- package/src/actions/ens/getEnsAddress.ts +122 -0
- package/src/actions/ens/getEnsName.bench.ts +30 -0
- package/src/actions/ens/getEnsName.test.ts +101 -0
- package/src/actions/ens/getEnsName.ts +106 -0
- package/src/actions/ens/index.test.ts +12 -0
- package/src/actions/ens/index.ts +3 -0
- package/src/actions/index.test.ts +2 -0
- package/src/actions/index.ts +9 -3
- package/src/actions/public/createEventFilter.test.ts +36 -4
- package/src/actions/public/createEventFilter.ts +27 -10
- package/src/actions/public/getFilterChanges.test.ts +198 -4
- package/src/actions/public/getFilterLogs.test.ts +195 -2
- package/src/actions/public/getLogs.test.ts +201 -2
- package/src/actions/public/index.test.ts +0 -1
- package/src/actions/public/index.ts +1 -7
- package/src/actions/public/multicall.ts +8 -3
- package/src/actions/public/simulateContract.ts +1 -4
- package/src/actions/public/watchContractEvent.test.ts +4 -4
- package/src/actions/{public → wallet}/deployContract.test.ts +1 -2
- package/src/actions/{public → wallet}/deployContract.ts +0 -0
- package/src/actions/wallet/index.test.ts +1 -0
- package/src/actions/wallet/index.ts +6 -0
- package/src/chains.test.ts +44 -1517
- package/src/clients/transports/webSocket.test.ts +1 -0
- package/src/clients/transports/webSocket.ts +1 -0
- package/src/contract.test.ts +31 -0
- package/src/contract.ts +68 -0
- package/src/ens.test.ts +15 -0
- package/src/ens.ts +4 -1
- package/src/errors/abi.ts +18 -2
- package/src/errors/chain.test.ts +46 -0
- package/src/errors/chain.ts +33 -0
- package/src/errors/contract.ts +2 -2
- package/src/errors/index.ts +3 -0
- package/src/index.test.ts +0 -145
- package/src/index.ts +0 -251
- package/src/public.test.ts +36 -0
- package/src/public.ts +2 -6
- package/src/test.test.ts +38 -0
- package/src/test.ts +1 -0
- package/src/types/contract.ts +144 -40
- package/src/types/index.ts +2 -1
- package/src/types/utils.ts +21 -0
- package/src/utils/abi/decodeErrorResult.test.ts +1 -1
- package/src/utils/abi/decodeEventLog.test.ts +542 -0
- package/src/utils/abi/decodeEventLog.ts +107 -0
- package/src/utils/abi/decodeFunctionData.test.ts +1 -2
- package/src/utils/abi/decodeFunctionData.ts +5 -2
- package/src/utils/abi/encodeFunctionData.ts +1 -4
- package/src/utils/abi/index.test.ts +1 -0
- package/src/utils/abi/index.ts +6 -0
- package/src/utils/ens/index.test.ts +1 -0
- package/src/utils/ens/index.ts +2 -0
- package/src/utils/ens/packetToBytes.test.ts +11 -0
- package/src/utils/ens/packetToBytes.ts +29 -0
- package/src/utils/index.test.ts +1 -3
- package/src/utils/index.ts +3 -2
- package/src/utils/rpc.test.ts +1 -0
- package/src/utils/rpc.ts +4 -2
- package/src/wallet.test.ts +19 -0
- package/wallet/package.json +4 -0
- package/clients/package.json +0 -4
- package/dist/chunk-7Y5QVLX7.js.map +0 -1
- package/dist/chunk-BV5NTHUX.js +0 -260
- package/dist/chunk-BV5NTHUX.js.map +0 -1
- package/dist/chunk-EGVXCZNJ.mjs +0 -260
- package/dist/chunk-EGVXCZNJ.mjs.map +0 -1
- package/dist/chunk-GX2KDAM3.mjs +0 -256
- package/dist/chunk-GX2KDAM3.mjs.map +0 -1
- package/dist/chunk-NW6724MI.js +0 -256
- package/dist/chunk-NW6724MI.js.map +0 -1
- package/dist/chunk-RJLUZTJS.mjs.map +0 -1
- package/dist/chunk-SSPRUPGN.js.map +0 -1
- package/dist/chunk-TXHOG6KU.mjs.map +0 -1
- package/dist/chunk-XBUH66KN.mjs.map +0 -1
- package/dist/chunk-ZKYGWITF.js.map +0 -1
- package/dist/clients/index.d.ts +0 -9
- package/dist/clients/index.js +0 -24
- package/dist/clients/index.mjs +0 -24
- package/dist/normalize-ef9240c0.d.ts +0 -33
- package/dist/parseGwei-3411cf2d.d.ts +0 -355
- package/dist/rpc-26932bae.d.ts +0 -61
- package/dist/stopImpersonatingAccount-afb26486.d.ts +0 -156
- package/dist/watchAsset-efd3dd05.d.ts +0 -38
- package/dist/watchPendingTransactions-57df1a13.d.ts +0 -373
- package/dist/webSocket-d2e7bd0e.d.ts +0 -83
package/dist/utils/index.mjs
CHANGED
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
decodeAbi,
|
11
11
|
decodeBytes,
|
12
12
|
decodeErrorResult,
|
13
|
+
decodeEventLog,
|
13
14
|
decodeFunctionData,
|
14
15
|
decodeFunctionResult,
|
15
16
|
decodeHex,
|
@@ -63,9 +64,6 @@ import {
|
|
63
64
|
isBytes,
|
64
65
|
isHex,
|
65
66
|
keccak256,
|
66
|
-
labelhash,
|
67
|
-
namehash,
|
68
|
-
normalize,
|
69
67
|
numberToBytes,
|
70
68
|
numberToHex,
|
71
69
|
pad,
|
@@ -85,7 +83,7 @@ import {
|
|
85
83
|
transactionType,
|
86
84
|
trim,
|
87
85
|
weiUnits
|
88
|
-
} from "../chunk-
|
86
|
+
} from "../chunk-KSAO4Y4Q.mjs";
|
89
87
|
export {
|
90
88
|
boolToBytes,
|
91
89
|
boolToHex,
|
@@ -98,6 +96,7 @@ export {
|
|
98
96
|
decodeAbi,
|
99
97
|
decodeBytes,
|
100
98
|
decodeErrorResult,
|
99
|
+
decodeEventLog,
|
101
100
|
decodeFunctionData,
|
102
101
|
decodeFunctionResult,
|
103
102
|
decodeHex,
|
@@ -151,9 +150,6 @@ export {
|
|
151
150
|
isBytes,
|
152
151
|
isHex,
|
153
152
|
keccak256,
|
154
|
-
labelhash,
|
155
|
-
namehash,
|
156
|
-
normalize,
|
157
153
|
numberToBytes,
|
158
154
|
numberToHex,
|
159
155
|
pad,
|
package/dist/wallet.d.ts
CHANGED
@@ -1,8 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import './
|
1
|
+
import { C as Chain, A as Address, H as Hex, B as ByteArray } from './chain-f16512e8.js';
|
2
|
+
import { W as WalletClient } from './createWalletClient-75813d83.js';
|
3
|
+
import { a as WalletPermission, b as WatchAssetParams } from './eip1193-6f9ba163.js';
|
4
|
+
export { F as FormattedTransactionRequest, S as SendTransactionArgs, a as SendTransactionResponse, s as sendTransaction } from './sendTransaction-e713f90c.js';
|
4
5
|
import '@wagmi/chains';
|
5
|
-
import './
|
6
|
-
import './
|
7
|
-
|
8
|
-
|
6
|
+
import './createClient-68ee4bb4.js';
|
7
|
+
import './transactionRequest-c7794f5e.js';
|
8
|
+
|
9
|
+
declare function addChain(client: WalletClient, chain: Chain): Promise<void>;
|
10
|
+
|
11
|
+
declare function getAccounts(client: WalletClient): Promise<`0x${string}`[]>;
|
12
|
+
|
13
|
+
type GetPermissionsResponse = WalletPermission[];
|
14
|
+
declare function getPermissions(client: WalletClient): Promise<WalletPermission[]>;
|
15
|
+
|
16
|
+
declare function requestAccounts(client: WalletClient): Promise<`0x${string}`[]>;
|
17
|
+
|
18
|
+
type RequestPermissionsArgs = {
|
19
|
+
eth_accounts: Record<string, any>;
|
20
|
+
} & {
|
21
|
+
[key: string]: Record<string, any>;
|
22
|
+
};
|
23
|
+
type RequestPermissionsResponse = WalletPermission[];
|
24
|
+
declare function requestPermissions(client: WalletClient, permissions: RequestPermissionsArgs): Promise<WalletPermission[]>;
|
25
|
+
|
26
|
+
type SignMessageArgs = {
|
27
|
+
from: Address;
|
28
|
+
data: Hex | ByteArray;
|
29
|
+
};
|
30
|
+
type SignMessageResponse = Hex;
|
31
|
+
declare function signMessage(client: WalletClient, { from, data: data_ }: SignMessageArgs): Promise<SignMessageResponse>;
|
32
|
+
|
33
|
+
type SwitchChainArgs = {
|
34
|
+
id: Chain['id'];
|
35
|
+
};
|
36
|
+
declare function switchChain(client: WalletClient, { id }: SwitchChainArgs): Promise<void>;
|
37
|
+
|
38
|
+
type WatchAssetArgs = WatchAssetParams;
|
39
|
+
type WatchAssetResponse = boolean;
|
40
|
+
declare function watchAsset(client: WalletClient, params: WatchAssetParams): Promise<WatchAssetResponse>;
|
41
|
+
|
42
|
+
export { GetPermissionsResponse, RequestPermissionsResponse, SignMessageArgs, SignMessageResponse, SwitchChainArgs, WatchAssetArgs, WatchAssetResponse, addChain, getAccounts, getPermissions, requestAccounts, requestPermissions, signMessage, switchChain, watchAsset };
|
package/dist/wallet.js
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
var
|
12
|
-
require('./chunk-
|
11
|
+
var _chunkNUXMGPMKjs = require('./chunk-NUXMGPMK.js');
|
12
|
+
require('./chunk-THMRUG4D.js');
|
13
13
|
|
14
14
|
|
15
15
|
|
@@ -20,5 +20,5 @@ require('./chunk-SSPRUPGN.js');
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
exports.addChain =
|
23
|
+
exports.addChain = _chunkNUXMGPMKjs.addChain; exports.getAccounts = _chunkNUXMGPMKjs.getAccounts; exports.getPermissions = _chunkNUXMGPMKjs.getPermissions; exports.requestAccounts = _chunkNUXMGPMKjs.requestAccounts; exports.requestPermissions = _chunkNUXMGPMKjs.requestPermissions; exports.sendTransaction = _chunkNUXMGPMKjs.sendTransaction; exports.signMessage = _chunkNUXMGPMKjs.signMessage; exports.switchChain = _chunkNUXMGPMKjs.switchChain; exports.watchAsset = _chunkNUXMGPMKjs.watchAsset;
|
24
24
|
//# sourceMappingURL=wallet.js.map
|
package/dist/wallet.mjs
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
import { A as Address, b as BlockTag, H as Hex, L as Log } from './chain-f16512e8.js';
|
2
|
+
import { P as PublicClient } from './createPublicClient-b732194e.js';
|
3
|
+
import { j as EventDefinition, k as ExtractArgsFromEventDefinition } from './contract-9e76e561.js';
|
4
|
+
|
5
|
+
type EventFilterArgs<TEventDefinition extends EventDefinition> = ExtractArgsFromEventDefinition<TEventDefinition>;
|
6
|
+
|
7
|
+
type GetBytecodeArgs = {
|
8
|
+
address: Address;
|
9
|
+
} & ({
|
10
|
+
blockNumber?: never;
|
11
|
+
blockTag?: BlockTag;
|
12
|
+
} | {
|
13
|
+
blockNumber?: bigint;
|
14
|
+
blockTag?: never;
|
15
|
+
});
|
16
|
+
type GetBytecodeResponse = Hex | undefined;
|
17
|
+
declare function getBytecode(client: PublicClient, { address, blockNumber, blockTag }: GetBytecodeArgs): Promise<GetBytecodeResponse>;
|
18
|
+
|
19
|
+
type OnLogsResponse = Log[];
|
20
|
+
type OnLogs = (logs: OnLogsResponse) => void;
|
21
|
+
type WatchEventArgs<TEventDefinition extends EventDefinition> = {
|
22
|
+
/** The address of the contract. */
|
23
|
+
address?: Address | Address[];
|
24
|
+
/** Whether or not the event logs should be batched on each invocation. */
|
25
|
+
batch?: boolean;
|
26
|
+
/** The callback to call when an error occurred when trying to get for a new block. */
|
27
|
+
onError?: (error: Error) => void;
|
28
|
+
/** The callback to call when new event logs are received. */
|
29
|
+
onLogs: OnLogs;
|
30
|
+
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
|
31
|
+
pollingInterval?: number;
|
32
|
+
} & ({
|
33
|
+
event: TEventDefinition;
|
34
|
+
args?: EventFilterArgs<TEventDefinition>;
|
35
|
+
} | {
|
36
|
+
event?: never;
|
37
|
+
args?: never;
|
38
|
+
});
|
39
|
+
declare function watchEvent<TEventDefinition extends EventDefinition>(client: PublicClient, { address, args, batch, event, onError, onLogs, pollingInterval, }: WatchEventArgs<TEventDefinition>): () => void;
|
40
|
+
|
41
|
+
export { EventFilterArgs as E, GetBytecodeArgs as G, OnLogs as O, GetBytecodeResponse as a, OnLogsResponse as b, getBytecode as g, watchEvent as w };
|
package/dist/window.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { R as Requests, E as Events } from './eip1193-
|
2
|
-
import './chain-
|
1
|
+
import { R as Requests, E as Events } from './eip1193-6f9ba163.js';
|
2
|
+
import './chain-f16512e8.js';
|
3
3
|
import '@wagmi/chains';
|
4
4
|
|
5
5
|
type WindowProvider = Requests & Events;
|
package/ens/package.json
ADDED
package/package.json
CHANGED
@@ -3,19 +3,23 @@
|
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
4
|
"dependencies": {
|
5
5
|
"@noble/hashes": "^1.1.2",
|
6
|
-
"@wagmi/chains": "~0.2.
|
6
|
+
"@wagmi/chains": "~0.2.8",
|
7
7
|
"abitype": "~0.3.0",
|
8
|
-
"idna-uts46-hx": "^4.1.2"
|
8
|
+
"idna-uts46-hx": "^4.1.2",
|
9
|
+
"isomorphic-unfetch": "^4.0.2",
|
10
|
+
"isomorphic-ws": "^5.0.0",
|
11
|
+
"ws": "^8.12.0"
|
9
12
|
},
|
10
|
-
"version": "0.0.1-alpha.
|
13
|
+
"version": "0.0.1-alpha.25",
|
11
14
|
"files": [
|
12
|
-
"/actions",
|
13
15
|
"/chains",
|
16
|
+
"/contract",
|
14
17
|
"/dist",
|
15
|
-
"/
|
18
|
+
"/ens",
|
16
19
|
"/src",
|
17
20
|
"/types",
|
18
21
|
"/utils",
|
22
|
+
"/wallet",
|
19
23
|
"/window"
|
20
24
|
],
|
21
25
|
"exports": {
|
@@ -29,10 +33,10 @@
|
|
29
33
|
"module": "./dist/chains.mjs",
|
30
34
|
"default": "./dist/chains.js"
|
31
35
|
},
|
32
|
-
"./
|
33
|
-
"types": "./dist/
|
34
|
-
"module": "./dist/
|
35
|
-
"default": "./dist/
|
36
|
+
"./contract": {
|
37
|
+
"types": "./dist/contract.d.ts",
|
38
|
+
"module": "./dist/contract.mjs",
|
39
|
+
"default": "./dist/contract.js"
|
36
40
|
},
|
37
41
|
"./ens": {
|
38
42
|
"types": "./dist/ens.d.ts",
|
package/src/_test/constants.ts
CHANGED
@@ -44,6 +44,8 @@ export const accounts = [
|
|
44
44
|
] as const
|
45
45
|
|
46
46
|
export const address = {
|
47
|
+
burn: '0x0000000000000000000000000000000000000000',
|
48
|
+
usdcHolder: '0x5414d89a8bf7e99d732bc52f3e6a3ef461c0c078',
|
47
49
|
vitalik: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
|
48
50
|
} as const
|
49
51
|
|
package/src/_test/utils.ts
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
getTransactionReceipt,
|
8
8
|
mine,
|
9
9
|
} from '../actions'
|
10
|
-
import { Chain, localhost } from '../chains'
|
10
|
+
import { Chain, localhost, mainnet } from '../chains'
|
11
11
|
import {
|
12
12
|
createPublicClient,
|
13
13
|
createTestClient,
|
@@ -27,15 +27,20 @@ import type { AddressInfo } from 'net'
|
|
27
27
|
import { baycContractConfig } from './abis'
|
28
28
|
import { Hex } from '../types'
|
29
29
|
|
30
|
+
const anvil = {
|
31
|
+
...localhost,
|
32
|
+
contracts: mainnet.contracts,
|
33
|
+
} as const satisfies Chain
|
34
|
+
|
30
35
|
export const publicClient =
|
31
36
|
process.env.VITE_NETWORK_TRANSPORT_MODE === 'webSocket'
|
32
37
|
? createPublicClient({
|
33
|
-
chain:
|
38
|
+
chain: anvil,
|
34
39
|
pollingInterval: 1_000,
|
35
40
|
transport: webSocket(localWsUrl),
|
36
41
|
})
|
37
42
|
: createPublicClient({
|
38
|
-
chain:
|
43
|
+
chain: anvil,
|
39
44
|
pollingInterval: 1_000,
|
40
45
|
transport: http(),
|
41
46
|
})
|
@@ -86,7 +91,7 @@ export const walletClient = createWalletClient({
|
|
86
91
|
},
|
87
92
|
]
|
88
93
|
|
89
|
-
const { result } = await rpc.http(
|
94
|
+
const { result } = await rpc.http(anvil.rpcUrls.default.http[0], {
|
90
95
|
body: {
|
91
96
|
method,
|
92
97
|
params,
|
@@ -98,7 +103,7 @@ export const walletClient = createWalletClient({
|
|
98
103
|
})
|
99
104
|
|
100
105
|
export const testClient = createTestClient({
|
101
|
-
chain:
|
106
|
+
chain: anvil,
|
102
107
|
mode: 'anvil',
|
103
108
|
transport: http(),
|
104
109
|
})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { bench, describe } from 'vitest'
|
2
|
+
|
3
|
+
import {
|
4
|
+
ethersProvider,
|
5
|
+
ethersV6Provider,
|
6
|
+
publicClient,
|
7
|
+
web3Provider,
|
8
|
+
} from '../../_test'
|
9
|
+
|
10
|
+
import { getEnsAddress } from './getEnsAddress'
|
11
|
+
|
12
|
+
describe('Get ENS Name', () => {
|
13
|
+
bench('viem: `getEnsAddress`', async () => {
|
14
|
+
await getEnsAddress(publicClient, {
|
15
|
+
name: 'awkweb.eth',
|
16
|
+
})
|
17
|
+
})
|
18
|
+
|
19
|
+
bench('ethers: `resolveName`', async () => {
|
20
|
+
await ethersProvider.resolveName('awkweb.eth')
|
21
|
+
})
|
22
|
+
|
23
|
+
bench('ethers@6: `resolveName`', async () => {
|
24
|
+
await ethersV6Provider.resolveName('awkweb.eth')
|
25
|
+
})
|
26
|
+
})
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
import { optimism } from '../../chains'
|
3
|
+
import { createPublicClient, http } from '../../clients'
|
4
|
+
|
5
|
+
import { localHttpUrl, publicClient } from '../../_test'
|
6
|
+
import { getEnsAddress } from './getEnsAddress'
|
7
|
+
|
8
|
+
test('gets address for name', async () => {
|
9
|
+
await expect(
|
10
|
+
getEnsAddress(publicClient, { name: 'awkweb.eth' }),
|
11
|
+
).resolves.toMatchInlineSnapshot(
|
12
|
+
'"0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"',
|
13
|
+
)
|
14
|
+
})
|
15
|
+
|
16
|
+
test('name without address', async () => {
|
17
|
+
await expect(
|
18
|
+
getEnsAddress(publicClient, { name: 'unregistered-name.eth' }),
|
19
|
+
).resolves.toMatchInlineSnapshot(
|
20
|
+
'"0x0000000000000000000000000000000000000000"',
|
21
|
+
)
|
22
|
+
})
|
23
|
+
|
24
|
+
test('custom universal resolver address', async () => {
|
25
|
+
await expect(
|
26
|
+
getEnsAddress(publicClient, {
|
27
|
+
name: 'awkweb.eth',
|
28
|
+
universalResolverAddress: '0x74E20Bd2A1fE0cdbe45b9A1d89cb7e0a45b36376',
|
29
|
+
}),
|
30
|
+
).resolves.toMatchInlineSnapshot(
|
31
|
+
'"0xA0Cf798816D4b9b9866b5330EEa46a18382f251e"',
|
32
|
+
)
|
33
|
+
})
|
34
|
+
|
35
|
+
test('chain not provided', async () => {
|
36
|
+
await expect(
|
37
|
+
getEnsAddress(
|
38
|
+
createPublicClient({
|
39
|
+
transport: http(localHttpUrl),
|
40
|
+
}),
|
41
|
+
{ name: 'awkweb.eth' },
|
42
|
+
),
|
43
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
44
|
+
'"client chain not configured. universalResolverAddress is required."',
|
45
|
+
)
|
46
|
+
})
|
47
|
+
|
48
|
+
test('universal resolver contract not configured for chain', async () => {
|
49
|
+
await expect(
|
50
|
+
getEnsAddress(
|
51
|
+
createPublicClient({
|
52
|
+
chain: optimism,
|
53
|
+
transport: http(),
|
54
|
+
}),
|
55
|
+
{ name: 'awkweb.eth' },
|
56
|
+
),
|
57
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
58
|
+
"Chain \\"Optimism\\" does not support contract \\"ensUniversalResolver\\".
|
59
|
+
|
60
|
+
This could be due to any of the following:
|
61
|
+
- The chain does not have the contract \\"ensUniversalResolver\\" configured.
|
62
|
+
|
63
|
+
Version: viem@1.0.2"
|
64
|
+
`)
|
65
|
+
})
|
66
|
+
|
67
|
+
test('universal resolver contract deployed on later block', async () => {
|
68
|
+
await expect(
|
69
|
+
getEnsAddress(publicClient, { name: 'awkweb.eth', blockNumber: 14353601n }),
|
70
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
71
|
+
"Chain \\"Localhost\\" does not support contract \\"ensUniversalResolver\\".
|
72
|
+
|
73
|
+
This could be due to any of the following:
|
74
|
+
- The contract \\"ensUniversalResolver\\" was not deployed until block 16172161 (current block 14353601).
|
75
|
+
|
76
|
+
Version: viem@1.0.2"
|
77
|
+
`)
|
78
|
+
})
|
79
|
+
|
80
|
+
test('invalid universal resolver address', async () => {
|
81
|
+
await expect(
|
82
|
+
getEnsAddress(publicClient, {
|
83
|
+
name: 'awkweb.eth',
|
84
|
+
universalResolverAddress: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
|
85
|
+
}),
|
86
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
87
|
+
"The contract function \\"resolve\\" reverted with the following reason:
|
88
|
+
execution reverted
|
89
|
+
|
90
|
+
Contract: 0x0000000000000000000000000000000000000000
|
91
|
+
Function: resolve(bytes name, bytes data)
|
92
|
+
Arguments: (0x0661776b7765620365746800, 0x3b3b57de52d0f5fbf348925621be297a61b88ec492ebbbdfa9477d82892e2786020ad61c)
|
93
|
+
|
94
|
+
Docs: https://viem.sh/docs/contract/readContract
|
95
|
+
Version: viem@1.0.2"
|
96
|
+
`)
|
97
|
+
})
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import { PublicClient } from '../../clients'
|
2
|
+
import { ChainDoesNotSupportContract } from '../../errors'
|
3
|
+
import type { Address, Prettify } from '../../types'
|
4
|
+
import {
|
5
|
+
decodeFunctionResult,
|
6
|
+
encodeFunctionData,
|
7
|
+
encodeHex,
|
8
|
+
} from '../../utils'
|
9
|
+
import { namehash, packetToBytes } from '../../utils/ens'
|
10
|
+
import { readContract, ReadContractArgs } from '../public'
|
11
|
+
|
12
|
+
export type GetEnsAddressArgs = Prettify<
|
13
|
+
Pick<ReadContractArgs, 'blockNumber' | 'blockTag'> & {
|
14
|
+
/** ENS name to get address. */
|
15
|
+
name: string
|
16
|
+
/** Address of ENS Universal Resolver Contract */
|
17
|
+
universalResolverAddress?: Address
|
18
|
+
}
|
19
|
+
>
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @description Gets address for ENS name.
|
23
|
+
*
|
24
|
+
* - Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract.
|
25
|
+
*
|
26
|
+
* @example
|
27
|
+
* const ensAddress = await getEnsAddress(publicClient, {
|
28
|
+
* name: 'wagmi-dev.eth',
|
29
|
+
* })
|
30
|
+
* // '0xd2135CfB216b74109775236E36d4b433F1DF507B'
|
31
|
+
*/
|
32
|
+
export async function getEnsAddress(
|
33
|
+
client: PublicClient,
|
34
|
+
{
|
35
|
+
blockNumber,
|
36
|
+
blockTag,
|
37
|
+
name,
|
38
|
+
universalResolverAddress: universalResolverAddress_,
|
39
|
+
}: GetEnsAddressArgs,
|
40
|
+
) {
|
41
|
+
let universalResolverAddress = universalResolverAddress_
|
42
|
+
if (!universalResolverAddress) {
|
43
|
+
if (!client.chain)
|
44
|
+
throw new Error(
|
45
|
+
'client chain not configured. universalResolverAddress is required.',
|
46
|
+
)
|
47
|
+
|
48
|
+
const contract = client.chain?.contracts?.ensUniversalResolver
|
49
|
+
if (!contract)
|
50
|
+
throw new ChainDoesNotSupportContract({
|
51
|
+
chain: client.chain,
|
52
|
+
contract: { name: 'ensUniversalResolver' },
|
53
|
+
})
|
54
|
+
|
55
|
+
if (
|
56
|
+
blockNumber &&
|
57
|
+
contract.blockCreated &&
|
58
|
+
contract.blockCreated > blockNumber
|
59
|
+
)
|
60
|
+
throw new ChainDoesNotSupportContract({
|
61
|
+
blockNumber,
|
62
|
+
chain: client.chain,
|
63
|
+
contract: {
|
64
|
+
name: 'ensUniversalResolver',
|
65
|
+
blockCreated: contract.blockCreated,
|
66
|
+
},
|
67
|
+
})
|
68
|
+
|
69
|
+
universalResolverAddress = contract.address
|
70
|
+
}
|
71
|
+
|
72
|
+
const res = await readContract(client, {
|
73
|
+
address: universalResolverAddress,
|
74
|
+
abi: [
|
75
|
+
{
|
76
|
+
name: 'resolve',
|
77
|
+
type: 'function',
|
78
|
+
stateMutability: 'view',
|
79
|
+
inputs: [
|
80
|
+
{ name: 'name', type: 'bytes' },
|
81
|
+
{ name: 'data', type: 'bytes' },
|
82
|
+
],
|
83
|
+
outputs: [
|
84
|
+
{ name: '', type: 'bytes' },
|
85
|
+
{ name: 'address', type: 'address' },
|
86
|
+
],
|
87
|
+
},
|
88
|
+
],
|
89
|
+
functionName: 'resolve',
|
90
|
+
args: [
|
91
|
+
encodeHex(packetToBytes(name)),
|
92
|
+
encodeFunctionData({
|
93
|
+
abi: [
|
94
|
+
{
|
95
|
+
name: 'addr',
|
96
|
+
type: 'function',
|
97
|
+
stateMutability: 'view',
|
98
|
+
inputs: [{ name: 'name', type: 'bytes32' }],
|
99
|
+
outputs: [],
|
100
|
+
},
|
101
|
+
],
|
102
|
+
functionName: 'addr',
|
103
|
+
args: [namehash(name)],
|
104
|
+
}),
|
105
|
+
],
|
106
|
+
blockNumber,
|
107
|
+
blockTag,
|
108
|
+
})
|
109
|
+
return decodeFunctionResult({
|
110
|
+
abi: [
|
111
|
+
{
|
112
|
+
name: 'addr',
|
113
|
+
type: 'function',
|
114
|
+
stateMutability: 'view',
|
115
|
+
inputs: [],
|
116
|
+
outputs: [{ name: 'name', type: 'address' }],
|
117
|
+
},
|
118
|
+
],
|
119
|
+
functionName: 'addr',
|
120
|
+
data: res[0],
|
121
|
+
})
|
122
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { bench, describe } from 'vitest'
|
2
|
+
|
3
|
+
import {
|
4
|
+
ethersProvider,
|
5
|
+
ethersV6Provider,
|
6
|
+
publicClient,
|
7
|
+
web3Provider,
|
8
|
+
} from '../../_test'
|
9
|
+
|
10
|
+
import { getEnsName } from './getEnsName'
|
11
|
+
|
12
|
+
describe('Get ENS Name', () => {
|
13
|
+
bench('viem: `getEnsName`', async () => {
|
14
|
+
await getEnsName(publicClient, {
|
15
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
16
|
+
})
|
17
|
+
})
|
18
|
+
|
19
|
+
bench('ethers: `lookupAddress`', async () => {
|
20
|
+
await ethersProvider.lookupAddress(
|
21
|
+
'0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
22
|
+
)
|
23
|
+
})
|
24
|
+
|
25
|
+
bench('ethers@6: `lookupAddress`', async () => {
|
26
|
+
await ethersV6Provider.lookupAddress(
|
27
|
+
'0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
28
|
+
)
|
29
|
+
})
|
30
|
+
})
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
import { localhost, mainnet, optimism } from '../../chains'
|
3
|
+
import { createPublicClient, http } from '../../clients'
|
4
|
+
|
5
|
+
import { address, localHttpUrl, publicClient } from '../../_test'
|
6
|
+
|
7
|
+
import { getEnsName } from './getEnsName'
|
8
|
+
|
9
|
+
test('gets primary name for address', async () => {
|
10
|
+
await expect(
|
11
|
+
getEnsName(publicClient, {
|
12
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
13
|
+
}),
|
14
|
+
).resolves.toMatchInlineSnapshot('"awkweb.eth"')
|
15
|
+
})
|
16
|
+
|
17
|
+
test('address with no primary name', async () => {
|
18
|
+
await expect(
|
19
|
+
getEnsName(publicClient, {
|
20
|
+
address: address.burn,
|
21
|
+
}),
|
22
|
+
).resolves.toMatchInlineSnapshot('null')
|
23
|
+
})
|
24
|
+
|
25
|
+
test('custom universal resolver address', async () => {
|
26
|
+
await expect(
|
27
|
+
getEnsName(publicClient, {
|
28
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
29
|
+
universalResolverAddress: '0x74E20Bd2A1fE0cdbe45b9A1d89cb7e0a45b36376',
|
30
|
+
}),
|
31
|
+
).resolves.toMatchInlineSnapshot('"awkweb.eth"')
|
32
|
+
})
|
33
|
+
|
34
|
+
test('chain not provided', async () => {
|
35
|
+
await expect(
|
36
|
+
getEnsName(
|
37
|
+
createPublicClient({
|
38
|
+
transport: http(localHttpUrl),
|
39
|
+
}),
|
40
|
+
{ address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' },
|
41
|
+
),
|
42
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
43
|
+
'"client chain not configured. universalResolverAddress is required."',
|
44
|
+
)
|
45
|
+
})
|
46
|
+
|
47
|
+
test('universal resolver contract not configured for chain', async () => {
|
48
|
+
await expect(
|
49
|
+
getEnsName(
|
50
|
+
createPublicClient({
|
51
|
+
chain: optimism,
|
52
|
+
transport: http(),
|
53
|
+
}),
|
54
|
+
{
|
55
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
56
|
+
},
|
57
|
+
),
|
58
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
59
|
+
"Chain \\"Optimism\\" does not support contract \\"ensUniversalResolver\\".
|
60
|
+
|
61
|
+
This could be due to any of the following:
|
62
|
+
- The chain does not have the contract \\"ensUniversalResolver\\" configured.
|
63
|
+
|
64
|
+
Version: viem@1.0.2"
|
65
|
+
`)
|
66
|
+
})
|
67
|
+
|
68
|
+
test('universal resolver contract deployed on later block', async () => {
|
69
|
+
await expect(
|
70
|
+
getEnsName(publicClient, {
|
71
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
72
|
+
blockNumber: 14353601n,
|
73
|
+
}),
|
74
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
75
|
+
"Chain \\"Localhost\\" does not support contract \\"ensUniversalResolver\\".
|
76
|
+
|
77
|
+
This could be due to any of the following:
|
78
|
+
- The contract \\"ensUniversalResolver\\" was not deployed until block 16172161 (current block 14353601).
|
79
|
+
|
80
|
+
Version: viem@1.0.2"
|
81
|
+
`)
|
82
|
+
})
|
83
|
+
|
84
|
+
test('invalid universal resolver address', async () => {
|
85
|
+
await expect(
|
86
|
+
getEnsName(publicClient, {
|
87
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
88
|
+
universalResolverAddress: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
|
89
|
+
}),
|
90
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
91
|
+
"The contract function \\"reverse\\" reverted with the following reason:
|
92
|
+
execution reverted
|
93
|
+
|
94
|
+
Contract: 0x0000000000000000000000000000000000000000
|
95
|
+
Function: reverse(bytes reverseName)
|
96
|
+
Arguments: (0x28613063663739383831366434623962393836366235333330656561343661313833383266323531650461646472077265766572736500)
|
97
|
+
|
98
|
+
Docs: https://viem.sh/docs/contract/readContract
|
99
|
+
Version: viem@1.0.2"
|
100
|
+
`)
|
101
|
+
})
|