@@ -320,7 +320,7 @@ export class EthImpl implements Eth {
320320
321321 return EthImpl . numberTo0x ( gasPrice ) ;
322322 } catch ( error ) {
323- this . logger . trace ( error ) ;
323+ this . logger . error ( error , ` ${ requestIdPrefix } Failed to retrieve gasPrice` ) ;
324324 throw error ;
325325 }
326326 }
@@ -688,24 +688,31 @@ export class EthImpl implements Eth {
688688 this . logger . trace ( `${ requestIdPrefix } getTransactionCount(address=${ address } , blockNumOrTag=${ blockNumOrTag } )` ) ;
689689 const blockNumber = await this . translateBlockTag ( blockNumOrTag , requestId ) ;
690690 if ( blockNumber === 0 ) {
691- return '0x0' ;
692- } else {
693- try {
694- const result = await this . mirrorNodeClient . resolveEntityType ( address , requestId ) ;
695- if ( result ?. type === constants . TYPE_ACCOUNT ) {
696- const accountInfo = await this . sdkClient . getAccountInfo ( result ?. entity . account , EthImpl . ethGetTransactionCount , requestId ) ;
697- return EthImpl . numberTo0x ( Number ( accountInfo . ethereumNonce ) ) ;
698- }
699- else if ( result ?. type === constants . TYPE_CONTRACT ) {
700- return EthImpl . numberTo0x ( 1 ) ;
701- }
702- } catch ( e : any ) {
703- this . logger . error ( e , `${ requestIdPrefix } Error raised during getTransactionCount for address ${ address } , block number or tag ${ blockNumOrTag } ` ) ;
704- return predefined . INTERNAL_ERROR ;
691+ return EthImpl . zeroHex ;
692+ } else if ( address && ! blockNumOrTag ) {
693+ // get latest ethereumNonce
694+ const mirrorAccount = await this . mirrorNodeClient . getAccount ( address , requestId ) ;
695+ if ( mirrorAccount && mirrorAccount . ethereum_nonce ) {
696+ return EthImpl . numberTo0x ( mirrorAccount . ethereum_nonce ) ;
705697 }
706-
707- return EthImpl . numberTo0x ( 0 ) ;
708698 }
699+
700+ // check consensus node as back up
701+ try {
702+ const result = await this . mirrorNodeClient . resolveEntityType ( address , requestId ) ;
703+ if ( result ?. type === constants . TYPE_ACCOUNT ) {
704+ const accountInfo = await this . sdkClient . getAccountInfo ( result ?. entity . account , EthImpl . ethGetTransactionCount , requestId ) ;
705+ return EthImpl . numberTo0x ( Number ( accountInfo . ethereumNonce ) ) ;
706+ }
707+ else if ( result ?. type === constants . TYPE_CONTRACT ) {
708+ return EthImpl . numberTo0x ( 1 )
709+ }
710+
711+ return EthImpl . zeroHex ;
712+ } catch ( e : any ) {
713+ this . logger . error ( e , `${ requestIdPrefix } Error raised during getTransactionCount for address ${ address } , block number or tag ${ blockNumOrTag } ` ) ;
714+ return predefined . INTERNAL_ERROR ;
715+ }
709716 }
710717
711718 /**
@@ -735,9 +742,16 @@ export class EthImpl implements Eth {
735742 try {
736743 // Wait for the record from the execution.
737744 const record = await this . sdkClient . executeGetTransactionRecord ( contractExecuteResponse , EthereumTransaction . name , EthImpl . ethSendRawTransaction , requestId ) ;
745+ if ( ! record ) {
746+ this . logger . warn ( `${ requestIdPrefix } No record retrieved` ) ;
747+ throw predefined . INTERNAL_ERROR ;
748+ }
749+
738750 if ( record . ethereumHash == null ) {
739- throw new Error ( 'The ethereumHash can never be null for an ethereum transaction, and yet it was!!' ) ;
751+ this . logger . error ( `${ requestIdPrefix } The ethereumHash can never be null for an ethereum transaction, and yet it was!!` ) ;
752+ throw predefined . INTERNAL_ERROR ;
740753 }
754+
741755 return EthImpl . prepend0x ( Buffer . from ( record . ethereumHash ) . toString ( 'hex' ) ) ;
742756 } catch ( e ) {
743757 this . logger . error ( e ,
0 commit comments