-
Notifications
You must be signed in to change notification settings - Fork 8
Example loading NPM module #84
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
base: master
Are you sure you want to change the base?
Conversation
| const wsProvider = new WsProvider('wss://rpc.polkadot.io'); | ||
| const api = await ApiPromise.create({ provider: wsProvider }); | ||
|
|
||
| return api.genesisHash.toHex(); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
error handling outside of the update Co-authored-by: Maciej Hirsz <[email protected]>
Co-authored-by: Maciej Hirsz <[email protected]>
Usage
Install Node.js and dependencies. Build JS to ESM. Run in browser.
cd examples/npm_lib rm -rf node_modules rm -rf yarn.lock nvm use nvm install npm install -g yarn yarn yarn run esbuild rustup update rustup target add wasm32-unknown-unknown cargo install --locked trunk RUST_LOG=info trunk serve --address=127.0.0.1 --openClick "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
Test
cargo test --target wasm32-unknown-unknownIssue Status
yarn run esbuildPerhaps I need a#[allow(???)]https://doc.rust-lang.org/rustc/lints/listing/index.htmlwasm_bindgen_testit 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/... cargo +nightly miri test ...) the CI passes even if i have a test that should fail, but if don't use Miri (i.e.... cargo +nightly test ...) the CI doesn't pass, and it outputs errors as if that command was run in the parent kobold directory, even though it is being run in the kobold/examples/npm_lib/ folder, where it works and should output different messages the same as it does when it's run locally (i.e. it should be outputtingDEBUG walrus::module)