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', () => {
73
73
expect ( typeof blockNumber ) . toBe ( 'number' ) ;
74
74
} ) ;
75
75
76
+ test ( 'getL1GasPrice' , async ( ) => {
77
+ const gasPrice = await rpcProvider . getL1GasPrice ( 'latest' ) ;
78
+ expect ( typeof gasPrice ) . toBe ( 'string' ) ;
79
+ } ) ;
80
+
76
81
test ( 'getStateUpdate' , async ( ) => {
77
82
const stateUpdate = await rpcProvider . getBlockStateUpdate ( 'latest' ) ;
78
83
expect ( stateUpdate ) . toMatchSchemaRef ( 'StateUpdateResponse' ) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,14 @@ export abstract class ProviderInterface {
78
78
blockIdentifier ?: BlockIdentifier
79
79
) : Promise < ContractClassResponse > ;
80
80
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
+
81
89
/**
82
90
* Returns the contract class hash in the given block for the contract deployed at the given address
83
91
*
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ export class RpcProvider implements ProviderInterface {
100
100
return this . channel . getBlockWithTxs ( blockIdentifier ) ;
101
101
}
102
102
103
+ public async getL1GasPrice ( blockIdentifier ?: BlockIdentifier ) {
104
+ return this . channel
105
+ . getBlockWithTxHashes ( blockIdentifier )
106
+ . then ( this . responseParser . parseL1GasPriceResponse ) ;
107
+ }
108
+
103
109
public async getBlockWithReceipts ( blockIdentifier ?: BlockIdentifier ) {
104
110
if ( this . channel instanceof RPC06 . RpcChannel )
105
111
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';
20
20
import { isString } from '../shortString' ;
21
21
import { estimateFeeToBounds , estimatedFeeToMaxFee } from '../stark' ;
22
22
import { ResponseParser } from '.' ;
23
+ import { isString } from '../shortString' ;
24
+
23
25
24
26
export class RPCResponseParser
25
27
implements
@@ -121,4 +123,8 @@ export class RPCResponseParser
121
123
abi : isString ( res . abi ) ? JSON . parse ( res . abi ) : res . abi ,
122
124
} ;
123
125
}
126
+
127
+ public parseL1GasPriceResponse ( res : BlockWithTxHashes ) : string {
128
+ return res . l1_gas_price . price_in_wei ;
129
+ }
124
130
}
You can’t perform that action at this time.
0 commit comments