From 9576335893561603cfd6a8ff4454b69cb49f7484 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Wed, 14 Dec 2022 12:10:25 +0100 Subject: [PATCH] fix: rpc deployAccountContract request, rpc nonce hotfix --- src/provider/rpc.ts | 33 +++++++++++++++++++++------------ src/types/api/openrpc.ts | 4 +++- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index ca11ee59f..a7a0e7926 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -84,15 +84,22 @@ 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( method: T, params?: RPC.Methods[T]['params'] ): Promise { try { - const rawResult = await this.fetch(method, params); - const { error, result } = await rawResult.json(); - this.errorHandler(error); - return result as RPC.Methods[T]['result']; + const rawResponse = await this.fetch(method, params); + const response = await rawResponse.json(); + return this.deviationHandler(method, response) as RPC.Methods[T]['result']; } catch (error: any) { this.errorHandler(error?.response?.data); throw error; @@ -335,14 +342,16 @@ export class RpcProvider implements ProviderInterface { details: InvocationsDetailsWithNonce ): Promise { return this.fetchEndpoint('starknet_addDeployAccountTransaction', { - constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []), - class_hash: toHex(toBN(classHash)), - contract_address_salt: toHex(toBN(addressSalt || 0)), - type: 'DEPLOY', - max_fee: toHex(toBN(details.maxFee || 0)), - version: toHex(toBN(details.version || 0)), - signature: bigNumberishArrayToHexadecimalStringArray(signature || []), - nonce: toHex(toBN(details.nonce)), + deploy_account_transaction: { + constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []), + class_hash: toHex(toBN(classHash)), + contract_address_salt: toHex(toBN(addressSalt || 0)), + type: 'DEPLOY_ACCOUNT', + max_fee: toHex(toBN(details.maxFee || 0)), + version: toHex(toBN(details.version || 0)), + signature: bigNumberishArrayToHexadecimalStringArray(signature || []), + nonce: toHex(toBN(details.nonce)), + }, }); } diff --git a/src/types/api/openrpc.ts b/src/types/api/openrpc.ts index 5a81c5170..a88f4849b 100644 --- a/src/types/api/openrpc.ts +++ b/src/types/api/openrpc.ts @@ -500,7 +500,9 @@ export namespace OPENRPC { errors: Errors.INVALID_CONTRACT_CLASS; }; starknet_addDeployAccountTransaction: { - params: BROADCASTED_DEPLOY_ACCOUNT_TXN; + params: { + deploy_account_transaction: BROADCASTED_DEPLOY_ACCOUNT_TXN; + }; result: { transaction_hash: TXN_HASH; contract_address: FELT;