tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 465 forks source link

Accounts.push() error, When I not use #[tokio::main] and async? #645

Open peter-jim opened 2 years ago

peter-jim commented 2 years ago

I want to try not use #[tokio::main] in my project . it show error follow this.

{unknown} no method named push found for struct CallFuture in the current scope method not found in CallFuture<Vec<H160>, Pin<Box<dyn std::future::Future<Output = Result<serde_json::value::Value, web3::Error>> + std::marker::Send>>>rustcE0599


my code is

let mut accounts = web3.eth().accounts(); accounts.push(hex!("0x5940C8F24c1c6ee04e0F7E1f44546d71859Cc3b7").into());

Is there a way I can run successfully without # [tokio::main] and async?

elpiel commented 2 years ago

I believe that the current implementation runs only in async. One way you could run it in blocking code is e.g. using the futures crate: https://docs.rs/futures/latest/futures/executor/fn.block_on.html or even better, with the exactly the same function exported by web3: https://docs.rs/web3/latest/web3/fn.block_on.html