Prerequisites

To complete this guide, you will need the following:

1. Create a Rust project

cargo new <project-name>
cd <project-name>

2. Install dependencies

Add both the zebedee-rust and tokio crates to your project:

cargo add zebedee-rust tokio

3. Update your Cargo.toml

Update your Cargo.toml file to use full features in tokio.

[package]
name = "zbd-rust"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.29.1", features = ['full']}
zebedee-rust = "0.4.4"

4. Create a Charge

Open your project’s main.rs file and add the following code:

use std::env;
use zebedee_rust::{charges::*, ZebedeeClient};

#[tokio::main]
async fn main(){
    let apikey: String = env::var("ZBD_API_KEY").unwrap();
    let zbd_client = ZebedeeClient::new().apikey(apikey).build();

    let charge = Charge{
        amount: String::from("5000"),
        ..Default::default()
    };

    let charges_res = zbd_client.create_charge(&charge).await.unwrap();

    println!("{:?}", charge_res);
}
Make sure to create an environment variable called ZBD_API_KEY in your Rust project. This is the API key you get from your ZBD Project.

Run the following command to create your charge:

cargo run

You can now create charges using the ZBD and Rust!

Charges and payment requests are usually shown to users as QR codes that can be scanned by mobile apps (e.g. ZBD). Read Callbacks to understand how to receive updates about your payment asynchronously.

5. Try it yourself

You can now begin receiving instant Bitcoin payments with Rust + ZBD!