provider.getBlock does not output all the block details
See original GitHub issueI am working on a block explorer project with ethers.js, experiencing that some data is not being outputted (specifically transaction and state roots). I tried the same with web3.js and could see these details.
getBlock from web3.js (https://web3js.readthedocs.io/en/v1.2.4/web3-eth.html#id51)
{ author: '0x08d85bd1004e3e674042eaddf81fb3beb4853a22',
difficulty: '340282366920938463463374607431768211452',
extraData:
'0xde830207008f5061726974792d457468657265756d86312e33392e30826c69',
gasLimit: 6041126,
gasUsed: 21000,
hash:
'0xf532be00c9cc1429c9fe11aeebb1b2541b98700c56b75ccca529b29918691739',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
miner: '0x08D85Bd1004E3e674042EAddF81Fb3beb4853a22',
number: 7,
parentHash:
'0x473125e4191781ee52242a2f88309bc5f1aeddf51b2c565e57f919f48e542f8d',
receiptsRoot:
'0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2',
sealFields:
[ '0x8412c58a07',
'0xb841ebebece16b24a9d9bf9c25c74d4371a2262669ce7bfaa70f7ee7f21614cfee922eddb6b03828ae81b8f5b2ef9cbb635d498810f93adb63c3d5996ba4ba032f7c01' ],
sha3Uncles:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
signature:
'ebebece16b24a9d9bf9c25c74d4371a2262669ce7bfaa70f7ee7f21614cfee922eddb6b03828ae81b8f5b2ef9cbb635d498810f93adb63c3d5996ba4ba032f7c01',
size: 700,
stateRoot:
'0x8ee6d1d71c090e51ba7b153f7d41472e417b44c8b66d31e473f588561bb4f949',
step: '314935815',
timestamp: 1574679079,
totalDifficulty: '2381976568446569244243622252022062675442',
transactions:
[ '0xd30e18e0f2d56e23ef85390222ba72e990e2480072d6d948698ed17b1e929894' ],
transactionsRoot:
'0x52a43eca1b06b7901b20429f45d687ac3a7dac95fe383d8d1223a1a19290078e',
uncles: [] }
The ethers.js getBlock gives the following output
{ hash:
'0xf532be00c9cc1429c9fe11aeebb1b2541b98700c56b75ccca529b29918691739',
parentHash:
'0x473125e4191781ee52242a2f88309bc5f1aeddf51b2c565e57f919f48e542f8d',
number: 7,
timestamp: 1574679079,
difficulty: null,
gasLimit: BigNumber { _hex: '0x5c2e26' },
gasUsed: BigNumber { _hex: '0x5208' },
miner: '0x08D85Bd1004E3e674042EAddF81Fb3beb4853a22',
extraData:
'0xde830207008f5061726974792d457468657265756d86312e33392e30826c69',
transactions:
[ '0xd30e18e0f2d56e23ef85390222ba72e990e2480072d6d948698ed17b1e929894' ] }
I also saw #276 which is closed, so I created a new one.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Provider - Ethers.js
A Provider in ethers is a read-only abstraction to access the blockchain data. ... Get the block from the network, where the result.transactions...
Read more >Why do I get no output when getting a block from a blockchain?
getBlockNumber() Block =await web3.eth.getBlock(latestBlock) Block.transactions. ... Seems the provider simply does not allow this method.
Read more >Hardhat get last block timestamp, block number, block hash ...
It's a provider that is connected to the network that Hardhat is using. ... just read the property from the returned block information:...
Read more >JSON-RPC API - ethereum.org
Fetches historical records of every block back to genesis. This is like one large append-only file, and includes all block headers, block bodies, ......
Read more >eth_getBlockByHash - Ethereum RPC method documentation
Object - A block object, or null when no block was found. ... gasUsed - The total used gas by all transactions in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just figured out a way to do this with ethers js:
const block = await provider.send('eth_getBlockByNumber', [ethers.utils.bigNumberify(i)._hex, true]);
Thank you @zemse this worked well.