Skip to content

Commit

Permalink
fix: nonce should be fixed for deploy account to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Dec 14, 2022
1 parent 9576335 commit c8a38e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class Account extends Provider implements AccountInterface {
}: DeployAccountContractPayload,
transactionsDetail: InvocationsDetails = {}
): Promise<DeployContractResponse> {
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
const nonce = '0x0';
const version = toBN(transactionVersion);
const chainId = await this.getChainId();

Expand Down
2 changes: 1 addition & 1 deletion src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export abstract class AccountInterface extends ProviderInterface {
- optional address salt
- optional contractAddress
* @param transactionsDetail Invocation Details containing:
- optional nonce
- constant nonce = 0
- optional version
- optional maxFee
* @returns a confirmation of sending a transaction on the starknet contract
Expand Down
15 changes: 4 additions & 11 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,15 @@ export class RpcProvider implements ProviderInterface {
}
}

protected deviationHandler(method: string, { error, result }: any): any {
// for non-existing address Sequencer return '0x0' rpc return error.
if (method === 'starknet_getNonce' && error.code === 20) return '0x0';

this.errorHandler(error);
return result;
}

protected async fetchEndpoint<T extends keyof RPC.Methods>(
method: T,
params?: RPC.Methods[T]['params']
): Promise<RPC.Methods[T]['result']> {
try {
const rawResponse = await this.fetch(method, params);
const response = await rawResponse.json();
return this.deviationHandler(method, response) as RPC.Methods[T]['result'];
const rawResult = await this.fetch(method, params);
const { error, result } = await rawResult.json();
this.errorHandler(error);
return result as RPC.Methods[T]['result'];
} catch (error: any) {
this.errorHandler(error?.response?.data);
throw error;
Expand Down

0 comments on commit c8a38e5

Please sign in to comment.