London Advancing Bitcoin Tutorial

Content for Following Along!

Other people have followed this tutorial with some success:

If you’re having a problem, see above log where people have had issues. Common problems include:

  1. Not building latest sapio binary
  2. Not having the correct clang version (>=12)
  3. brew installing clang somewhere else (try /opt/homebrew, but also /usr/local/Cellar)
  4. xargs not liking something (working to debug it, you can open the JSONs with vi and do by hand some of the steps).

  1. Install JQ (json manipulating tool) if you don’t have it / other things needed to run a bitcoin node.
  2. Set up a signet node.

Build this branch

You’ll likely want settings like this in your bitcoin.conf too:

# generate this yourself                                                                                                                    rpcauth=generateme:fromtherpcauth.pyfile     

Get coins / DM me

  1. Follow the install instructions on You can skip the the sapio-studio part / pod part and just do the Local Quickstart up until “Instantiate a contract from the plugin”. You’ll also want to run cargo build –release from the root directory to build the sapio-cli.

  2. Open up the site
  3. Run sapio-cli contract api –file plugin-example/target/wasm32-unknown-unknown/debug/sapio_wasm_plugin_example.wasm
  4. Copy the resulting JSON into the RJSF site
  5. Fill out the form as you wish. You should see a JSON like
      "context": {
     "amount": 3,
     "network": "Signet",
     "effects": {
       "effects": {}
      "arguments": {
     "TreePay": {
       "fee_sats_per_tx": 1000,
       "participants": [
           "address": "tb1pwqchwp3zur2ewuqsvg0mcl34pmcyxzqn9x8vn0p5a4hzckmujqpqp2dlma",
           "amount": 1
           "address": "tb1pwqchwp3zur2ewuqsvg0mcl34pmcyxzqn9x8vn0p5a4hzckmujqpqp2dlma",
           "amount": 1
       "radix": 2

    You may have to delete some extra fields (that site is a little buggy).

Optionally, just modify the JSON above directly.

  1. Copy the JSON and paste it into a file ARGS.json
  2. Find your sapio-cli config file (mine is at ~/.config/sapio-cli/config.json). Modify it to look like (enter your rpcauth credentials):
      "main": null,
      "testnet": null,
      "signet": {
     "active": true,
     "api_node": {
       "url": "",
       "auth": {
         "UserPass": [
           "YOUR RPC NAME",
     "emulator_nodes": {
       "enabled": false,
       "emulators": [],
       "threshold": 1
     "plugin_map": {}
      "regtest": null
  3. Create a contract template:
    cat ARGS.json| ./target/release/sapio-cli contract create  --file plugin-example/target/wasm32-unknown-unknown/debug/sapio_wasm_plugin_example.wasm  | jq > UNBOUND.json
  4. Get a proposed funding & binding of the template to that utxo:
cat UNBOUND.json| ./target/release/sapio-cli contract bind | jq > BOUND.json
  1. Finalize the funding tx:
cat BOUND.json | jq ".program[\"funding\"].txs[0].linked_psbt.psbt" | xargs echo | xargs -I% ./bitcoin-cli -signet utxoupdatepsbt % |  xargs -I% ./bitcoin-cli -signet walletprocesspsbt % | jq ".psbt" | xargs -I% ./bitcoin-cli -signet finalizepsbt % | jq ".hex"
  1. Review the hex transaction/make sure you want this contract… and then send to network:
    ./bitcoin-cli -signet sendrawtransaction 020000000001015e69106b2eb00d668d945101ed3c0102cf35aba738ee6520fc2603bd60a872ea0000000000feffffff02e8c5eb0b000000002200203d00d88fd664cbfaf8a1296d3f717625595d2980976bbf4feeb
  2. Send the other transactions:
cat BOUND.json| jq .program | jq ".[].txs[0].linked_psbt.psbt" | xargs -I% ./target/release/sapio-cli psbt finalize --psbt %  | xargs -I% ./bitcoin-cli -signet sendrawtransaction %

Now what?

to continue the conversation...

© 2011-2021 Jeremy Rubin. All rights reserved.