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

I cannot initialize my WebAssembly built from Rust. It told me failed to fetch when I call init() #3033

Open
martinrhan opened this issue Jan 23, 2025 · 2 comments

Comments

@martinrhan
Copy link

martinrhan commented Jan 23, 2025

Hi, I am trying to add the WebAssembly I built from Rust by this guide into my Snap. I added the pkg folder into /packages/snap

In my index.tsx, I added import init, { greet, get_hello_world_string } from '../pkg/hello_wasm.js';.

Then I was trying to add await init('../pkg/hello_wasm_bg.wasm'); into onRpcRequest. I did not work and I was given error "failed to fetch" when I click send message in the webpage of localhost:8000.

I also tried await fetch('./hello_wasm_bg.wasm'); and await fetch('../pkg/hello_wasm_bg.wasm'); They were all giving the same error failed to fetch.

I already added "endowment:network-access": {}, "endowment:webassembly": {} into my snap.manifest.json

Can any tell me how can I add my WebAssembly correctly into my Snap?

@FrederikBolding
Copy link
Member

For improved compatibility with WebAssembly, make sure you are running the latest Snaps CLI and have the experimental wasm flag enabled: https://github.com/MetaMask/snaps/blob/main/packages/examples/packages/wasm/snap.config.ts#L15-L17

Once you've done this you should be able to import the WASM bundle and bindgen code without requiring fetch!

Let me know if you run into more problems!

@martinrhan
Copy link
Author

I tried to put hello_wasm_bg.wasm onto liveserver and fetch it via http, now failed to fetch no longer appear, but I got this error instead

Failed to execute 'compile' on 'WebAssembly': An argument must be provided, which must be a Response or Promise object

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

No branches or pull requests

2 participants