@@ -227,3 +227,53 @@ func (e *Eth) ChainID() (*big.Int, error) {
227227 }
228228 return parseBigInt (out ), nil
229229}
230+
231+ // FeeHistory is the result of the eth_feeHistory endpoint
232+ type FeeHistory struct {
233+ OldestBlock * big.Int `json:"oldestBlock"`
234+ Reward [][]* big.Int `json:"reward,omitempty"`
235+ BaseFee []* big.Int `json:"baseFeePerGas,omitempty"`
236+ GasUsedRatio []float64 `json:"gasUsedRatio"`
237+ }
238+
239+ func (f * FeeHistory ) UnmarshalJSON (data []byte ) error {
240+ var raw struct {
241+ OldestBlock * ArgBig `json:"oldestBlock"`
242+ Reward [][]* ArgBig `json:"reward,omitempty"`
243+ BaseFee []* ArgBig `json:"baseFeePerGas,omitempty"`
244+ GasUsedRatio []float64 `json:"gasUsedRatio"`
245+ }
246+ if err := json .Unmarshal (data , & raw ); err != nil {
247+ return err
248+ }
249+ if raw .OldestBlock != nil {
250+ f .OldestBlock = raw .OldestBlock .Big ()
251+ }
252+ if raw .Reward != nil {
253+ f .Reward = [][]* big.Int {}
254+ for _ , r := range raw .Reward {
255+ elem := []* big.Int {}
256+ for _ , i := range r {
257+ elem = append (elem , i .Big ())
258+ }
259+ f .Reward = append (f .Reward , elem )
260+ }
261+ }
262+ if raw .BaseFee != nil {
263+ f .BaseFee = []* big.Int {}
264+ for _ , i := range raw .BaseFee {
265+ f .BaseFee = append (f .BaseFee , i .Big ())
266+ }
267+ }
268+ f .GasUsedRatio = raw .GasUsedRatio
269+ return nil
270+ }
271+
272+ // FeeHistory returns base fee per gas and transaction effective priority fee
273+ func (e * Eth ) FeeHistory (from , to ethgo.BlockNumber ) (* FeeHistory , error ) {
274+ var out * FeeHistory
275+ if err := e .c .Call ("eth_feeHistory" , & out , from .String (), to .String (), nil ); err != nil {
276+ return nil , err
277+ }
278+ return out , nil
279+ }
0 commit comments