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

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

Closed
coinwalletdev opened this issue Aug 11, 2021 · 10 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@coinwalletdev
Copy link

coinwalletdev commented Aug 11, 2021

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

@coinwalletdev coinwalletdev added the investigate Under investigation and may be a bug. label Aug 11, 2021
@firebun1337
Copy link

Yes, I noticed this problem as well after updating. Perhaps 5.4.2 or 5.4.3 is where the root change happened.

@epheph
Copy link

epheph commented Aug 17, 2021

Additionally, transaction type type is specified as a number but is returned as a string (such as 0x2)

@ricmoo
Copy link
Member

ricmoo commented Aug 17, 2021

Investigating this now. It should certainly still be a BigNumber.

@ricmoo
Copy link
Member

ricmoo commented Aug 17, 2021

What Provider or backend are you using?

@epheph
Copy link

epheph commented Aug 17, 2021

JsonRpcProvider, OpenEthereum

@coinwalletdev
Copy link
Author

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

@ricmoo
Copy link
Member

ricmoo commented Aug 18, 2021

Thanks! I've verified this is an issue, and am still investigating the root cause.

@ricmoo
Copy link
Member

ricmoo commented Aug 18, 2021

I've found the issue and fixed it in 78e4273. Sorry, a typo in the commit message (missing #) prevented the commit from being automatically picked up on this issue.

@ricmoo
Copy link
Member

ricmoo commented 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! :)

@ricmoo ricmoo added bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. labels Aug 18, 2021
@ricmoo
Copy link
Member

ricmoo commented Aug 24, 2021

No complaints, so I think this is working. I'll close it now. Let me know if there are any more problems.

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants