-1

In javascript to connect metamask it uses window.ethereum

    if (window.ethereum) {
  
      window.ethereum
        .request({ method: "eth_requestAccounts" })
        .then((res) => accountChangeHandler(res[0]));
    } else {
      alert("install metamask extension!!");
    }

How to do that in yew.rs?

      if web_sys::window().unwrap().ethereum {
            let eth = web_sys::window().unwrap().ethereum;
            log!(eth);

        } else {
            log!("install metamask extension!!");
        }

Code error: no field ethereum on type Window

Amiya Behera
  • 2,210
  • 19
  • 32

1 Answers1

1

It seems etherum is something created by some script you have somewhere and not a standard DOM property. (https://developer.mozilla.org/en-US/search?q=ethereum)

web-sys is just a convience library created on top of wasm-bindgen that gives easier access to the DOM API.

Still you have several ways to get the etherum value:

  1. Write some javascript using wasm-bindgen https://rustwasm.github.io/docs/wasm-bindgen/reference/js-snippets.html#using-inline_js
  2. Use the javascript Reflect, you will need js-sys library for this, because web-sys has no binding for it for some reason. js_sys::Reflect::get(&window, &"ethereum".into());
Julius Lungys
  • 191
  • 1
  • 6