I'm trying to use the Web3 JavaScript library from Rust and I'm stuck. The standard usage of the library starts with:
// In Node.js use: const Web3 = require('web3');
let web3 = new Web3(Web3.givenProvider || "ws://localhost:8545");
The module you're supposed to import is a constructor, that also has some other properties. My Rust code that's supposed to bind this API looks like this:
#[wasm_bindgen(module = "web3")]
extern "C" {
type Web3;
#[wasm_bindgen(constructor)]
fn new(_: &Provider) -> Web3;
type Provider;
static givenProvider: Provider;
}
Which ends up outputting import { Web3, givenProvider } from 'web3';
and trying to run new Web3(...)
which fails. It should be doing something like import * as Web3 from 'web3';
, running new Web3(...)
and referencing Web3.givenProvider
.
How can I get wasm-bindgen to output code like that?