viem 0.2.0-canary.20230316T020523 → 0.2.0-jxom-async-verify-message.20230321T000803
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/abi.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/account-07d04222.d.ts +74 -0
- package/dist/{chain-1b53ef88.d.ts → chain-b2e88e30.d.ts} +113 -108
- package/dist/{chain-ec8c485d.d.ts → chain-c4f924cf.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-ZTHR4YS2.js → chunk-22BDIC7J.js} +406 -108
- package/dist/chunk-22BDIC7J.js.map +1 -0
- package/dist/{chunk-FDTKU2PS.js → chunk-2NJCP2DN.js} +19 -19
- package/dist/{chunk-FDTKU2PS.js.map → chunk-2NJCP2DN.js.map} +1 -1
- package/dist/{chunk-MWJLP6MO.mjs → chunk-FEPL5HFW.mjs} +336 -38
- package/dist/chunk-FEPL5HFW.mjs.map +1 -0
- package/dist/{chunk-7OP5XRWB.mjs → chunk-OZCG5IO7.mjs} +2 -2
- package/dist/chunk-OZCG5IO7.mjs.map +1 -0
- package/dist/contract.d.ts +8 -7
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-a28317a9.d.ts → createClient-d4f1dea1.d.ts} +6 -6
- package/dist/{createPublicClient-0021fc35.d.ts → createPublicClient-3a714a8d.d.ts} +154 -207
- package/dist/{eip1193-4f4e240c.d.ts → eip1193-cd3e872a.d.ts} +1 -1
- package/dist/{encodeFunctionResult-1f324375.d.ts → encodeFunctionResult-750c9055.d.ts} +1 -1
- package/dist/{encodePacked-d5d5264a.d.ts → encodePacked-de74201f.d.ts} +1 -1
- package/dist/ens.d.ts +5 -4
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +3 -5
- package/dist/ethers.js +3 -3
- package/dist/ethers.mjs +1 -1
- package/dist/{formatAbiItem-15e8817d.d.ts → formatAbiItem-fdbdda39.d.ts} +1 -1
- package/dist/{getAbiItem-3e809ff9.d.ts → getAbiItem-9d709e3b.d.ts} +1 -1
- package/dist/index.d.ts +14 -13
- package/dist/index.js +101 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-c2fb9fa2.d.ts → parseGwei-b138c041.d.ts} +49 -12
- package/dist/public.d.ts +5 -4
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/{test-2bd23d7e.d.ts → test-c70126a6.d.ts} +33 -32
- package/dist/test.d.ts +10 -10
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/utils/index.d.ts +28 -18
- package/dist/utils/index.js +10 -2
- package/dist/utils/index.mjs +11 -3
- package/dist/wallet.d.ts +5 -4
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/window.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-7OP5XRWB.mjs.map +0 -1
- package/dist/chunk-MWJLP6MO.mjs.map +0 -1
- package/dist/chunk-ZTHR4YS2.js.map +0 -1
@@ -20,7 +20,7 @@ import "abitype";
|
|
20
20
|
var package_default = {
|
21
21
|
name: "viem",
|
22
22
|
description: "TypeScript Interface for Ethereum",
|
23
|
-
version: "0.1.
|
23
|
+
version: "0.1.21",
|
24
24
|
scripts: {
|
25
25
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
26
26
|
bench: "vitest bench --no-threads",
|
@@ -218,7 +218,9 @@ var BaseError = class extends Error {
|
|
218
218
|
shortMessage || "An error occurred.",
|
219
219
|
"",
|
220
220
|
...args.metaMessages ? [...args.metaMessages, ""] : [],
|
221
|
-
...docsPath6 ? [
|
221
|
+
...docsPath6 ? [
|
222
|
+
`Docs: https://viem.sh${docsPath6}.html${args.docsSlug ? `#${args.docsSlug}` : ""}`
|
223
|
+
] : [],
|
222
224
|
...details ? [`Details: ${details}`] : [],
|
223
225
|
`Version: ${getVersion()}`
|
224
226
|
].join("\n");
|
@@ -519,6 +521,23 @@ var UnsupportedPackedAbiType = class extends BaseError {
|
|
519
521
|
}
|
520
522
|
};
|
521
523
|
|
524
|
+
// src/errors/account.ts
|
525
|
+
var AccountNotFoundError = class extends BaseError {
|
526
|
+
constructor({ docsPath: docsPath6 } = {}) {
|
527
|
+
super(
|
528
|
+
[
|
529
|
+
"Could not find an Account to execute with this Action.",
|
530
|
+
"Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the WalletClient."
|
531
|
+
].join("\n"),
|
532
|
+
{
|
533
|
+
docsPath: docsPath6,
|
534
|
+
docsSlug: "account"
|
535
|
+
}
|
536
|
+
);
|
537
|
+
__publicField(this, "name", "AccountNotFoundError");
|
538
|
+
}
|
539
|
+
};
|
540
|
+
|
522
541
|
// src/errors/address.ts
|
523
542
|
var InvalidAddressError = class extends BaseError {
|
524
543
|
constructor({ address }) {
|
@@ -572,7 +591,7 @@ var ChainMismatchError = class extends BaseError {
|
|
572
591
|
currentChainId
|
573
592
|
}) {
|
574
593
|
super(
|
575
|
-
`The current chain (id: ${currentChainId}) does not match the chain
|
594
|
+
`The current chain of the wallet (id: ${currentChainId}) does not match the target chain for the transaction (id: ${chain.id} \u2013 ${chain.name}).`,
|
576
595
|
{
|
577
596
|
metaMessages: [
|
578
597
|
`Current Chain ID: ${currentChainId}`,
|
@@ -583,6 +602,17 @@ var ChainMismatchError = class extends BaseError {
|
|
583
602
|
__publicField(this, "name", "ChainMismatchError");
|
584
603
|
}
|
585
604
|
};
|
605
|
+
var ChainNotFoundError = class extends BaseError {
|
606
|
+
constructor() {
|
607
|
+
super(
|
608
|
+
[
|
609
|
+
"No chain was provided to the request.",
|
610
|
+
"Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."
|
611
|
+
].join("\n")
|
612
|
+
);
|
613
|
+
__publicField(this, "name", "ChainNotFoundError");
|
614
|
+
}
|
615
|
+
};
|
586
616
|
|
587
617
|
// src/constants/abis.ts
|
588
618
|
var multicall3Abi = [
|
@@ -713,7 +743,7 @@ var TransactionExecutionError = class extends BaseError {
|
|
713
743
|
}) {
|
714
744
|
const prettyArgs = prettyPrint({
|
715
745
|
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
716
|
-
from: account
|
746
|
+
from: account?.address,
|
717
747
|
to,
|
718
748
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
719
749
|
data,
|
@@ -778,7 +808,7 @@ var WaitForTransactionReceiptTimeoutError = class extends BaseError {
|
|
778
808
|
// src/errors/contract.ts
|
779
809
|
var CallExecutionError = class extends BaseError {
|
780
810
|
constructor(cause, {
|
781
|
-
account,
|
811
|
+
account: account_,
|
782
812
|
docsPath: docsPath6,
|
783
813
|
chain,
|
784
814
|
data,
|
@@ -790,6 +820,7 @@ var CallExecutionError = class extends BaseError {
|
|
790
820
|
to,
|
791
821
|
value
|
792
822
|
}) {
|
823
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
793
824
|
const prettyArgs = prettyPrint({
|
794
825
|
from: account?.address,
|
795
826
|
to,
|
@@ -1032,7 +1063,7 @@ var EstimateGasExecutionError = class extends BaseError {
|
|
1032
1063
|
value
|
1033
1064
|
}) {
|
1034
1065
|
const prettyArgs = prettyPrint({
|
1035
|
-
from: account
|
1066
|
+
from: account?.address,
|
1036
1067
|
to,
|
1037
1068
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
1038
1069
|
data,
|
@@ -2829,19 +2860,30 @@ function formatAbiItemWithArgs({
|
|
2829
2860
|
}
|
2830
2861
|
|
2831
2862
|
// src/utils/account.ts
|
2832
|
-
function getAccount(
|
2833
|
-
if (typeof
|
2834
|
-
if (!isAddress(
|
2835
|
-
throw new InvalidAddressError({ address:
|
2836
|
-
return {
|
2863
|
+
function getAccount(source) {
|
2864
|
+
if (typeof source === "string") {
|
2865
|
+
if (!isAddress(source))
|
2866
|
+
throw new InvalidAddressError({ address: source });
|
2867
|
+
return {
|
2868
|
+
address: source,
|
2869
|
+
type: "json-rpc"
|
2870
|
+
};
|
2837
2871
|
}
|
2838
|
-
if (!isAddress(
|
2839
|
-
throw new InvalidAddressError({ address:
|
2872
|
+
if (!isAddress(source.address))
|
2873
|
+
throw new InvalidAddressError({ address: source.address });
|
2840
2874
|
return {
|
2841
|
-
|
2875
|
+
address: source.address,
|
2876
|
+
signMessage: source.signMessage,
|
2877
|
+
signTransaction: source.signTransaction,
|
2878
|
+
signTypedData: source.signTypedData,
|
2842
2879
|
type: "local"
|
2843
2880
|
};
|
2844
2881
|
}
|
2882
|
+
function parseAccount(account) {
|
2883
|
+
if (typeof account === "string")
|
2884
|
+
return { address: account, type: "json-rpc" };
|
2885
|
+
return account;
|
2886
|
+
}
|
2845
2887
|
|
2846
2888
|
// src/utils/promise/withCache.ts
|
2847
2889
|
var promiseCache = /* @__PURE__ */ new Map();
|
@@ -3507,15 +3549,172 @@ ${messageBytes.length}`
|
|
3507
3549
|
return keccak256(concat([prefixBytes, messageBytes]), to_);
|
3508
3550
|
}
|
3509
3551
|
|
3552
|
+
// src/utils/signature/hashTypedData.ts
|
3553
|
+
function hashTypedData({
|
3554
|
+
domain,
|
3555
|
+
message,
|
3556
|
+
primaryType,
|
3557
|
+
types: types_
|
3558
|
+
}) {
|
3559
|
+
const types = {
|
3560
|
+
EIP712Domain: [
|
3561
|
+
domain?.name && { name: "name", type: "string" },
|
3562
|
+
domain?.version && { name: "version", type: "string" },
|
3563
|
+
domain?.chainId && { name: "chainId", type: "uint256" },
|
3564
|
+
domain?.verifyingContract && {
|
3565
|
+
name: "verifyingContract",
|
3566
|
+
type: "address"
|
3567
|
+
},
|
3568
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
3569
|
+
].filter(Boolean),
|
3570
|
+
...types_
|
3571
|
+
};
|
3572
|
+
let parts = ["0x1901"];
|
3573
|
+
if (domain)
|
3574
|
+
parts.push(
|
3575
|
+
hashDomain({
|
3576
|
+
domain,
|
3577
|
+
types
|
3578
|
+
})
|
3579
|
+
);
|
3580
|
+
if (primaryType !== "EIP712Domain") {
|
3581
|
+
parts.push(
|
3582
|
+
hashStruct({
|
3583
|
+
data: message,
|
3584
|
+
primaryType,
|
3585
|
+
types
|
3586
|
+
})
|
3587
|
+
);
|
3588
|
+
}
|
3589
|
+
return keccak256(concat(parts));
|
3590
|
+
}
|
3591
|
+
function hashDomain({
|
3592
|
+
domain,
|
3593
|
+
types
|
3594
|
+
}) {
|
3595
|
+
return hashStruct({
|
3596
|
+
data: domain,
|
3597
|
+
primaryType: "EIP712Domain",
|
3598
|
+
types
|
3599
|
+
});
|
3600
|
+
}
|
3601
|
+
function hashStruct({
|
3602
|
+
data,
|
3603
|
+
primaryType,
|
3604
|
+
types
|
3605
|
+
}) {
|
3606
|
+
const encoded = encodeData({
|
3607
|
+
data,
|
3608
|
+
primaryType,
|
3609
|
+
types
|
3610
|
+
});
|
3611
|
+
return keccak256(encoded);
|
3612
|
+
}
|
3613
|
+
function encodeData({
|
3614
|
+
data,
|
3615
|
+
primaryType,
|
3616
|
+
types
|
3617
|
+
}) {
|
3618
|
+
let encodedTypes = [{ type: "bytes32" }];
|
3619
|
+
const encodedValues = [hashType({ primaryType, types })];
|
3620
|
+
for (const field of types[primaryType]) {
|
3621
|
+
const [type, value] = encodeField({
|
3622
|
+
types,
|
3623
|
+
name: field.name,
|
3624
|
+
type: field.type,
|
3625
|
+
value: data[field.name]
|
3626
|
+
});
|
3627
|
+
encodedTypes.push(type);
|
3628
|
+
encodedValues.push(value);
|
3629
|
+
}
|
3630
|
+
return encodeAbiParameters(encodedTypes, encodedValues);
|
3631
|
+
}
|
3632
|
+
function hashType({
|
3633
|
+
primaryType,
|
3634
|
+
types
|
3635
|
+
}) {
|
3636
|
+
const encodedHashType = toHex(encodeType({ primaryType, types }));
|
3637
|
+
return keccak256(encodedHashType);
|
3638
|
+
}
|
3639
|
+
function encodeType({
|
3640
|
+
primaryType,
|
3641
|
+
types
|
3642
|
+
}) {
|
3643
|
+
let result = "";
|
3644
|
+
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
3645
|
+
unsortedDeps.delete(primaryType);
|
3646
|
+
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
3647
|
+
for (const type of deps) {
|
3648
|
+
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
3649
|
+
}
|
3650
|
+
return result;
|
3651
|
+
}
|
3652
|
+
function findTypeDependencies({
|
3653
|
+
primaryType: primaryType_,
|
3654
|
+
types
|
3655
|
+
}, results = /* @__PURE__ */ new Set()) {
|
3656
|
+
const match = primaryType_.match(/^\w*/u);
|
3657
|
+
const primaryType = match?.[0];
|
3658
|
+
if (results.has(primaryType) || types[primaryType] === void 0) {
|
3659
|
+
return results;
|
3660
|
+
}
|
3661
|
+
results.add(primaryType);
|
3662
|
+
for (const field of types[primaryType]) {
|
3663
|
+
findTypeDependencies({ primaryType: field.type, types }, results);
|
3664
|
+
}
|
3665
|
+
return results;
|
3666
|
+
}
|
3667
|
+
function encodeField({
|
3668
|
+
types,
|
3669
|
+
name,
|
3670
|
+
type,
|
3671
|
+
value
|
3672
|
+
}) {
|
3673
|
+
if (types[type] !== void 0) {
|
3674
|
+
return [
|
3675
|
+
{ type: "bytes32" },
|
3676
|
+
keccak256(encodeData({ data: value, primaryType: type, types }))
|
3677
|
+
];
|
3678
|
+
}
|
3679
|
+
if (type === "bytes") {
|
3680
|
+
const prepend = value.length % 2 ? "0" : "";
|
3681
|
+
value = `0x${prepend + value.slice(2)}`;
|
3682
|
+
return [{ type: "bytes32" }, keccak256(value)];
|
3683
|
+
}
|
3684
|
+
if (type === "string")
|
3685
|
+
return [{ type: "bytes32" }, keccak256(toHex(value))];
|
3686
|
+
if (type.lastIndexOf("]") === type.length - 1) {
|
3687
|
+
const parsedType = type.slice(0, type.lastIndexOf("["));
|
3688
|
+
const typeValuePairs = value.map(
|
3689
|
+
(item) => encodeField({
|
3690
|
+
name,
|
3691
|
+
type: parsedType,
|
3692
|
+
types,
|
3693
|
+
value: item
|
3694
|
+
})
|
3695
|
+
);
|
3696
|
+
return [
|
3697
|
+
{ type: "bytes32" },
|
3698
|
+
keccak256(
|
3699
|
+
encodeAbiParameters(
|
3700
|
+
typeValuePairs.map(([t]) => t),
|
3701
|
+
typeValuePairs.map(([, v]) => v)
|
3702
|
+
)
|
3703
|
+
)
|
3704
|
+
];
|
3705
|
+
}
|
3706
|
+
return [{ type }, value];
|
3707
|
+
}
|
3708
|
+
|
3510
3709
|
// src/utils/signature/recoverAddress.ts
|
3511
|
-
|
3512
|
-
function recoverAddress({
|
3710
|
+
async function recoverAddress({
|
3513
3711
|
hash: hash2,
|
3514
3712
|
signature
|
3515
3713
|
}) {
|
3516
3714
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
3517
3715
|
const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
|
3518
3716
|
const v = hexToNumber(`0x${signatureHex.slice(130)}`);
|
3717
|
+
const { recoverPublicKey } = await import("@noble/secp256k1");
|
3519
3718
|
const publicKey = toHex(
|
3520
3719
|
recoverPublicKey(
|
3521
3720
|
hashHex.substring(2),
|
@@ -3528,28 +3727,75 @@ function recoverAddress({
|
|
3528
3727
|
}
|
3529
3728
|
|
3530
3729
|
// src/utils/signature/recoverMessageAddress.ts
|
3531
|
-
function recoverMessageAddress({
|
3730
|
+
async function recoverMessageAddress({
|
3532
3731
|
message,
|
3533
3732
|
signature
|
3534
3733
|
}) {
|
3535
3734
|
return recoverAddress({ hash: hashMessage(message), signature });
|
3536
3735
|
}
|
3537
3736
|
|
3737
|
+
// src/utils/signature/recoverTypedDataAddress.ts
|
3738
|
+
async function recoverTypedDataAddress({
|
3739
|
+
domain,
|
3740
|
+
message,
|
3741
|
+
primaryType,
|
3742
|
+
signature,
|
3743
|
+
types
|
3744
|
+
}) {
|
3745
|
+
return recoverAddress({
|
3746
|
+
hash: hashTypedData({
|
3747
|
+
domain,
|
3748
|
+
message,
|
3749
|
+
primaryType,
|
3750
|
+
types
|
3751
|
+
}),
|
3752
|
+
signature
|
3753
|
+
});
|
3754
|
+
}
|
3755
|
+
|
3538
3756
|
// src/utils/signature/verifyMessage.ts
|
3539
|
-
function verifyMessage({
|
3757
|
+
async function verifyMessage({
|
3540
3758
|
address,
|
3541
3759
|
message,
|
3542
3760
|
signature
|
3543
3761
|
}) {
|
3544
3762
|
return isAddressEqual(
|
3545
3763
|
getAddress(address),
|
3546
|
-
recoverMessageAddress({ message, signature })
|
3764
|
+
await recoverMessageAddress({ message, signature })
|
3765
|
+
);
|
3766
|
+
}
|
3767
|
+
|
3768
|
+
// src/utils/signature/verifyTypedData.ts
|
3769
|
+
async function verifyTypedData({
|
3770
|
+
address,
|
3771
|
+
domain,
|
3772
|
+
message,
|
3773
|
+
primaryType,
|
3774
|
+
signature,
|
3775
|
+
types
|
3776
|
+
}) {
|
3777
|
+
return isAddressEqual(
|
3778
|
+
getAddress(address),
|
3779
|
+
await recoverTypedDataAddress({
|
3780
|
+
domain,
|
3781
|
+
message,
|
3782
|
+
primaryType,
|
3783
|
+
signature,
|
3784
|
+
types
|
3785
|
+
})
|
3547
3786
|
);
|
3548
3787
|
}
|
3549
3788
|
|
3550
3789
|
// src/utils/transaction/assertRequest.ts
|
3551
3790
|
function assertRequest(args) {
|
3552
|
-
const {
|
3791
|
+
const {
|
3792
|
+
account: account_,
|
3793
|
+
gasPrice,
|
3794
|
+
maxFeePerGas,
|
3795
|
+
maxPriorityFeePerGas,
|
3796
|
+
to
|
3797
|
+
} = args;
|
3798
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
3553
3799
|
if (account && !isAddress(account.address))
|
3554
3800
|
throw new InvalidAddressError({ address: account.address });
|
3555
3801
|
if (to && !isAddress(to))
|
@@ -3565,7 +3811,7 @@ function assertRequest(args) {
|
|
3565
3811
|
// src/actions/public/call.ts
|
3566
3812
|
async function call(client, args) {
|
3567
3813
|
const {
|
3568
|
-
account,
|
3814
|
+
account: account_,
|
3569
3815
|
blockNumber,
|
3570
3816
|
blockTag = "latest",
|
3571
3817
|
accessList,
|
@@ -3579,6 +3825,7 @@ async function call(client, args) {
|
|
3579
3825
|
value,
|
3580
3826
|
...rest
|
3581
3827
|
} = args;
|
3828
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
3582
3829
|
try {
|
3583
3830
|
assertRequest(args);
|
3584
3831
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
@@ -3612,6 +3859,7 @@ async function call(client, args) {
|
|
3612
3859
|
} catch (err) {
|
3613
3860
|
throw getCallError(err, {
|
3614
3861
|
...args,
|
3862
|
+
account,
|
3615
3863
|
chain: client.chain
|
3616
3864
|
});
|
3617
3865
|
}
|
@@ -3625,6 +3873,7 @@ async function simulateContract(client, {
|
|
3625
3873
|
functionName,
|
3626
3874
|
...callRequest
|
3627
3875
|
}) {
|
3876
|
+
const account = callRequest.account ? parseAccount(callRequest.account) : void 0;
|
3628
3877
|
const calldata = encodeFunctionData({
|
3629
3878
|
abi,
|
3630
3879
|
args,
|
@@ -3659,7 +3908,7 @@ async function simulateContract(client, {
|
|
3659
3908
|
args,
|
3660
3909
|
docsPath: "/docs/contract/simulateContract",
|
3661
3910
|
functionName,
|
3662
|
-
sender:
|
3911
|
+
sender: account?.address
|
3663
3912
|
});
|
3664
3913
|
}
|
3665
3914
|
}
|
@@ -3751,9 +4000,13 @@ async function createContractEventFilter(client, {
|
|
3751
4000
|
|
3752
4001
|
// src/actions/public/estimateGas.ts
|
3753
4002
|
async function estimateGas(client, args) {
|
4003
|
+
if (!args.account)
|
4004
|
+
throw new AccountNotFoundError({
|
4005
|
+
docsPath: "/docs/actions/public/estimateGas"
|
4006
|
+
});
|
4007
|
+
const account = parseAccount(args.account);
|
3754
4008
|
try {
|
3755
4009
|
const {
|
3756
|
-
account,
|
3757
4010
|
accessList,
|
3758
4011
|
blockNumber,
|
3759
4012
|
blockTag = "latest",
|
@@ -3766,7 +4019,7 @@ async function estimateGas(client, args) {
|
|
3766
4019
|
to,
|
3767
4020
|
value,
|
3768
4021
|
...rest
|
3769
|
-
} =
|
4022
|
+
} = account.type === "local" ? await prepareRequest(client, args) : args;
|
3770
4023
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3771
4024
|
assertRequest(args);
|
3772
4025
|
const formatter = client.chain?.formatters?.transactionRequest;
|
@@ -3797,6 +4050,7 @@ async function estimateGas(client, args) {
|
|
3797
4050
|
} catch (err) {
|
3798
4051
|
throw getEstimateGasError(err, {
|
3799
4052
|
...args,
|
4053
|
+
account,
|
3800
4054
|
chain: client.chain
|
3801
4055
|
});
|
3802
4056
|
}
|
@@ -3810,6 +4064,7 @@ async function estimateContractGas(client, {
|
|
3810
4064
|
functionName,
|
3811
4065
|
...request
|
3812
4066
|
}) {
|
4067
|
+
const account = parseAccount(request.account);
|
3813
4068
|
const data = encodeFunctionData({
|
3814
4069
|
abi,
|
3815
4070
|
args,
|
@@ -3829,7 +4084,7 @@ async function estimateContractGas(client, {
|
|
3829
4084
|
args,
|
3830
4085
|
docsPath: "/docs/contract/simulateContract",
|
3831
4086
|
functionName,
|
3832
|
-
sender:
|
4087
|
+
sender: account?.address
|
3833
4088
|
});
|
3834
4089
|
}
|
3835
4090
|
}
|
@@ -4980,7 +5235,12 @@ async function addChain(client, { chain }) {
|
|
4980
5235
|
}
|
4981
5236
|
|
4982
5237
|
// src/actions/wallet/deployContract.ts
|
4983
|
-
function deployContract(walletClient, {
|
5238
|
+
function deployContract(walletClient, {
|
5239
|
+
abi,
|
5240
|
+
args,
|
5241
|
+
bytecode,
|
5242
|
+
...request
|
5243
|
+
}) {
|
4984
5244
|
const calldata = encodeDeployData({
|
4985
5245
|
abi,
|
4986
5246
|
args,
|
@@ -5021,10 +5281,9 @@ async function requestPermissions(client, permissions) {
|
|
5021
5281
|
// src/actions/wallet/sendTransaction.ts
|
5022
5282
|
async function sendTransaction(client, args) {
|
5023
5283
|
const {
|
5024
|
-
account,
|
5025
|
-
chain,
|
5284
|
+
account: account_ = client.account,
|
5285
|
+
chain = client.chain,
|
5026
5286
|
accessList,
|
5027
|
-
assertChain = true,
|
5028
5287
|
data,
|
5029
5288
|
gas,
|
5030
5289
|
gasPrice,
|
@@ -5035,13 +5294,20 @@ async function sendTransaction(client, args) {
|
|
5035
5294
|
value,
|
5036
5295
|
...rest
|
5037
5296
|
} = args;
|
5297
|
+
if (!account_)
|
5298
|
+
throw new AccountNotFoundError({
|
5299
|
+
docsPath: "/docs/actions/wallet/sendTransaction"
|
5300
|
+
});
|
5301
|
+
const account = parseAccount(account_);
|
5038
5302
|
try {
|
5039
5303
|
assertRequest(args);
|
5040
|
-
const
|
5041
|
-
if (
|
5042
|
-
|
5304
|
+
const chainId = await getChainId(client);
|
5305
|
+
if (chain !== null && chainId !== chain?.id) {
|
5306
|
+
if (!chain)
|
5307
|
+
throw new ChainNotFoundError();
|
5308
|
+
throw new ChainMismatchError({ chain, currentChainId: chainId });
|
5309
|
+
}
|
5043
5310
|
if (account.type === "local") {
|
5044
|
-
const chainId = chain?.id ?? currentChainId;
|
5045
5311
|
const request2 = await prepareRequest(client, {
|
5046
5312
|
account,
|
5047
5313
|
accessList,
|
@@ -5090,12 +5356,25 @@ async function sendTransaction(client, args) {
|
|
5090
5356
|
params: [request]
|
5091
5357
|
});
|
5092
5358
|
} catch (err) {
|
5093
|
-
throw getTransactionError(err,
|
5359
|
+
throw getTransactionError(err, {
|
5360
|
+
...args,
|
5361
|
+
account,
|
5362
|
+
chain: args.chain || void 0
|
5363
|
+
});
|
5094
5364
|
}
|
5095
5365
|
}
|
5096
5366
|
|
5097
5367
|
// src/actions/wallet/signMessage.ts
|
5098
|
-
async function signMessage(client, {
|
5368
|
+
async function signMessage(client, {
|
5369
|
+
account: account_ = client.account,
|
5370
|
+
data,
|
5371
|
+
message
|
5372
|
+
}) {
|
5373
|
+
if (!account_)
|
5374
|
+
throw new AccountNotFoundError({
|
5375
|
+
docsPath: "/docs/actions/wallet/signMessage"
|
5376
|
+
});
|
5377
|
+
const account = parseAccount(account_);
|
5099
5378
|
const message_ = message || data;
|
5100
5379
|
if (account.type === "local")
|
5101
5380
|
return account.signMessage(message_);
|
@@ -5107,12 +5386,17 @@ async function signMessage(client, { account, data, message }) {
|
|
5107
5386
|
|
5108
5387
|
// src/actions/wallet/signTypedData.ts
|
5109
5388
|
async function signTypedData(client, {
|
5110
|
-
account,
|
5389
|
+
account: account_ = client.account,
|
5111
5390
|
domain,
|
5112
5391
|
message,
|
5113
5392
|
primaryType,
|
5114
5393
|
types: types_
|
5115
5394
|
}) {
|
5395
|
+
if (!account_)
|
5396
|
+
throw new AccountNotFoundError({
|
5397
|
+
docsPath: "/docs/actions/wallet/signTypedData"
|
5398
|
+
});
|
5399
|
+
const account = parseAccount(account_);
|
5116
5400
|
const types = {
|
5117
5401
|
EIP712Domain: [
|
5118
5402
|
domain?.name && { name: "name", type: "string" },
|
@@ -5262,7 +5546,17 @@ function parseGwei(ether, unit = "wei") {
|
|
5262
5546
|
// src/utils/transaction/prepareRequest.ts
|
5263
5547
|
var defaultTip = parseGwei("1.5");
|
5264
5548
|
async function prepareRequest(client, args) {
|
5265
|
-
const {
|
5549
|
+
const {
|
5550
|
+
account: account_,
|
5551
|
+
gas,
|
5552
|
+
gasPrice,
|
5553
|
+
maxFeePerGas,
|
5554
|
+
maxPriorityFeePerGas,
|
5555
|
+
nonce
|
5556
|
+
} = args;
|
5557
|
+
if (!account_)
|
5558
|
+
throw new AccountNotFoundError();
|
5559
|
+
const account = parseAccount(account_);
|
5266
5560
|
const block = await getBlock(client, { blockTag: "latest" });
|
5267
5561
|
const request = { ...args, from: account.address };
|
5268
5562
|
if (typeof nonce === "undefined")
|
@@ -5482,6 +5776,7 @@ export {
|
|
5482
5776
|
parseAbiParameter,
|
5483
5777
|
parseAbiParameters,
|
5484
5778
|
getAccount,
|
5779
|
+
parseAccount,
|
5485
5780
|
isDeterministicError,
|
5486
5781
|
buildRequest,
|
5487
5782
|
defineChain,
|
@@ -5507,9 +5802,12 @@ export {
|
|
5507
5802
|
getSocket,
|
5508
5803
|
rpc,
|
5509
5804
|
hashMessage,
|
5805
|
+
hashTypedData,
|
5510
5806
|
recoverAddress,
|
5511
5807
|
recoverMessageAddress,
|
5808
|
+
recoverTypedDataAddress,
|
5512
5809
|
verifyMessage,
|
5810
|
+
verifyTypedData,
|
5513
5811
|
assertRequest,
|
5514
5812
|
call,
|
5515
5813
|
simulateContract,
|
@@ -5593,4 +5891,4 @@ export {
|
|
5593
5891
|
formatGwei,
|
5594
5892
|
parseEther
|
5595
5893
|
};
|
5596
|
-
//# sourceMappingURL=chunk-
|
5894
|
+
//# sourceMappingURL=chunk-FEPL5HFW.mjs.map
|