Skip to content

Commit

Permalink
fix: prevent undefined rpc chainId in account
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Sep 8, 2022
1 parent d81f24d commit 9f69229
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/account/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZERO } from '../constants';
import { StarknetChainId, ZERO } from '../constants';
import { ProviderInterface, ProviderOptions } from '../provider';
import { Provider } from '../provider/default';
import { Signer, SignerInterface } from '../signer';
Expand Down Expand Up @@ -32,6 +32,10 @@ export class Account extends Provider implements AccountInterface {
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
}

public async getChainId(): Promise<StarknetChainId> {
return this.getChainId();
}

public async getNonce(): Promise<string> {
const { result } = await this.callContract({
contractAddress: this.address,
Expand All @@ -47,13 +51,14 @@ export class Account extends Provider implements AccountInterface {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = providedNonce ?? (await this.getNonce());
const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();

const signerDetails: InvocationsSignerDetails = {
walletAddress: this.address,
nonce: toBN(nonce),
maxFee: ZERO,
version,
chainId: this.chainId,
chainId,
};

const signature = await this.signer.signTransaction(transactions, signerDetails);
Expand Down Expand Up @@ -99,13 +104,14 @@ export class Account extends Provider implements AccountInterface {
}

const version = toBN(transactionVersion);
const chainId = await this.getChainId();

const signerDetails: InvocationsSignerDetails = {
walletAddress: this.address,
nonce,
maxFee,
version,
chainId: this.chainId,
chainId,
};

const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
Expand Down
4 changes: 4 additions & 0 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export class SequencerProvider implements ProviderInterface {
}
}

public async getChainId(): Promise<StarknetChainId> {
return Promise.resolve(this.chainId);
}

public async callContract(
{ contractAddress, entrypoint: entryPointSelector, calldata = [] }: Call,
blockIdentifier: BlockIdentifier = 'pending'
Expand Down

0 comments on commit 9f69229

Please sign in to comment.