alloy icon indicating copy to clipboard operation
alloy copied to clipboard

[Bug] wasm erc20 token transfer not working

Open skutcher opened this issue 1 year ago • 2 comments

Component

contract, transports

What version of Alloy are you on?

├── alloy v0.2.0 │ ├── alloy-contract v0.2.0 │ │ ├── alloy-dyn-abi v0.7.7 │ │ │ ├── alloy-json-abi v0.7.7 │ │ │ │ ├── alloy-primitives v0.7.7 │ │ │ │ │ ├── alloy-rlp v0.3.7 │ │ │ │ │ │ ├── alloy-rlp-derive v0.3.7 (proc-macro) │ │ │ │ │ │ ├── alloy-rlp v0.3.7 () │ │ │ │ ├── alloy-sol-type-parser v0.7.7 │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ ├── alloy-sol-type-parser v0.7.7 () │ │ │ ├── alloy-sol-types v0.7.7 │ │ │ │ ├── alloy-json-abi v0.7.7 () │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ │ ├── alloy-sol-macro v0.7.7 (proc-macro) │ │ │ │ │ ├── alloy-sol-macro-expander v0.7.7 │ │ │ │ │ │ ├── alloy-json-abi v0.7.7 │ │ │ │ │ │ │ ├── alloy-primitives v0.7.7 │ │ │ │ │ │ │ ├── alloy-sol-type-parser v0.7.7 │ │ │ │ │ │ ├── alloy-sol-macro-input v0.7.7 │ │ │ │ │ │ │ ├── alloy-json-abi v0.7.7 () │ │ │ │ │ ├── alloy-sol-macro-input v0.7.7 () │ │ ├── alloy-json-abi v0.7.7 () │ │ ├── alloy-network v0.2.0 │ │ │ ├── alloy-consensus v0.2.0 │ │ │ │ ├── alloy-eips v0.2.0 │ │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ │ │ ├── alloy-rlp v0.3.7 () │ │ │ │ │ ├── alloy-serde v0.2.0 │ │ │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ │ ├── alloy-rlp v0.3.7 () │ │ │ │ ├── alloy-serde v0.2.0 () │ │ │ ├── alloy-eips v0.2.0 () │ │ │ ├── alloy-json-rpc v0.2.0 │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ ├── alloy-rpc-types-eth v0.2.0 │ │ │ │ ├── alloy-consensus v0.2.0 () │ │ │ │ ├── alloy-eips v0.2.0 () │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ │ ├── alloy-rlp v0.3.7 () │ │ │ │ ├── alloy-serde v0.2.0 () │ │ │ │ ├── alloy-sol-types v0.7.7 () │ │ │ ├── alloy-serde v0.2.0 () │ │ │ ├── alloy-signer v0.2.0 │ │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ ├── alloy-sol-types v0.7.7 () │ │ ├── alloy-primitives v0.7.7 () │ │ ├── alloy-provider v0.2.0 │ │ │ ├── alloy-chains v0.1.23 │ │ │ ├── alloy-consensus v0.2.0 () │ │ │ ├── alloy-eips v0.2.0 () │ │ │ ├── alloy-json-rpc v0.2.0 () │ │ │ ├── alloy-network v0.2.0 () │ │ │ ├── alloy-primitives v0.7.7 () │ │ │ ├── alloy-rpc-client v0.2.0 │ │ │ │ ├── alloy-json-rpc v0.2.0 () │ │ │ │ ├── alloy-transport v0.2.0 │ │ │ │ │ ├── alloy-json-rpc v0.2.0 () │ │ │ │ ├── alloy-transport-http v0.2.0 │ │ │ │ │ ├── alloy-json-rpc v0.2.0 () │ │ │ │ │ ├── alloy-transport v0.2.0 () │ │ │ ├── alloy-rpc-types-eth v0.2.0 () │ │ │ ├── alloy-transport v0.2.0 () │ │ │ ├── alloy-transport-http v0.2.0 () │ │ ├── alloy-rpc-types-eth v0.2.0 () │ │ ├── alloy-sol-types v0.7.7 () │ │ ├── alloy-transport v0.2.0 () │ ├── alloy-core v0.7.7 │ │ ├── alloy-dyn-abi v0.7.7 () │ │ ├── alloy-json-abi v0.7.7 () │ │ ├── alloy-primitives v0.7.7 () │ │ └── alloy-sol-types v0.7.7 () │ ├── alloy-eips v0.2.0 () │ ├── alloy-provider v0.2.0 () │ └── alloy-rpc-client v0.2.0 (*)

Operating System

Linux

Describe the bug

I try todo an erc20 token transfer with target wasm32-unknown-unknown. contract total supply as well as contract balance of works perfect. but as soon as i call contract.transfer("to_adress", "token_amount).from("my_address").send().await

i got the following error message in the browser console:

panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-transport-0.2.0/src/utils.rs:56:9:
The 'wasm-bindgen' feature must be enabled

I have already added wasm bindgen to the future list in my Cargo.toml, but this changed nothing:

alloy = { version = "0.2", features = ["providers", "sol-types", "json", "contract", "wasm-bindgen"] }

skutcher avatar Jul 23 '24 19:07 skutcher

Can you try enabling "transports" feature too?

DaniPopes avatar Jul 24 '24 03:07 DaniPopes

Can you try enabling "transports" feature too?

sure than i got this at exactly the same line within the code

panicked at library/std/src/sys/pal/wasm/../unsupported/time.rs:13:9:
time not implemented on this platform

skutcher avatar Jul 24 '24 08:07 skutcher

Can you try enabling "transports" feature too?

sure than i got this at exactly the same line within the code

panicked at library/std/src/sys/pal/wasm/../unsupported/time.rs:13:9:
time not implemented on this platform

I'm having the same problem.. Did someone find a fix for this?

I think it is caused by Alloy using std::time instead of something like https://github.com/daxpedda/web-time . std::time is not WASM compatible.

mickvandijke avatar Oct 03 '24 09:10 mickvandijke

I ran into the same trouble with alloy. I have been using the wasm-bindgen feature, but that wasn't enough.

I have made a fork with patches that seem to work for me: https://github.com/b-zee/alloy/tree/fix-wasm-instant

See the patch here (it's unfortunately based on the 0.2.1 we depend on): https://github.com/alloy-rs/alloy/compare/v0.2.1...b-zee:alloy:fix-wasm-instant

Essentially it's a patch changing to depend on wasmtimer in the places I encountered a runtime error, e.g.:

#[cfg(target_arch = "wasm32")]
use wasmtimer::{std::Instant, tokio::sleep_until};

@DaniPopes, do you think the above is suitable for a PR? We'd love to publish a package soon and it would be awesome if the patch can be included in a future release of alloy.

b-zee avatar Oct 03 '24 13:10 b-zee

Sure, feel free!

DaniPopes avatar Oct 03 '24 13:10 DaniPopes

Great, I've put in a PR: https://github.com/alloy-rs/alloy/pull/1426

b-zee avatar Oct 03 '24 14:10 b-zee