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

Fails to build for target wasm32-unknown-unknown #636

Closed mark-ruddy closed 2 years ago

mark-ruddy commented 2 years ago

Hi - I'm not sure if it is a target of this crate to build for wasm32-unknown-unknown but in my experience most crates do build for this target without issue.

If there was a simple update that would allow this crate to build for this target it would be great.

How to reproduce:

# If you don't have the WASM target yet
rustup target add wasm32-unknown-unknown

cargo new testing
# Add below to the Cargo.toml
[dependencies]
web3 = "0.18.0"

cargo build --target=wasm32-unknown-unknown

Short snippet of the large amount of error output, seems in general possibly a conflict with the std::net?:

error[E0308]: mismatched types
    --> /home/chr0/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1780:15
     |
1780 | from!(Socket, net::TcpListener);
     |               ^^^^^^^^^^^^^^^^ expected struct `TcpListener`, found `()`
     |
    ::: /home/chr0/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
     |
104  |             fn from(socket: $from) -> $for {
     |                ---- implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
    --> /home/chr0/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1781:15
     |
1781 | from!(Socket, net::UdpSocket);
     |               ^^^^^^^^^^^^^^ expected struct `UdpSocket`, found `()`
     |
    ::: /home/chr0/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
     |
104  |             fn from(socket: $from) -> $for {
     |                ---- implicitly returns `()` as its body has no tail or `return` expression
mark-ruddy commented 2 years ago

My bad this issue was unnecessary - just found the readme note about wasm.

For anyone who finds this issue in a similar situation to get it to build add this to your Cargo.toml:

web3 = { version = "0.18.0", default_features = false, features = ["wasm"] }
aewc commented 2 years ago
15 | use web3::signing::{keccak256, recover};
   |                                ^^^^^^^ no `recover` in `signing`

but in wasm, the signing has no recover