Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Add wasm support #2692

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

client: Add wasm support #2692

wants to merge 4 commits into from

Conversation

Aursen
Copy link
Contributor

@Aursen Aursen commented Nov 3, 2023

Problem

Currently, the anchor client cannot compile or be used in wasm.

Summary of changes

  • Reorganization a bit of the client code
  • Add wasm dependencies to the client
  • Add wasm tests

Copy link

vercel bot commented Nov 3, 2023

@Aursen is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto
Copy link
Collaborator

The import error makes sense as we don't have MessageEvent feature enabled here

error[E0432]: unresolved import `web_sys::MessageEvent`
  --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solana-client-wasm-1.17.2/src/pubsub.rs:10:15
   |
10 | use web_sys::{MessageEvent, WebSocket};
   |               ^^^^^^^^^^^^ no `MessageEvent` in the root

It's still strange that running wasm-pack test --chrome --features pubsub works locally for me even though MessageEvent feature is not enabled.

The errors about str is incorrect because MessageEvent is not enabled, and because the type is not available it doesn't get the correct return type of JsValue::as_string

error[E0277]: the size for values of type `str` cannot be known at compilation time
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solana-client-wasm-1.17.2/src/pubsub.rs:129:75
    |
129 |             if let Some(Ok(notification)) = event.data().as_string().map(|data| {
    |                                                                           ^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `str`
    = note: all function arguments must have a statically known size

Will push a fix for solana-client-wasm.

acheroncrypto added a commit to solana-playground/solana-playground that referenced this pull request Nov 4, 2023
…ersions

* Enable `MessageEvent` feature of `web-sys`. The crate works without `MessageEvent` feature enabled in the repo but not with the published version as revealed in coral-xyz/anchor#2692

* Update Solana crates to `1.17.4`

* Update `wasm-bindgen` to `0.2.88` and other related crates to the latest
@acheroncrypto
Copy link
Collaborator

Are you still interested in working on this? The main reason this hasn't been merged yet is because I wanted to check if we can decouple the WASM impl to reduce the complexity a bit.

@wiseaidev
Copy link

imho, having a single standalone crate is much better than having two separate crates and letting the compiler decide which one to enable. It also reduces the carbon footprint because you only need to host one crate on crate.io.

@Aursen
Copy link
Contributor Author

Aursen commented Jul 24, 2024

Are you still interested in working on this? The main reason this hasn't been merged yet is because I wanted to check if we can decouple the WASM impl to reduce the complexity a bit.

Yeah let met finish this one

@acheroncrypto
Copy link
Collaborator

imho, having a single standalone crate is much better than having two separate crates and letting the compiler decide which one to enable. It also reduces the carbon footprint because you only need to host one crate on crate.io.

By "decouple" I meant moving the impl to a different file or folder similar to blocking.rs and nonblocking.rs files.

@wiseaidev
Copy link

By "decouple" I meant moving the impl to a different file or folder similar to blocking.rs and nonblocking.rs files.

That makes sense! At first, I thought you meant to split it into two separate crates.

@wiseaidev
Copy link

Hey, @Aursen! It would be great if you could add a function to return the transaction without sending it by the client. I want the browser's wallet extension to handle signing and sending the transaction. If you can add this feature, that would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants