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
I am trying to build an event listener in web3 Rust. However, I am getting this error message below. I believe this is because .events returns a web3::contract::error, but my function returns a web3::error.
However, the web3::error from the web3 crate does not have a method to convert between the two errors. Is there anything I can do to get around this?
error[E0277]: `?` couldn't convert the error to `web3::Error`
--> src/main.rs:24:94
|
24 | let event_listener = contract_object.events("Vote", topic0, "".to_string(), topic2).await?;
| ^ the trait `From<web3::contract::Error>` is not implemented for `web3::Error`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `From<T>`:
<web3::Error as From<RecoveryError>>
<web3::Error as From<jsonrpc_core::types::error::Error>>
<web3::Error as From<native_tls::Error>>
<web3::Error as From<rocket::tokio::sync::mpsc::error::SendError<ipc::TransportMessage>>>
<web3::Error as From<rocket::tokio::sync::oneshot::error::RecvError>>
<web3::Error as From<serde_json::error::Error>>
<web3::Error as From<soketto::connection::Error>>
<web3::Error as From<soketto::handshake::Error>>
and 3 others
= note: required for `Result<std::string::String, web3::Error>` to implement `FromResidual<Result<Infallible, web3::contract::Error>>`
#[macro_use] extern crate rocket;
async fn get_donations(address: &String) -> web3::Result<String> {
let ws = web3::transports::WebSocket::new("wss://mainnet.infura.io/ws/v3/").await?;
let web3 = web3::Web3::new(ws);
let contract_address: H160 = Address::from_str("0x0F8e03A2175184228A429A118653D068F3a0Bb35").unwrap();
let abi = include_bytes!("../abi.json");
let contract_object = match Contract::from_json(web3.eth(), contract_address, abi) {
Ok(contract) => contract,
Err(e) => panic!("Error loading contract: {:?}", e),
};
let topic0:String= "0x0064caa73f1d59b69adbeb65654b0f0953597994e4241ee2460b560b8d65aaa2".to_string();
let topic2:String = "0xf0572ad90c411f8f5d5dcb0938f0021e1b5d28d7cf427ddc34cc3a53cc740336".to_string();
let event_listener = contract_object.events("Vote", topic0, "".to_string(), topic2).await?;
let address: H160 = Address::from_str(&address).unwrap();
let balance: U256 = web3.eth().balance(address,Some(BlockNumber::Latest)).await?;
let balance: String = balance.to_string();
Ok(balance)
}
The text was updated successfully, but these errors were encountered:
I am trying to build an event listener in web3 Rust. However, I am getting this error message below. I believe this is because .events returns a web3::contract::error, but my function returns a web3::error.
However, the web3::error from the web3 crate does not have a method to convert between the two errors. Is there anything I can do to get around this?
The text was updated successfully, but these errors were encountered: