Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit ec4bb7e

Browse files
committed
fix: nonce issue
1 parent d7a2901 commit ec4bb7e

File tree

9 files changed

+654
-812
lines changed

9 files changed

+654
-812
lines changed

actions/transferAll/core.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Account } from "../../ui/pickAccounts";
1111
import TOKENS from "../../default-tokens.json";
1212
import { Ora } from "ora";
1313
import { oraLog } from "../../oraLog";
14+
import { getNonce } from "./getNonce";
1415

1516
export async function transferAll(acc: Account, newAddress: string, ora: Ora) {
1617
const { privateKey } = acc;
@@ -52,7 +53,8 @@ export async function transferAll(acc: Account, newAddress: string, ora: Ora) {
5253
});
5354

5455
if (calls.length) {
55-
const { suggestedMaxFee } = await account.estimateFee(calls);
56+
const nonce = await getNonce(acc.address, acc.networkId); // use this to get the nonce, as this covers old and new way of getting nonce
57+
const { suggestedMaxFee } = await account.estimateFee(calls, { nonce });
5658

5759
const callsWithFee = calls.map((c) => {
5860
const tokenDetails = tokens.find((t) => t.symbol === "ETH");

actions/transferAll/getNonce.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { SequencerProvider as NewProvider } from "starknet-490";
2+
import { SequencerProvider as OldProvider } from "starknet";
3+
4+
export async function getNonce(address: string, network: string) {
5+
const lowerCaseAddress = address.toLowerCase();
6+
try {
7+
const oldProvider = new OldProvider({ network: network as any });
8+
const nonceResponse = await oldProvider
9+
.callContract({
10+
contractAddress: lowerCaseAddress,
11+
entrypoint: "get_nonce",
12+
})
13+
.catch(() =>
14+
oldProvider.callContract({
15+
contractAddress: lowerCaseAddress,
16+
entrypoint: "getNonce",
17+
})
18+
);
19+
const nonce = nonceResponse.result[0];
20+
return nonce;
21+
} catch {
22+
const newProvider = new NewProvider({ network: network as any });
23+
return newProvider.getNonce(lowerCaseAddress);
24+
}
25+
}

actions/transferAll/ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function showTransferAll(accounts: Account[]) {
3636

3737
transferResults.forEach((result) => {
3838
if (result.status === "rejected") {
39-
spinner.fail(result.reason);
39+
spinner.fail(result.reason?.toString());
4040
}
4141
});
4242

getImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function getImplementation(
66
network: "mainnet-alpha" | "goerli-alpha"
77
) {
88
const provider = new SequencerProvider({ network });
9-
const multicallProvider = new Multicall(provider);
9+
const multicallProvider = new Multicall(provider as any);
1010

1111
const implementationAnswers = await Promise.allSettled(
1212
addresses.map((address) =>

getSigner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function getSigners(
66
network: "mainnet-alpha" | "goerli-alpha"
77
) {
88
const provider = new SequencerProvider({ network });
9-
const multicallProvider = new Multicall(provider);
9+
const multicallProvider = new Multicall(provider as any);
1010

1111
const signerAnswers = await Promise.allSettled(
1212
addresses.map((address) =>

getTokenBalance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function getBalances(
1010
const tokens = TOKENS.filter((token) => token.network === network);
1111
const tokenAddresses = tokens.map((token) => token.address);
1212
const provider = new SequencerProvider({ network });
13-
const multicallProvider = new Multicall(provider);
13+
const multicallProvider = new Multicall(provider as any);
1414

1515
const addressesTokensCombinations = tokenAddresses.flatMap((token) =>
1616
addresses.map((address) => ({ address, token }))

getVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function getVersion(
66
network: "mainnet-alpha" | "goerli-alpha"
77
) {
88
const provider = new SequencerProvider({ network });
9-
const multicallContract = new Multicall(provider);
9+
const multicallContract = new Multicall(provider as any);
1010

1111
const versionAnswers = await Promise.allSettled(
1212
addresses.map((address) =>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"ora": "5",
4141
"prompts": "^2.4.2",
4242
"semver": "^7.3.7",
43-
"starknet": "^4.1.0",
43+
"starknet-490": "npm:[email protected]",
44+
"starknet": "4.1.0",
4445
"starknet-390": "npm:[email protected]",
4546
"yup": "^1.0.0-beta.4"
4647
}

0 commit comments

Comments
 (0)