{ bdk primer }

@danielabrozzoni - pleb.fi 2022

{ bitcoin wallet }

A piece of software that shows you how many sats you have, lets you receive new ones, and (eventually) lets you spend them

{ bitcoin wallet }

You might want to build...

 

  • ...a wallet with a cool UI/UX
  • ...a wallet with exotic features 🍍
    • multisig wallet with a non-shitty ux
    • multisig with timelocks

{ bitcoin wallet }

Building a bitcoin wallet from scratch is tricky

 

Things you need to take care of:

  • Generating keys
  • Generate addresses from keys
  • Monitor addresses
  • Spend

{ building a wallet }

{ from scratch }

{ 1. generating keys }

Not the worst part

{ 2. generating addresses }

{ OP_whattefck }

Well you just have to hash the script

It's easy right?
Ohh, so you want a 1 out of 10 multisig and you don't have the slightest idea how to write the script? Too bad

{ 3. monitor addresses }

Easy and boring

fn boring_sync() -> Result<(), Box<dyn Error>> {
  let client = connect_to_some_blockchain_backend()?;
  let new_utxos = client.did_i_receive_new_utxos()?;
  somehow_update_my_internal_state(new_utxos)?;
  // yay done
  Ok(())
}

If you want your app to support multiple backends you write the code multiple times ugh

{ 4. spend }

{ a shitshow 💩 }

How do I select coins

Ok it doesn't seem a shitshow but trust me it's hard

What should I put in the script sig

What should I put in the witness script

Wtf do I do to spend from taproot

What should I set the nLockTime to

What's the nSequence lol

No one gets RBF rules

{ tools that help }

{ 1. descriptors & miniscript }

Make the receive/spend funds part slightly easier

Dev writes policy instead of Bitcoin script

 

 

Miniscript compiler takes policy, gives back descriptor

 

 

When you need to receive or spend, miniscript figures outs most of the difficult stuff (generates the address, helps with building the tx but doesn't really do everything)

<A> OP_CHECKSIGVERIFY <B> OP_CHECKSIG
and_v(v:pk(A),pk(B))
and(pk(A),pk(B))

{ 2. bdk }

Library to build bitcoin wallets that makes everything super easy yay

Builds on top of miniscript

 

Basically does everything for ya 😘

{ 2. bdk }

Modular - you can customize many parts of the wallet, leave out pieces of code you don't like, add your code without forking the lib

You know LEGO? ->

{ 2. bdk }

{ Everything customizable }

Custom database

Custom coin selection

Custom blockchain backend

Custom signer

Thanks ❤️

We're doing a BDK workshop later 11.30AM

It's going to be cool

Don't miss it

Download Rust tho

{ bdk primer }

By Daniela Brozzoni