viem 0.0.1-alpha.13 → 0.0.1-alpha.15
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/chains.js +5 -5
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-4XV4JRFM.mjs → chunk-2HENAFQN.mjs} +16 -6
- package/dist/{chunk-O3XABJRL.js → chunk-EMQSYKNY.js} +11 -11
- package/dist/{chunk-OHOJCVQD.js → chunk-HTYEJEWI.js} +156 -529
- package/dist/chunk-IMYI7Z6M.js +255 -0
- package/dist/chunk-KGXH5DYI.js +152 -0
- package/dist/chunk-NYXBQHNJ.mjs +255 -0
- package/dist/chunk-PHAG5KUF.mjs +152 -0
- package/dist/{chunk-NJ5NFIT4.mjs → chunk-PPDHFNFM.mjs} +107 -480
- package/dist/{chunk-AGF7GU6G.js → chunk-QMLDI5JU.js} +16 -6
- package/dist/{chunk-KZVBHS2T.mjs → chunk-SX7GPOCZ.mjs} +1 -1
- package/dist/clients/index.d.ts +6 -3
- package/dist/clients/index.js +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/createClient-cd948138.d.ts +62 -0
- package/dist/createPublicClient-989a0556.d.ts +19 -0
- package/dist/createTestClient-81507f58.d.ts +34 -0
- package/dist/createWalletClient-43f801b9.d.ts +30 -0
- package/dist/{eip1193-c001fcd5.d.ts → eip1193-4330b722.d.ts} +1 -1
- package/dist/index.d.ts +13 -6
- package/dist/index.js +10 -4
- package/dist/index.mjs +35 -29
- package/dist/{parseGwei-21f98a29.d.ts → parseGwei-f2d23de6.d.ts} +1 -1
- package/dist/public.d.ts +12 -0
- package/dist/public.js +58 -0
- package/dist/public.mjs +58 -0
- package/dist/sendTransaction-7a9d241a.d.ts +13 -0
- package/dist/stopImpersonatingAccount-8113150e.d.ts +156 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +59 -0
- package/dist/test.mjs +59 -0
- package/dist/{transactionRequest-1d4e4385.d.ts → transactionReceipt-5d332aab.d.ts} +4 -32
- package/dist/transactionRequest-327eb7c2.d.ts +33 -0
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.mjs +1 -1
- package/dist/wallet.d.ts +9 -0
- package/dist/wallet.js +23 -0
- package/dist/wallet.mjs +23 -0
- package/dist/watchAsset-0088384c.d.ts +39 -0
- package/dist/{stopImpersonatingAccount-70c4a70c.d.ts → watchPendingTransactions-670a7ca3.d.ts} +19 -197
- package/dist/{webSocket-3385e295.d.ts → webSocket-9a3b0b26.d.ts} +1 -1
- package/dist/window.d.ts +1 -1
- package/package.json +16 -6
- package/actions/package.json +0 -4
- package/dist/actions/index.d.ts +0 -8
- package/dist/actions/index.js +0 -127
- package/dist/actions/index.mjs +0 -127
- package/dist/createWalletClient-3f9fa8b6.d.ts +0 -130
@@ -0,0 +1,152 @@
|
|
1
|
+
import {
|
2
|
+
BaseError,
|
3
|
+
InvalidGasArgumentsError,
|
4
|
+
checksumAddress,
|
5
|
+
encodeHex,
|
6
|
+
extract,
|
7
|
+
format,
|
8
|
+
formatTransactionRequest,
|
9
|
+
getAddress,
|
10
|
+
numberToHex
|
11
|
+
} from "./chunk-2HENAFQN.mjs";
|
12
|
+
|
13
|
+
// src/actions/wallet/addChain.ts
|
14
|
+
async function addChain(client, chain) {
|
15
|
+
const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
|
16
|
+
await client.request({
|
17
|
+
method: "wallet_addEthereumChain",
|
18
|
+
params: [
|
19
|
+
{
|
20
|
+
chainId: numberToHex(id),
|
21
|
+
chainName: name,
|
22
|
+
nativeCurrency,
|
23
|
+
rpcUrls: rpcUrls.default.http,
|
24
|
+
blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
|
25
|
+
}
|
26
|
+
]
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
30
|
+
// src/actions/wallet/getAccounts.ts
|
31
|
+
async function getAccounts(client) {
|
32
|
+
const addresses = await client.request({ method: "eth_accounts" });
|
33
|
+
return addresses.map((address) => checksumAddress(address));
|
34
|
+
}
|
35
|
+
|
36
|
+
// src/actions/wallet/getPermissions.ts
|
37
|
+
async function getPermissions(client) {
|
38
|
+
const permissions = await client.request({ method: "wallet_getPermissions" });
|
39
|
+
return permissions;
|
40
|
+
}
|
41
|
+
|
42
|
+
// src/actions/wallet/requestAccounts.ts
|
43
|
+
async function requestAccounts(client) {
|
44
|
+
const addresses = await client.request({ method: "eth_requestAccounts" });
|
45
|
+
return addresses.map((address) => getAddress(address));
|
46
|
+
}
|
47
|
+
|
48
|
+
// src/actions/wallet/requestPermissions.ts
|
49
|
+
async function requestPermissions(client, permissions) {
|
50
|
+
return client.request({
|
51
|
+
method: "wallet_requestPermissions",
|
52
|
+
params: [permissions]
|
53
|
+
});
|
54
|
+
}
|
55
|
+
|
56
|
+
// src/actions/wallet/sendTransaction.ts
|
57
|
+
async function sendTransaction(client, {
|
58
|
+
chain,
|
59
|
+
from,
|
60
|
+
accessList,
|
61
|
+
data,
|
62
|
+
gas,
|
63
|
+
gasPrice,
|
64
|
+
maxFeePerGas,
|
65
|
+
maxPriorityFeePerGas,
|
66
|
+
nonce,
|
67
|
+
to,
|
68
|
+
value,
|
69
|
+
...rest
|
70
|
+
}) {
|
71
|
+
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
72
|
+
throw new InvalidGasArgumentsError();
|
73
|
+
const formatter = chain?.formatters?.transactionRequest;
|
74
|
+
const request_ = format(
|
75
|
+
{
|
76
|
+
from,
|
77
|
+
accessList,
|
78
|
+
data,
|
79
|
+
gas,
|
80
|
+
gasPrice,
|
81
|
+
maxFeePerGas,
|
82
|
+
maxPriorityFeePerGas,
|
83
|
+
nonce,
|
84
|
+
to,
|
85
|
+
value,
|
86
|
+
...extract(rest, { formatter })
|
87
|
+
},
|
88
|
+
{
|
89
|
+
formatter: formatter || formatTransactionRequest
|
90
|
+
}
|
91
|
+
);
|
92
|
+
const hash = await client.request({
|
93
|
+
method: "eth_sendTransaction",
|
94
|
+
params: [request_]
|
95
|
+
});
|
96
|
+
return hash;
|
97
|
+
}
|
98
|
+
|
99
|
+
// src/actions/wallet/signMessage.ts
|
100
|
+
async function signMessage(client, { from, data: data_ }) {
|
101
|
+
let data;
|
102
|
+
if (typeof data_ === "string") {
|
103
|
+
if (!data_.startsWith("0x"))
|
104
|
+
throw new BaseError(
|
105
|
+
`data ("${data_}") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.`,
|
106
|
+
{
|
107
|
+
docsPath: "/TODO"
|
108
|
+
}
|
109
|
+
);
|
110
|
+
data = data_;
|
111
|
+
} else {
|
112
|
+
data = encodeHex(data_);
|
113
|
+
}
|
114
|
+
const signed = await client.request({
|
115
|
+
method: "personal_sign",
|
116
|
+
params: [data, from]
|
117
|
+
});
|
118
|
+
return signed;
|
119
|
+
}
|
120
|
+
|
121
|
+
// src/actions/wallet/switchChain.ts
|
122
|
+
async function switchChain(client, { id }) {
|
123
|
+
await client.request({
|
124
|
+
method: "wallet_switchEthereumChain",
|
125
|
+
params: [
|
126
|
+
{
|
127
|
+
chainId: numberToHex(id)
|
128
|
+
}
|
129
|
+
]
|
130
|
+
});
|
131
|
+
}
|
132
|
+
|
133
|
+
// src/actions/wallet/watchAsset.ts
|
134
|
+
async function watchAsset(client, params) {
|
135
|
+
const added = await client.request({
|
136
|
+
method: "wallet_watchAsset",
|
137
|
+
params: [params]
|
138
|
+
});
|
139
|
+
return added;
|
140
|
+
}
|
141
|
+
|
142
|
+
export {
|
143
|
+
addChain,
|
144
|
+
getAccounts,
|
145
|
+
getPermissions,
|
146
|
+
requestAccounts,
|
147
|
+
requestPermissions,
|
148
|
+
sendTransaction,
|
149
|
+
signMessage,
|
150
|
+
switchChain,
|
151
|
+
watchAsset
|
152
|
+
};
|