question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getBlockWithTransactions doesn't parse anymore transactions' gasPrice and value into BigNumber

See original GitHub issue

Describe the bug

Providers::getBlockWithTransactions should return a Promise of a BlockWithTransaction which contains an array of TransactionResponse, where gasPrice and value members are ethers.BigNumber.

However, it now returns an hex string which should be parsed via ethers.BigNumber.from(tx.gasPrice). The running behavior does not match the types.

The behavior should be fixed, or the documentation changed to let us know when we manually need to use ethers.BigNumber.from and on which members of a TransactionResponse.

Reproduction steps In the code snippet below, tx.(gasPrice|value) and sameTx.(gasPrice|value) should be both ethers.BigNumber, but tx.(gasPrice|value) is a string.

const { ethers } = require("ethers")
 
;(async () => {
    const provider = new ethers.providers.InfuraProvider('homestead', XXX)
    const block = await provider.getBlockWithTransactions(13002989)
    const tx = block.transactions[0] // or take the index block.transactions.length-1, issue is the same with legacy (non eip1559) txs
    console.log('Testing TX:', tx.hash)
    console.log('[BLOCK] Gas price:', tx.gasPrice, typeof tx.gasPrice)
    console.log('[BLOCK] Value:', tx.value, typeof tx.value)
 
    const sameTx = await provider.getTransaction(tx.hash)
    console.log('[SINGLE TX]Gas price:', sameTx.gasPrice, typeof sameTx.gasPrice)
    console.log('[SINGLE TX]Value:', sameTx.value, typeof sameTx.value)
})()

Sample output:

Testing TX: 0x13758c2c3535460bdfaf109d7946b1a14351a93e7b4117b686da081f77b0381e
[BLOCK] Gas price: 0x948b168ed string
[BLOCK] Value: 0x176f906d16b8ce4 string
[SINGLE TX]Gas price: BigNumber { _hex: '0x0948b168ed', _isBigNumber: true } object
[SINGLE TX]Value: BigNumber { _hex: '0x0176f906d16b8ce4', _isBigNumber: true } object

Desired output:

Testing TX: 0x13758c2c3535460bdfaf109d7946b1a14351a93e7b4117b686da081f77b0381e
[BLOCK] Gas price: BigNumber { _hex: '0x0948b168ed', _isBigNumber: true } object
[BLOCK] Value: BigNumber { _hex: '0x0176f906d16b8ce4', _isBigNumber: true } object
[SINGLE TX]Gas price: BigNumber { _hex: '0x0948b168ed', _isBigNumber: true } object
[SINGLE TX]Value: BigNumber { _hex: '0x0176f906d16b8ce4', _isBigNumber: true } object

Environment: node.js v14.17.0 ethers.js: 5.4.4

Issue is the same with InfuraProvider or JsonRpcProvider (geth 1.10.6) Issue is the same whether the TX is version 0 or 2 (EIP 1559).

Search Terms gasPrice value BigNumber regression

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ricmoocommented, Aug 18, 2021

This has been fixed in 5.4.5. Please try it out and let me know if you have any more issues.

Thanks! 😃

1reaction
coinwalletdevcommented, Aug 18, 2021

The issue is the same with InfuraProvider or JsonRpcProvider connected to geth 1.10.6 Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I access a BigNumer in a transaction object?
I am struggling to simply access the BigNumber Object from the gasPrice in Javascript. Currently, I am storing the whole transaction to a ......
Read more >
How to re-send a transaction with higher gas price using ...
1. Sometimes, you submit a transaction on Ethereum without enough gas due to network congestion or too m... 2. We do a transaction...
Read more >
How to fix EthersJS "underflow" error | BigNumber.from Error
An underflow error can be thrown if you pass a wei value with a decimal place to a function. I'll show you a...
Read more >
bigNumber not parsing ether properly - Stack Overflow
The BigNumber is actually a BigInteger (you can't have decimal values in it). This is because on the Ethereum blockchain, ...
Read more >
BigNumber - ethers
A BigNumber is an object which safely allows mathematical operations on numbers of any magnitude. Most operations which need to return a value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found