getBlockWithTransactions doesn't parse anymore transactions' gasPrice and value into BigNumber
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:2
- Comments:10 (6 by maintainers)
Top GitHub Comments
This has been fixed in 5.4.5. Please try it out and let me know if you have any more issues.
Thanks! 😃
The issue is the same with InfuraProvider or JsonRpcProvider connected to geth 1.10.6 Thanks!