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
@@ -1,15 +1,15 @@
|
|
1
1
|
import {
|
2
|
-
|
2
|
+
sendTransaction
|
3
|
+
} from "./chunk-PHAG5KUF.mjs";
|
4
|
+
import {
|
3
5
|
BlockNotFoundError,
|
4
6
|
InvalidGasArgumentsError,
|
5
7
|
TransactionNotFoundError,
|
6
8
|
TransactionReceiptNotFoundError,
|
7
9
|
WaitForTransactionReceiptTimeoutError,
|
8
|
-
checksumAddress,
|
9
10
|
decodeFunctionResult,
|
10
11
|
encodeDeployData,
|
11
12
|
encodeFunctionData,
|
12
|
-
encodeHex,
|
13
13
|
extract,
|
14
14
|
format,
|
15
15
|
formatBlock,
|
@@ -18,14 +18,13 @@ import {
|
|
18
18
|
formatTransaction,
|
19
19
|
formatTransactionReceipt,
|
20
20
|
formatTransactionRequest,
|
21
|
-
getAddress,
|
22
21
|
getCache,
|
23
22
|
getContractError,
|
24
23
|
hexToNumber,
|
25
24
|
numberToHex,
|
26
25
|
wait,
|
27
26
|
withCache
|
28
|
-
} from "./chunk-
|
27
|
+
} from "./chunk-2HENAFQN.mjs";
|
29
28
|
|
30
29
|
// src/actions/public/call.ts
|
31
30
|
async function call(client, {
|
@@ -126,135 +125,6 @@ async function createBlockFilter(client) {
|
|
126
125
|
return { id, type: "block" };
|
127
126
|
}
|
128
127
|
|
129
|
-
// src/actions/wallet/addChain.ts
|
130
|
-
async function addChain(client, chain) {
|
131
|
-
const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
|
132
|
-
await client.request({
|
133
|
-
method: "wallet_addEthereumChain",
|
134
|
-
params: [
|
135
|
-
{
|
136
|
-
chainId: numberToHex(id),
|
137
|
-
chainName: name,
|
138
|
-
nativeCurrency,
|
139
|
-
rpcUrls: rpcUrls.default.http,
|
140
|
-
blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
|
141
|
-
}
|
142
|
-
]
|
143
|
-
});
|
144
|
-
}
|
145
|
-
|
146
|
-
// src/actions/wallet/getAccounts.ts
|
147
|
-
async function getAccounts(client) {
|
148
|
-
const addresses = await client.request({ method: "eth_accounts" });
|
149
|
-
return addresses.map((address) => checksumAddress(address));
|
150
|
-
}
|
151
|
-
|
152
|
-
// src/actions/wallet/getPermissions.ts
|
153
|
-
async function getPermissions(client) {
|
154
|
-
const permissions = await client.request({ method: "wallet_getPermissions" });
|
155
|
-
return permissions;
|
156
|
-
}
|
157
|
-
|
158
|
-
// src/actions/wallet/requestAccounts.ts
|
159
|
-
async function requestAccounts(client) {
|
160
|
-
const addresses = await client.request({ method: "eth_requestAccounts" });
|
161
|
-
return addresses.map((address) => getAddress(address));
|
162
|
-
}
|
163
|
-
|
164
|
-
// src/actions/wallet/requestPermissions.ts
|
165
|
-
async function requestPermissions(client, permissions) {
|
166
|
-
return client.request({
|
167
|
-
method: "wallet_requestPermissions",
|
168
|
-
params: [permissions]
|
169
|
-
});
|
170
|
-
}
|
171
|
-
|
172
|
-
// src/actions/wallet/sendTransaction.ts
|
173
|
-
async function sendTransaction(client, {
|
174
|
-
chain,
|
175
|
-
from,
|
176
|
-
accessList,
|
177
|
-
data,
|
178
|
-
gas,
|
179
|
-
gasPrice,
|
180
|
-
maxFeePerGas,
|
181
|
-
maxPriorityFeePerGas,
|
182
|
-
nonce,
|
183
|
-
to,
|
184
|
-
value,
|
185
|
-
...rest
|
186
|
-
}) {
|
187
|
-
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
188
|
-
throw new InvalidGasArgumentsError();
|
189
|
-
const formatter = chain?.formatters?.transactionRequest;
|
190
|
-
const request_ = format(
|
191
|
-
{
|
192
|
-
from,
|
193
|
-
accessList,
|
194
|
-
data,
|
195
|
-
gas,
|
196
|
-
gasPrice,
|
197
|
-
maxFeePerGas,
|
198
|
-
maxPriorityFeePerGas,
|
199
|
-
nonce,
|
200
|
-
to,
|
201
|
-
value,
|
202
|
-
...extract(rest, { formatter })
|
203
|
-
},
|
204
|
-
{
|
205
|
-
formatter: formatter || formatTransactionRequest
|
206
|
-
}
|
207
|
-
);
|
208
|
-
const hash = await client.request({
|
209
|
-
method: "eth_sendTransaction",
|
210
|
-
params: [request_]
|
211
|
-
});
|
212
|
-
return hash;
|
213
|
-
}
|
214
|
-
|
215
|
-
// src/actions/wallet/signMessage.ts
|
216
|
-
async function signMessage(client, { from, data: data_ }) {
|
217
|
-
let data;
|
218
|
-
if (typeof data_ === "string") {
|
219
|
-
if (!data_.startsWith("0x"))
|
220
|
-
throw new BaseError(
|
221
|
-
`data ("${data_}") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.`,
|
222
|
-
{
|
223
|
-
docsPath: "/TODO"
|
224
|
-
}
|
225
|
-
);
|
226
|
-
data = data_;
|
227
|
-
} else {
|
228
|
-
data = encodeHex(data_);
|
229
|
-
}
|
230
|
-
const signed = await client.request({
|
231
|
-
method: "personal_sign",
|
232
|
-
params: [data, from]
|
233
|
-
});
|
234
|
-
return signed;
|
235
|
-
}
|
236
|
-
|
237
|
-
// src/actions/wallet/switchChain.ts
|
238
|
-
async function switchChain(client, { id }) {
|
239
|
-
await client.request({
|
240
|
-
method: "wallet_switchEthereumChain",
|
241
|
-
params: [
|
242
|
-
{
|
243
|
-
chainId: numberToHex(id)
|
244
|
-
}
|
245
|
-
]
|
246
|
-
});
|
247
|
-
}
|
248
|
-
|
249
|
-
// src/actions/wallet/watchAsset.ts
|
250
|
-
async function watchAsset(client, params) {
|
251
|
-
const added = await client.request({
|
252
|
-
method: "wallet_watchAsset",
|
253
|
-
params: [params]
|
254
|
-
});
|
255
|
-
return added;
|
256
|
-
}
|
257
|
-
|
258
128
|
// src/actions/public/deployContract.ts
|
259
129
|
function deployContract(walletClient, { abi, args, bytecode, ...request }) {
|
260
130
|
const calldata = encodeDeployData({
|
@@ -373,6 +243,18 @@ async function getBlockTransactionCount(client, {
|
|
373
243
|
return hexToNumber(count);
|
374
244
|
}
|
375
245
|
|
246
|
+
// src/actions/public/getBytecode.ts
|
247
|
+
async function getBytecode(client, { address, blockNumber, blockTag = "latest" }) {
|
248
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
249
|
+
const hex = await client.request({
|
250
|
+
method: "eth_getCode",
|
251
|
+
params: [address, blockNumberHex || blockTag]
|
252
|
+
});
|
253
|
+
if (hex === "0x")
|
254
|
+
return void 0;
|
255
|
+
return hex;
|
256
|
+
}
|
257
|
+
|
376
258
|
// src/actions/public/getChainId.ts
|
377
259
|
async function getChainId(client) {
|
378
260
|
const chainIdHex = await client.request({ method: "eth_chainId" });
|
@@ -549,98 +431,6 @@ function observe(observerId, callbacks, fn) {
|
|
549
431
|
return unwatch;
|
550
432
|
}
|
551
433
|
|
552
|
-
// src/actions/public/waitForTransactionReceipt.ts
|
553
|
-
async function waitForTransactionReceipt(client, {
|
554
|
-
confirmations = 1,
|
555
|
-
hash,
|
556
|
-
onReplaced,
|
557
|
-
pollingInterval = client.pollingInterval,
|
558
|
-
timeout
|
559
|
-
}) {
|
560
|
-
const observerId = JSON.stringify([
|
561
|
-
"waitForTransactionReceipt",
|
562
|
-
client.uid,
|
563
|
-
hash
|
564
|
-
]);
|
565
|
-
let transaction;
|
566
|
-
let replacedTransaction;
|
567
|
-
let receipt;
|
568
|
-
return new Promise((resolve, reject) => {
|
569
|
-
if (timeout)
|
570
|
-
setTimeout(
|
571
|
-
() => reject(new WaitForTransactionReceiptTimeoutError({ hash })),
|
572
|
-
timeout
|
573
|
-
);
|
574
|
-
const unobserve = observe(
|
575
|
-
observerId,
|
576
|
-
{ onReplaced, resolve, reject },
|
577
|
-
(emit) => {
|
578
|
-
const unwatch = watchBlockNumber(client, {
|
579
|
-
emitMissed: true,
|
580
|
-
emitOnBegin: true,
|
581
|
-
pollingInterval,
|
582
|
-
async onBlockNumber(blockNumber) {
|
583
|
-
const done = async (fn) => {
|
584
|
-
unwatch();
|
585
|
-
fn();
|
586
|
-
unobserve();
|
587
|
-
};
|
588
|
-
try {
|
589
|
-
if (receipt) {
|
590
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
591
|
-
return;
|
592
|
-
done(() => emit.resolve(receipt));
|
593
|
-
return;
|
594
|
-
}
|
595
|
-
transaction = await getTransaction(client, { hash });
|
596
|
-
receipt = await getTransactionReceipt(client, { hash });
|
597
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
598
|
-
return;
|
599
|
-
done(() => emit.resolve(receipt));
|
600
|
-
} catch (err) {
|
601
|
-
if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
|
602
|
-
replacedTransaction = transaction;
|
603
|
-
const block = await getBlock(client, {
|
604
|
-
blockNumber,
|
605
|
-
includeTransactions: true
|
606
|
-
});
|
607
|
-
const replacementTransaction = block.transactions.find(
|
608
|
-
({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
|
609
|
-
);
|
610
|
-
if (!replacementTransaction)
|
611
|
-
return;
|
612
|
-
receipt = await getTransactionReceipt(client, {
|
613
|
-
hash: replacementTransaction.hash
|
614
|
-
});
|
615
|
-
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
616
|
-
return;
|
617
|
-
let reason = "replaced";
|
618
|
-
if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
|
619
|
-
reason = "repriced";
|
620
|
-
} else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
|
621
|
-
reason = "cancelled";
|
622
|
-
}
|
623
|
-
done(() => {
|
624
|
-
emit.onReplaced?.({
|
625
|
-
reason,
|
626
|
-
replacedTransaction,
|
627
|
-
transaction: replacementTransaction,
|
628
|
-
transactionReceipt: receipt
|
629
|
-
});
|
630
|
-
emit.resolve(receipt);
|
631
|
-
});
|
632
|
-
} else {
|
633
|
-
done(() => emit.reject(err));
|
634
|
-
}
|
635
|
-
}
|
636
|
-
}
|
637
|
-
});
|
638
|
-
return unwatch;
|
639
|
-
}
|
640
|
-
);
|
641
|
-
});
|
642
|
-
}
|
643
|
-
|
644
434
|
// src/utils/poll.ts
|
645
435
|
function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
|
646
436
|
let active = true;
|
@@ -817,223 +607,95 @@ function watchPendingTransactions(client, {
|
|
817
607
|
});
|
818
608
|
}
|
819
609
|
|
820
|
-
// src/actions/
|
821
|
-
async function
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
}
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
}
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
}
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
}
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
const request_ = formatTransactionRequest(request);
|
910
|
-
const hash = await client.request({
|
911
|
-
method: "eth_sendUnsignedTransaction",
|
912
|
-
params: [request_]
|
913
|
-
});
|
914
|
-
return hash;
|
915
|
-
}
|
916
|
-
|
917
|
-
// src/actions/test/setAutomine.ts
|
918
|
-
async function setAutomine(client, enabled) {
|
919
|
-
return await client.request({
|
920
|
-
method: "evm_setAutomine",
|
921
|
-
params: [enabled]
|
922
|
-
});
|
923
|
-
}
|
924
|
-
|
925
|
-
// src/actions/test/setBalance.ts
|
926
|
-
async function setBalance(client, { address, value }) {
|
927
|
-
return await client.request({
|
928
|
-
method: `${client.mode}_setBalance`,
|
929
|
-
params: [address, numberToHex(value)]
|
930
|
-
});
|
931
|
-
}
|
932
|
-
|
933
|
-
// src/actions/test/setBlockGasLimit.ts
|
934
|
-
async function setBlockGasLimit(client, { gasLimit }) {
|
935
|
-
return await client.request({
|
936
|
-
method: "evm_setBlockGasLimit",
|
937
|
-
params: [numberToHex(gasLimit)]
|
938
|
-
});
|
939
|
-
}
|
940
|
-
|
941
|
-
// src/actions/test/setBlockTimestampInterval.ts
|
942
|
-
async function setBlockTimestampInterval(client, { interval }) {
|
943
|
-
return await client.request({
|
944
|
-
method: `${client.mode}_setBlockTimestampInterval`,
|
945
|
-
params: [interval]
|
946
|
-
});
|
947
|
-
}
|
948
|
-
|
949
|
-
// src/actions/test/setCode.ts
|
950
|
-
async function setCode(client, { address, bytecode }) {
|
951
|
-
return await client.request({
|
952
|
-
method: `${client.mode}_setCode`,
|
953
|
-
params: [address, bytecode]
|
954
|
-
});
|
955
|
-
}
|
956
|
-
|
957
|
-
// src/actions/test/setCoinbase.ts
|
958
|
-
async function setCoinbase(client, { address }) {
|
959
|
-
return await client.request({
|
960
|
-
method: `${client.mode}_setCoinbase`,
|
961
|
-
params: [address]
|
962
|
-
});
|
963
|
-
}
|
964
|
-
|
965
|
-
// src/actions/test/setIntervalMining.ts
|
966
|
-
async function setIntervalMining(client, { interval }) {
|
967
|
-
return await client.request({
|
968
|
-
method: "evm_setIntervalMining",
|
969
|
-
params: [interval]
|
970
|
-
});
|
971
|
-
}
|
972
|
-
|
973
|
-
// src/actions/test/setLoggingEnabled.ts
|
974
|
-
async function setLoggingEnabled(client, enabled) {
|
975
|
-
return await client.request({
|
976
|
-
method: `${client.mode}_setLoggingEnabled`,
|
977
|
-
params: [enabled]
|
978
|
-
});
|
979
|
-
}
|
980
|
-
|
981
|
-
// src/actions/test/setMinGasPrice.ts
|
982
|
-
async function setMinGasPrice(client, { gasPrice }) {
|
983
|
-
return await client.request({
|
984
|
-
method: `${client.mode}_setMinGasPrice`,
|
985
|
-
params: [numberToHex(gasPrice)]
|
986
|
-
});
|
987
|
-
}
|
988
|
-
|
989
|
-
// src/actions/test/setNextBlockBaseFeePerGas.ts
|
990
|
-
async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
|
991
|
-
return await client.request({
|
992
|
-
method: `${client.mode}_setNextBlockBaseFeePerGas`,
|
993
|
-
params: [numberToHex(baseFeePerGas)]
|
994
|
-
});
|
995
|
-
}
|
996
|
-
|
997
|
-
// src/actions/test/setNextBlockTimestamp.ts
|
998
|
-
async function setNextBlockTimestamp(client, { timestamp }) {
|
999
|
-
return await client.request({
|
1000
|
-
method: "evm_setNextBlockTimestamp",
|
1001
|
-
params: [numberToHex(timestamp)]
|
1002
|
-
});
|
1003
|
-
}
|
1004
|
-
|
1005
|
-
// src/actions/test/setNonce.ts
|
1006
|
-
async function setNonce(client, { address, nonce }) {
|
1007
|
-
return await client.request({
|
1008
|
-
method: `${client.mode}_setNonce`,
|
1009
|
-
params: [address, numberToHex(nonce)]
|
1010
|
-
});
|
1011
|
-
}
|
1012
|
-
|
1013
|
-
// src/actions/test/setStorageAt.ts
|
1014
|
-
async function setStorageAt(client, { address, index, value }) {
|
1015
|
-
return await client.request({
|
1016
|
-
method: `${client.mode}_setStorageAt`,
|
1017
|
-
params: [
|
1018
|
-
address,
|
1019
|
-
typeof index === "number" ? numberToHex(index) : index,
|
1020
|
-
value
|
1021
|
-
]
|
1022
|
-
});
|
1023
|
-
}
|
1024
|
-
|
1025
|
-
// src/actions/test/snapshot.ts
|
1026
|
-
async function snapshot(client) {
|
1027
|
-
return await client.request({
|
1028
|
-
method: "evm_snapshot"
|
1029
|
-
});
|
1030
|
-
}
|
1031
|
-
|
1032
|
-
// src/actions/test/stopImpersonatingAccount.ts
|
1033
|
-
async function stopImpersonatingAccount(client, { address }) {
|
1034
|
-
return await client.request({
|
1035
|
-
method: `${client.mode}_stopImpersonatingAccount`,
|
1036
|
-
params: [address]
|
610
|
+
// src/actions/public/waitForTransactionReceipt.ts
|
611
|
+
async function waitForTransactionReceipt(client, {
|
612
|
+
confirmations = 1,
|
613
|
+
hash,
|
614
|
+
onReplaced,
|
615
|
+
pollingInterval = client.pollingInterval,
|
616
|
+
timeout
|
617
|
+
}) {
|
618
|
+
const observerId = JSON.stringify([
|
619
|
+
"waitForTransactionReceipt",
|
620
|
+
client.uid,
|
621
|
+
hash
|
622
|
+
]);
|
623
|
+
let transaction;
|
624
|
+
let replacedTransaction;
|
625
|
+
let receipt;
|
626
|
+
return new Promise((resolve, reject) => {
|
627
|
+
if (timeout)
|
628
|
+
setTimeout(
|
629
|
+
() => reject(new WaitForTransactionReceiptTimeoutError({ hash })),
|
630
|
+
timeout
|
631
|
+
);
|
632
|
+
const unobserve = observe(
|
633
|
+
observerId,
|
634
|
+
{ onReplaced, resolve, reject },
|
635
|
+
(emit) => {
|
636
|
+
const unwatch = watchBlockNumber(client, {
|
637
|
+
emitMissed: true,
|
638
|
+
emitOnBegin: true,
|
639
|
+
pollingInterval,
|
640
|
+
async onBlockNumber(blockNumber) {
|
641
|
+
const done = async (fn) => {
|
642
|
+
unwatch();
|
643
|
+
fn();
|
644
|
+
unobserve();
|
645
|
+
};
|
646
|
+
try {
|
647
|
+
if (receipt) {
|
648
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
649
|
+
return;
|
650
|
+
done(() => emit.resolve(receipt));
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
transaction = await getTransaction(client, { hash });
|
654
|
+
receipt = await getTransactionReceipt(client, { hash });
|
655
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
656
|
+
return;
|
657
|
+
done(() => emit.resolve(receipt));
|
658
|
+
} catch (err) {
|
659
|
+
if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
|
660
|
+
replacedTransaction = transaction;
|
661
|
+
const block = await getBlock(client, {
|
662
|
+
blockNumber,
|
663
|
+
includeTransactions: true
|
664
|
+
});
|
665
|
+
const replacementTransaction = block.transactions.find(
|
666
|
+
({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
|
667
|
+
);
|
668
|
+
if (!replacementTransaction)
|
669
|
+
return;
|
670
|
+
receipt = await getTransactionReceipt(client, {
|
671
|
+
hash: replacementTransaction.hash
|
672
|
+
});
|
673
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
674
|
+
return;
|
675
|
+
let reason = "replaced";
|
676
|
+
if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
|
677
|
+
reason = "repriced";
|
678
|
+
} else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
|
679
|
+
reason = "cancelled";
|
680
|
+
}
|
681
|
+
done(() => {
|
682
|
+
emit.onReplaced?.({
|
683
|
+
reason,
|
684
|
+
replacedTransaction,
|
685
|
+
transaction: replacementTransaction,
|
686
|
+
transactionReceipt: receipt
|
687
|
+
});
|
688
|
+
emit.resolve(receipt);
|
689
|
+
});
|
690
|
+
} else {
|
691
|
+
done(() => emit.reject(err));
|
692
|
+
}
|
693
|
+
}
|
694
|
+
}
|
695
|
+
});
|
696
|
+
return unwatch;
|
697
|
+
}
|
698
|
+
);
|
1037
699
|
});
|
1038
700
|
}
|
1039
701
|
|
@@ -1042,15 +704,6 @@ export {
|
|
1042
704
|
callContract,
|
1043
705
|
createPendingTransactionFilter,
|
1044
706
|
createBlockFilter,
|
1045
|
-
addChain,
|
1046
|
-
getAccounts,
|
1047
|
-
getPermissions,
|
1048
|
-
requestAccounts,
|
1049
|
-
requestPermissions,
|
1050
|
-
sendTransaction,
|
1051
|
-
signMessage,
|
1052
|
-
switchChain,
|
1053
|
-
watchAsset,
|
1054
707
|
deployContract,
|
1055
708
|
estimateGas,
|
1056
709
|
getBalance,
|
@@ -1058,6 +711,7 @@ export {
|
|
1058
711
|
getBlockNumberCache,
|
1059
712
|
getBlockNumber,
|
1060
713
|
getBlockTransactionCount,
|
714
|
+
getBytecode,
|
1061
715
|
getChainId,
|
1062
716
|
getFeeHistory,
|
1063
717
|
getFilterChanges,
|
@@ -1071,32 +725,5 @@ export {
|
|
1071
725
|
waitForTransactionReceipt,
|
1072
726
|
watchBlockNumber,
|
1073
727
|
watchBlocks,
|
1074
|
-
watchPendingTransactions
|
1075
|
-
dropTransaction,
|
1076
|
-
getAutomine,
|
1077
|
-
getTxpoolContent,
|
1078
|
-
getTxpoolStatus,
|
1079
|
-
impersonateAccount,
|
1080
|
-
increaseTime,
|
1081
|
-
inspectTxpool,
|
1082
|
-
mine,
|
1083
|
-
removeBlockTimestampInterval,
|
1084
|
-
reset,
|
1085
|
-
revert,
|
1086
|
-
sendUnsignedTransaction,
|
1087
|
-
setAutomine,
|
1088
|
-
setBalance,
|
1089
|
-
setBlockGasLimit,
|
1090
|
-
setBlockTimestampInterval,
|
1091
|
-
setCode,
|
1092
|
-
setCoinbase,
|
1093
|
-
setIntervalMining,
|
1094
|
-
setLoggingEnabled,
|
1095
|
-
setMinGasPrice,
|
1096
|
-
setNextBlockBaseFeePerGas,
|
1097
|
-
setNextBlockTimestamp,
|
1098
|
-
setNonce,
|
1099
|
-
setStorageAt,
|
1100
|
-
snapshot,
|
1101
|
-
stopImpersonatingAccount
|
728
|
+
watchPendingTransactions
|
1102
729
|
};
|
@@ -9,7 +9,7 @@ var __publicField = (obj, key, value) => {
|
|
9
9
|
var package_default = {
|
10
10
|
name: "viem",
|
11
11
|
description: "TypeScript Interface for Ethereum",
|
12
|
-
version: "0.0.1-alpha.
|
12
|
+
version: "0.0.1-alpha.15",
|
13
13
|
scripts: {
|
14
14
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
15
15
|
bench: "vitest bench --no-threads",
|
@@ -50,11 +50,6 @@ var package_default = {
|
|
50
50
|
module: "./dist/index.mjs",
|
51
51
|
default: "./dist/index.js"
|
52
52
|
},
|
53
|
-
"./actions": {
|
54
|
-
types: "./dist/actions/index.d.ts",
|
55
|
-
module: "./dist/actions/index.mjs",
|
56
|
-
default: "./dist/actions/index.js"
|
57
|
-
},
|
58
53
|
"./chains": {
|
59
54
|
types: "./dist/chains.d.ts",
|
60
55
|
module: "./dist/chains.mjs",
|
@@ -65,11 +60,26 @@ var package_default = {
|
|
65
60
|
module: "./dist/clients/index.mjs",
|
66
61
|
default: "./dist/clients/index.js"
|
67
62
|
},
|
63
|
+
"./public": {
|
64
|
+
types: "./dist/public.d.ts",
|
65
|
+
module: "./dist/public.mjs",
|
66
|
+
default: "./dist/public.js"
|
67
|
+
},
|
68
|
+
"./test": {
|
69
|
+
types: "./dist/test.d.ts",
|
70
|
+
module: "./dist/test.mjs",
|
71
|
+
default: "./dist/test.js"
|
72
|
+
},
|
68
73
|
"./utils": {
|
69
74
|
types: "./dist/utils/index.d.ts",
|
70
75
|
module: "./dist/utils/index.mjs",
|
71
76
|
default: "./dist/utils/index.js"
|
72
77
|
},
|
78
|
+
"./wallet": {
|
79
|
+
types: "./dist/wallet.d.ts",
|
80
|
+
module: "./dist/wallet.mjs",
|
81
|
+
default: "./dist/wallet.js"
|
82
|
+
},
|
73
83
|
"./window": {
|
74
84
|
types: "./dist/window.d.ts",
|
75
85
|
module: "./dist/window.mjs",
|