Skip to content

Commit ef9d5ec

Browse files
committed
tokio blocks wasm-unknown-unknown & ∴ wasm-pack & wasm-bindgen
web takeaway for the day: tokio doesn't support wasm32-unknown-unknown. will have to use wasm32-unknown-wasi, which tokio supports. i don't think wasm32-unknown-emscripten is going to help so: skip the wasm-pack and wasm-bindgen crates, which use wasm32-unknown-unknown see rustwasm/wasm-bindgen#3421 probably no big deal and other tools will work, this was just the first resource I tried
1 parent dddd3e3 commit ef9d5ec

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "www"]
2+
path = www
3+
url = [email protected]:ManyMath/create-wasm-app

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "monero-wasm"
33
version = "0.0.1"
44
authors = ["sneurlax <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[lib]
88
crate-type = ["cdylib", "rlib"]
@@ -28,3 +28,7 @@ wasm-bindgen-test = "0.3.34"
2828
[profile.release]
2929
# Tell `rustc` to optimize for small code size.
3030
opt-level = "s"
31+
32+
[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom]
33+
version = "0.2.15"
34+
features = ["js"]

src/lib.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod utils;
22

3+
use monero_rust::{MoneroWallet, Language, Network};
34
use wasm_bindgen::prelude::*;
45

56
#[wasm_bindgen]
@@ -9,5 +10,23 @@ extern "C" {
910

1011
#[wasm_bindgen]
1112
pub fn greet() {
12-
alert("Hello, monero-wasm!");
13+
// Generate a mnemonic seed in English
14+
let mnemonic = MoneroWallet::generate_mnemonic(Language::English);
15+
println!("Generated mnemonic: {}", mnemonic);
16+
17+
let mut primary_address = String::new();
18+
// Create a wallet from the mnemonic
19+
match MoneroWallet::new(&mnemonic, Network::Mainnet) {
20+
Ok(wallet) => {
21+
// Get the primary address of the wallet
22+
primary_address = wallet.get_primary_address();
23+
println!("Primary address: {}", primary_address);
24+
}
25+
Err(e) => {
26+
eprintln!("Failed to create wallet: {}", e);
27+
}
28+
}
29+
30+
let message = format!("{}: {}", &mnemonic, &primary_address);
31+
alert(message.as_str());
1332
}

www

Submodule www added at 5531752

0 commit comments

Comments
 (0)