Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_feeHistory (EIP 1559) #4191

Merged
merged 11 commits into from
Jul 24, 2021
5 changes: 5 additions & 0 deletions packages/web3-eth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ var Eth = function Eth() {
params: 0,
outputFormatter: formatter.outputBigNumberFormatter
}),
new Method({
name: 'getFeeHistory',
call: 'eth_feeHistory',
params: 3,
spacesailor24 marked this conversation as resolved.
Show resolved Hide resolved
}),
new Method({
name: 'getAccounts',
call: 'eth_accounts',
Expand Down
14 changes: 14 additions & 0 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,16 @@ export class Eth {
): Promise<number>;

getGasPrice(
blockCount: number,
newestBlock: string,
rewardPercentiles: number[],
callback?: (error: Error, gasPrice: string) => void
): Promise<string>;

getFeeHistory(
callback?: (error: Error, feeHistory: FeeHistoryResult) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should contain blockCount, newestBlock and rewardPercentiles?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mixed up getGasPrice and getFeeHistory?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also rewardPercentiles should be marked as optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think the docs here are misleading https://github.com/ChainSafe/web3.js/pull/4190/files#diff-b1b5b8a010cd61ad800e528887f49730db04064d59d3ee5ed14de0f49f2ba11cR740

Looks like you still have to pass an empty array so I'm not sure if web3 should just do that as the default if that param isn't set? Would be more user friendly than having to pass an empty array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GregTheGreek Whoops, forgot to push, thank you

@corymsmith I think web3 defaulting an empty array would be nice for the user, but we can't have two optional arguments in typescript, so I'm not sure how we could do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I suppose the only way to do it would be to add a formatter that formats null into []

): Promise<FeeHistoryResult>;

getAccounts(
callback?: (error: Error, accounts: string[]) => void
): Promise<string[]>;
Expand Down Expand Up @@ -439,3 +446,10 @@ export interface StorageProof {
value: string;
proof: string[];
}

export interface FeeHistoryResult {
oldestBlock: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specifies oldestBlock is returned as a string but the tests are showing its returned as a number here:
https://github.com/ChainSafe/web3.js/pull/4191/files#diff-99b1655ae7b89f474d7f663a07e45ccaa75c9270bb15bf852f1f0bdf2164f711R23

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I just blindly followed the RPC docs, thank you

baseFeePerGas: string[];
gasUsedRatio: number[];
reward: string[][];
}
8 changes: 7 additions & 1 deletion packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
TransactionConfig,
hardfork,
Common,
chain
chain,
FeeHistoryResult
} from 'web3-eth';
import BN = require('bn.js');
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -178,6 +179,11 @@ eth.getGasPrice();
// $ExpectType Promise<string>
eth.getGasPrice((error: Error, gasPrice: string) => {});

// $ExpectType Promise<FeeHistoryResult>
eth.getFeeHistory();
// $ExpectType Promise<FeeHistoryResult>
eth.getFeeHistory((error: Error, feeHistory: FeeHistoryResult) => {});

// $ExpectType Promise<string[]>
eth.getAccounts();
// $ExpectType Promise<string[]>
Expand Down
46 changes: 46 additions & 0 deletions test/eth.feeHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var testMethod = require('./helpers/test.method.js');

var method = 'getFeeHistory';
var methodCall = 'eth_feeHistory';

var tests = [{
args: [4, "0xA30953", []],
formattedArgs: [4, "0xA30953", []],
result: {
"baseFeePerGas": [
"0xa",
"0x9",
"0x8",
"0x9",
"0x9"
],
"gasUsedRatio": [
0.003920375,
0.002625,
0.904999125,
0.348347625
],
"oldestBlock": 10684752
},
formattedResult: {
"baseFeePerGas": [
"0xa",
"0x9",
"0x8",
"0x9",
"0x9"
],
"gasUsedRatio": [
0.003920375,
0.002625,
0.904999125,
0.348347625
],
"oldestBlock": 10684752
},
call: methodCall
}];


testMethod.runTests('eth', method, tests);

1 change: 1 addition & 0 deletions test/eth_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('eth', function() {
u.methodExists(eth, 'isMining');
u.methodExists(eth, 'getCoinbase');
u.methodExists(eth, 'getGasPrice');
u.methodExists(eth, 'getFeeHistory');
u.methodExists(eth, 'getHashrate');
u.methodExists(eth, 'getAccounts');
u.methodExists(eth, 'getBlockNumber');
Expand Down