#crypto #ethereum #wasm #web3 #walletconnect

walletconnect-client

WASM library for walletconnect dApp connections

5 releases

new 0.1.4 Apr 22, 2024
0.1.3 Apr 15, 2024
0.1.2 Feb 27, 2024
0.1.1 Feb 13, 2024
0.1.0 Feb 13, 2024

#1935 in Magic Beans

Download history 30/week @ 2024-02-08 43/week @ 2024-02-15 186/week @ 2024-02-22 116/week @ 2024-02-29 50/week @ 2024-03-07 83/week @ 2024-03-14 52/week @ 2024-03-21 161/week @ 2024-03-28 107/week @ 2024-04-04 240/week @ 2024-04-11 254/week @ 2024-04-18

768 downloads per month
Used in ethers-web

MIT/Apache

120KB
3K SLoC

Quickstart

Add this to your Cargo.toml:

[dependencies]
walletconnect-client = "0.1"

And this to your code:

use walletconnect_client::prelude::*;

To initiate walletconnect connection with the wallet, set up your dApps metadata:

use walletconnect_client::prelude::*;

let dapp = Metadata::from("Your dApp's name", 
                          "Your dApp's short description", 
                          "https://url.of.your.dapp", 
                          vec!["https://url.to.your.dapps.icon".to_string()]);

...and once you'll get your projects id from WalletConnect portal, you can simply create the connection:

use walletconnect_client::prelude::*;

const PROJECT_ID: &str = "myprojectidfromwalletconnectportal";

async fn start_session(dapp: Metadata) -> Result<String, WalletConnectError> {
    let client = WalletConnect::connect(PROJECT_ID.into(), 
            1 /* Ethereums chain id */, 
            dapp, 
            None)?;
    let url = client.initiate_session(None).await?;
    Ok(url)
}

Now your wallet need to get your sessions url. You can pass it on using url call with proper schema, or present it using qrcode using crates such as qrcode-generator:

State loop is manually handled by the implementor (there's no concurrency in some places). You have to loop somewhere to get any updates from WalletConnect.

use walletconnect_client::prelude::*;

async fn handle_messages(wc: WalletConnect) {
    while let Ok(event) = wc.next().await {
        match event {
            Some(event) => println!("Got a new WC event {event:?}"),
            None => println!("This loop brought no new event, and that is fine")
        }
    }
}

Documentation

In progress of creation.

Features

  • Session creation and handling
  • Handling transaction signatures
  • Handling typed data signatures
  • Handling manual chain changes
  • Handling events
  • Handling pings
  • Handling session updates
  • Handling session deletion
  • Handling non-WASM usage for servers

Note on WASM

This library currently needs WASM to work. There is a plan to support server-side implementations, though. For now, we focus on building robust solution for WASM implementations of websites.

Dependencies

~34–54MB
~1M SLoC