You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now I'm participating in FVM Space Warp hackathon in Mark3d team with FileMarket project.
I've faced an issue with eth_getBlockByNumber and eth_getBlockByHash methods. Block format in response is not compatible with Rust web3 library. Trying to fetch block returns following error:
thread 'main' panicked at 'Decoder error: Error("invalid value: string \"\", expected 0x prefix", line: 0, column: 0)', src/bin/get_block.rs:16:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Code to represent the issue is following:
src/bin/get_block.rs file:
use web3::{
types::{BlockId,BlockNumber},};use env_logger;#[tokio::main]asyncfnmain(){
env_logger::init();let url = "https://api.hyperspace.node.glif.io/rpc/v1";let transport = web3::transports::Http::new(url).unwrap();let web3 = web3::Web3::new(transport);let block = match web3.eth().block(BlockId::Number(BlockNumber::Latest)).await{Ok(b) => b,Err(e) => panic!("{:}", e),};let block = match block {Some(b) => b,None => panic!("none"),};println!("{:?}", block);}
Running get_block.rs with trace log level gives following log:
[2023-01-25T13:08:27Z DEBUG web3::transports::http] [id:0] sending request: "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"latest\",false],\"id\":0}"
[2023-01-25T13:08:28Z DEBUG web3::transports::http] [id:0] received response: "{\"jsonrpc\":\"2.0\",\"result\":{\"hash\":\"0xe0f85c0ae6fe10cf099d29039dd083a5fb2be8b9a409b42512312dbf5e4699e8\",\"parentHash\":\"0x932f50fec9b5e67fa225cb0604c9d1e28e06a29b8baf8bf4225ff7c2e1ced42a\",\"sha3Uncles\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"stateRoot\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"transactionsRoot\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"receiptsRoot\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\",\"difficulty\":\"0x0\",\"totalDifficulty\":\"0x0\",\"number\":\"0x6897\",\"gasLimit\":\"0x2540be400\",\"gasUsed\":\"0x0\",\"timestamp\":\"0x63d12992\",\"extraData\":\"\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x0000000000000000\",\"baseFeePerGas\":\"0x64\",\"size\":\"0x0\",\"transactions\":[],\"uncles\":[]},\"id\":0}\n"
thread 'main' panicked at 'Decoder error: Error("invalid value: string \"\", expected 0x prefix", line: 0, column: 0)', src/bin/get_block.rs:16:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
So, there is no issue with the connection, it's just about the block structure.
I believe the issue is with extraData field. In web3 library it defined as Bytes. This requires 0x prefix for the field value and in response extraData is just an empty string.
Defining self-made block structure without extraData field and fetching it with web3::Transport execute method directly is a workaround (this can help other hackathon participants facing the same issue until it will be fixed).
The text was updated successfully, but these errors were encountered:
Right now I'm participating in FVM Space Warp hackathon in
Mark3d
team withFileMarket
project.I've faced an issue with
eth_getBlockByNumber
andeth_getBlockByHash
methods. Block format in response is not compatible with Rust web3 library. Trying to fetch block returns following error:Code to represent the issue is following:
src/bin/get_block.rs file:
Cargo.toml file:
Running
get_block.rs
with trace log level gives following log:So, there is no issue with the connection, it's just about the block structure.
I believe the issue is with
extraData
field. In web3 library it defined asBytes
. This requires0x
prefix for the field value and in responseextraData
is just an empty string.Defining self-made block structure without
extraData
field and fetching it with web3::Transportexecute
method directly is a workaround (this can help other hackathon participants facing the same issue until it will be fixed).The text was updated successfully, but these errors were encountered: