rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

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

Open peter-jim opened this issue 2 years ago • 1 comments

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?

peter-jim avatar Jun 03 '22 09:06 peter-jim

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

elpiel avatar Jul 11 '22 07:07 elpiel