Skip to content

Send payments

Automatic swap

Sending will automatically swap (see NUT-03) tokens if necessary, to ensure the correct amount is sent.

Send ecash

pub async fn send(
    multi_mint_wallet: &MultiMintWallet,
    mint_url: MintUrl,
    send_amount: Amount,
    send_unit: CurrencyUnit,
) -> Result<Token> {
    let wallet_key = WalletKey::new(mint_url, send_unit.clone());
    let wallet = multi_mint_wallet.expect_wallet(&wallet_key).await?;

    let prepared_send = wallet
        .prepare_send(
            send_amount,
            SendOptions {
                include_fee: true,
                ..Default::default()
            },
        )
        .await?;
    println!("The fees are: {} {send_unit}", prepared_send.fee());

    let token = wallet.send(prepared_send, None).await?;
    println!("The token is: {token}");

    Ok(token)
}

Send to Lightning

In this situation, the sender converts ecash into Lightning sats and pays the receiver's Lightning invoice in one step.

This is sometimes also referred to as "melting ecash".

pub async fn melt(
    multi_mint_wallet: &MultiMintWallet,
    mint_url: MintUrl,
    send_unit: CurrencyUnit,
    bolt11: String,
) -> Result<Melted> {
    let wallet_key = WalletKey::new(mint_url, send_unit);
    let wallet = multi_mint_wallet.expect_wallet(&wallet_key).await?;

    let quote = wallet.melt_quote(bolt11, None).await?;
    let melt = wallet.melt(&quote.id).await?;

    Ok(melt)
}