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

web3.eth.getBlock() returns baseFeePerGas field as hex string instead of BN or number #4326

Closed
haltman-at opened this issue Sep 13, 2021 · 11 comments · Fixed by #4330
Closed
Assignees
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@haltman-at
Copy link
Contributor

Expected behavior

The field should be a BN, a number, or possibly a (decimal) numeric string.

Actual behavior

The field is a hexadecimal string.

Steps to reproduce the behavior

Start a private blockchain with Geth, using geth --dev --http. In a location where web3 is installed, run node --experimental-repl-await to open a Node console. Do:

Web3 = require("web3")
web3 = new Web3("http://localhost:8545/")
await web3.eth.getBlock("latest")

You will see that the baseFeePerGas field is returned as a hexadecimal string rather than any of the possibilities above.

Logs

> await web3.eth.getBlock("latest")
{
  baseFeePerGas: '0x3b9aca00',
  difficulty: '1',
  extraData: '0x0000000000000000000000000000000000000000000000000000000000000000e136d1f0e70b67d39719a234df75ca7ad60313410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  gasLimit: 11500000,
  gasUsed: 0,
  hash: '0xb0da7449ddcfd6a2a452464fc7ac58e9ec0be13cbbd3861b0a69498e90f25d9a',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  miner: '0x0000000000000000000000000000000000000000',
  mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
  nonce: '0x0000000000000000',
  number: 0,
  parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
  receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
  sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
  size: 627,
  stateRoot: '0x9f3a58bdd7a3fd28c637dc5d94dc07aee2226ccea79bbadb60b9093ac299357e',
  timestamp: 0,
  totalDifficulty: '1',
  transactions: [],
  transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
  uncles: []
}

Environment

Geth: 1.10.6-stable-576681f2
Web3.js: 1.5.2
Npm: 6.14.11
Node.js: v12.21.0

@spacesailor24
Copy link
Contributor

This is a simple fix, however I'm slightly concerned being that this is technically a breaking change

@philknows
Copy link

@spacesailor24 Once you have the PR, can we connect it and discuss as mentioned in today's call? Thanks. cc: @jdevcs to follow up on best way forward due to potential breaking change.

@3alpha
Copy link

3alpha commented Sep 19, 2021

Related to this issue, in Typescript you can't access (await web3.eth.getBlock(londonBlockNumber)).baseFeePerGas property because:

Property 'baseFeePerGas' does not exist on type 'BlockTransactionString

As a quick fix I just added that property here and I just wanted you to be aware.

@philknows
Copy link

This breaking change is being pushed to the next release (1.5.4) to not interfere with the already released 1.5.3-rc0.

spacesailor24 added a commit that referenced this issue Sep 24, 2021
* Add BigNumber formatter to baseFeePerGas in returned blocks

* Update CHANGELOG

* Update docs for getBlcok

* Add baseFeePerGas to example output

* Update formatting of baseFeePerGas to number

* Add baseFeePerGas to BlockHeader type
@spacesailor24 spacesailor24 reopened this Sep 24, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Nov 24, 2021
@haltman-at
Copy link
Contributor Author

Not stale, unless it's already done and wasn't properly closed.

@github-actions github-actions bot removed the Stale Has not received enough activity label Nov 25, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jan 26, 2022
@haltman-at
Copy link
Contributor Author

Not stale, unless it's already done and wasn't properly closed.

@github-actions github-actions bot removed the Stale Has not received enough activity label Jan 27, 2022
@kfazil
Copy link

kfazil commented Jul 26, 2022

What is the returned unit for baseFeePerGas? Is it wei or Gwei?

@gordilovvv
Copy link

gordilovvv commented Sep 24, 2022

Wei

@AlexandraC0DE
Copy link

`node --experimental-repl-await
Welcome to Node.js v16.14.2.
Type ".help" for more information.

Web3 = require("web3")
Uncaught Error: Cannot find module 'web3'
Require stack:

  • at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15

)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '' ]
}

web3 = new Web3("http://localhost:8545/")
Uncaught ReferenceError: Web3 is not defined
await web3.eth.getBlock("latest")
Uncaught ReferenceError: web3 is not defined
at REPL3:1:16

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants