File tree Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ describeIfRpc('RPCProvider', () => {
7373 expect ( typeof blockNumber ) . toBe ( 'number' ) ;
7474 } ) ;
7575
76+ test ( 'getL1GasPrice' , async ( ) => {
77+ const gasPrice = await rpcProvider . getL1GasPrice ( 'latest' ) ;
78+ expect ( typeof gasPrice ) . toBe ( 'string' ) ;
79+ } ) ;
80+
7681 test ( 'getStateUpdate' , async ( ) => {
7782 const stateUpdate = await rpcProvider . getBlockStateUpdate ( 'latest' ) ;
7883 expect ( stateUpdate ) . toMatchSchemaRef ( 'StateUpdateResponse' ) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,14 @@ export abstract class ProviderInterface {
7878 blockIdentifier ?: BlockIdentifier
7979 ) : Promise < ContractClassResponse > ;
8080
81+ /**
82+ * Gets the price of l1 gas in the block
83+ *
84+ * @param blockIdentifier block identifier
85+ * @returns gas price of the block
86+ */
87+ public abstract getL1GasPrice ( blockIdentifier : BlockIdentifier ) : Promise < string > ;
88+
8189 /**
8290 * Returns the contract class hash in the given block for the contract deployed at the given address
8391 *
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ export class RpcProvider implements ProviderInterface {
100100 return this . channel . getBlockWithTxs ( blockIdentifier ) ;
101101 }
102102
103+ public async getL1GasPrice ( blockIdentifier ?: BlockIdentifier ) {
104+ return this . channel
105+ . getBlockWithTxHashes ( blockIdentifier )
106+ . then ( this . responseParser . parseL1GasPriceResponse ) ;
107+ }
108+
103109 public async getBlockWithReceipts ( blockIdentifier ?: BlockIdentifier ) {
104110 if ( this . channel instanceof RPC06 . RpcChannel )
105111 throw new LibraryError ( 'Unsupported method for RPC version' ) ;
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ import { toBigInt } from '../num';
2020import { isString } from '../shortString' ;
2121import { estimateFeeToBounds , estimatedFeeToMaxFee } from '../stark' ;
2222import { ResponseParser } from '.' ;
23+ import { isString } from '../shortString' ;
24+
2325
2426export class RPCResponseParser
2527 implements
@@ -121,4 +123,8 @@ export class RPCResponseParser
121123 abi : isString ( res . abi ) ? JSON . parse ( res . abi ) : res . abi ,
122124 } ;
123125 }
126+
127+ public parseL1GasPriceResponse ( res : BlockWithTxHashes ) : string {
128+ return res . l1_gas_price . price_in_wei ;
129+ }
124130}
You can’t perform that action at this time.
0 commit comments