Rust library to connect a dApp to a Qubic wallet using WalletConnect v2, including QR-code flow and WASM support.
- Installation
- Quick start (Rust)
- Browser usage (WASM)
- API overview
- Data structures
- Examples
- TypeScript interoperability
- Requirements
- Important notes
- License
- Contributing
Add to your Cargo.toml (workspace/path dependency example):
[dependencies]
scapi = { path = "../scapi" }use scapi::wallet_connect::{WalletConnectClient, WalletConnectConfig, ClientMetadata};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = WalletConnectConfig {
project_id: std::env::var("WALLETCONNECT_PROJECT_ID")?,
qubic_chain_id: "qubic:mainnet".to_string(),
metadata: ClientMetadata {
name: "My Qubic dApp".to_string(),
description: "WalletConnect integration".to_string(),
url: "https://example.com".to_string(),
icons: vec![],
},
relay_url: None,
};
let mut client = WalletConnectClient::new(config)?;
client.init().await?;
let uri = client.connect().await?;
println!("WalletConnect URI (render as QR): {uri}");
let approved = client.wait_for_connection(120).await?;
if !approved {
println!("Connection rejected by wallet");
return Ok(());
}
let accounts = client.request_accounts().await?;
println!("Accounts: {accounts:?}");
Ok(())
}# Install wasm-pack
cargo install wasm-pack
# Build
wasm-pack build --target web- Import
pkg/scapi.js - Initialize WASM
- Create the client and call
connect() - Render the returned URI as a QR code using any QR library
new(config)→ create a clientinit()→ connect/init internal stateconnect()→ generate WalletConnect URI (for QR rendering)wait_for_connection(timeout_secs)→ wait for wallet approvalapprove()→ internal approval handling (advanced usage)request_accounts()→ fetch accounts from walletsend_qubic(from, to, amount)→ send Qubicsign_transaction(params)→ sign a transactionsend_transaction(params)→ sign and send a transactionsign_message(from, message)→ sign an arbitrary messagedisconnect()→ disconnect and clear sessionis_session_active()→ session statusget_session()→ session infoget_connection_url()→ current URI if availableevent_handler()→ subscribe to/emit events
project_id: String- WalletConnect Project IDqubic_chain_id: String-qubic:mainnetorqubic:testnetmetadata: ClientMetadata- app metadatarelay_url: Option<String>- optional relay URL override
address: Stringamount: Option<u64>additional_data: HashMap<String, serde_json::Value>
from: Stringto: Stringamount: u64tick: Option<u64>input_type: Option<u16>payload: Option<String>
See: examples/wallet_connect_basic.rs
See: examples/wallet_connect_transaction.rs
See: examples/wallet_connect_events.rs
If you migrate from the TypeScript implementation, the Rust client aims to keep:
- similar method names
- similar request/response payload shapes
- the same WalletConnect v2 + Qubic namespace approach
- Rust toolchain (stable)
- WalletConnect Project ID (WalletConnect Cloud)
wasm-pack(only for WASM builds)
- Project ID: get it from https://cloud.walletconnect.com/
- Chain ID: use
qubic:mainnetorqubic:testnet - Security: never store private keys in client-side code
- CORS: for browser integration ensure your environment allows required requests
As part of SCAPI, the project uses the same license as the main repository.
Contributions are welcome. Please open an issue or a pull request.