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

Example loading NPM module #84

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

Conversation

ltfschoen
Copy link
Contributor

@ltfschoen ltfschoen commented May 13, 2023

Usage:

  • Install Node.js
cd examples/npm_lib
nvm use
yarn
yarn run esbuild
RUST_LOG=info trunk serve --address=127.0.0.1 --open
  • Test cargo test --target wasm32-unknown-unknown
  • Click "Connect" in the UI at http://127.0.0.1:8080 and view it use Polkadot.js API to fetch and display a genesis hash

ISSUES

  • Note: I'm not sure how to get it to pass the CI since the .mjs file is gitignored until the user runs yarn run esbuild Perhaps I need a #[allow(???)] https://doc.rust-lang.org/rustc/lints/listing/index.html
  • Not sure how to run the tests since for wasm_bindgen_test it says "One other difference is that the tests must be in the root of the crate, or within a pub mod" and the implementation is in src/

const wsProvider = new WsProvider('wss://rpc.polkadot.io');
const api = await ApiPromise.create({ provider: wsProvider });

return api.genesisHash.toHex();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the type of genesisHash? You could potentially send raw binary from Uint8Array to Rust via &[u8] or Vec<u8> much more cheaply than via string (no Utf16 to Utf8 conversion necessary).

Copy link
Contributor Author

@ltfschoen ltfschoen May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's of type Hash that extends H256, and H256 extends U8aFixed, and U8aFixed extends Raw, which is a wrapper
around Uint8Array that implements IU8a.
i tried to send Uint8Array as you mentioned in this commit d921638, but not sure how to convert the bytes to string.
i also tried https://crates.io/crates/serde-wasm-bindgen/0.4.2 serde_wasm_bindgen::from_value without any luck

ltfschoen and others added 4 commits May 31, 2023 10:02
error handling outside of the update

Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

None yet

2 participants