Skip to content

Get Started

Setup Project

CDK supports several storage backends:

  • cdk-redb for Redb
  • cdk-rexie for Rexie
  • cdk-sqlite for SQLite

Add the dependencies for CDK and the chosen storage backend to your Cargo.toml:

#cdk = { version = "0.8.1", features = ["wallet"] }
#cdk-sqlite = { version = "0.8.1", features = ["wallet"] }

cdk = { git = "https://github.com/ok300/cdk", branch = "ok300-add-expect-wallet", features = ["wallet"] }
cdk-sqlite = { git = "https://github.com/ok300/cdk", branch = "ok300-add-expect-wallet", features = ["wallet"] }

Initialize CDK Wallet

Based on the chosen DB type, initialize the DB location and the CDK wallet:

async fn init_wallet() -> Result<Arc<MultiMintWallet>> {
    let work_dir = std::env::current_dir()?;
    let sql_path = work_dir.join("cdk-db.sqlite");
    let localstore = Arc::new(WalletSqliteDatabase::new(&sql_path).await?);
    let seed = Arc::new(Mnemonic::generate(12)?.to_seed_normalized(""));

    let multi_mint_wallet = MultiMintWallet::new(localstore.clone(), seed, vec![]);
    for (mint_url, _) in localstore.get_mints().await? {
        multi_mint_wallet
            .create_and_add_wallet(&mint_url.to_string(), CurrencyUnit::Sat, None)
            .await?;
    }

    Ok(Arc::new(multi_mint_wallet))
}