Hi Devs,

As promised, a Sapio Tutorial. In this tutorial we'll walk through how to use the Sapio CLI to generate contracts and play with them on the network. We'll use a congestion control tree because it's very simple! We will walk through this step-by-step during the meeting today.

-1. Install JQ (json manipulating tool) if you don't have it / other things needed to run a bitcoin node.
0. Set up a node as described above.  You'll likely want settings like this in your bitcoin.conf too:
[signet]
# generate this yourself                                                                                                                    rpcauth=generateme:fromtherpcauth.pyfile     
txindex=1
signetchallenge=512102946e8ba8eca597194e7ed90377d9bbebc5d17a9609ab3e35e706612ee882759351ae
rpcport=18332
rpcworkqueue=1000
fallbackfee=0.0002

Get coins https://faucet.ctvsignet.com/ / DM me

1. Follow the install instructions on https://learn.sapio-lang.org/ch01-01-installation.html 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.


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.

6. Copy the JSON and paste it into a file ARGS.json
7. 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": "http://0.0.0.0:18332",
     "auth": {
       "UserPass": [
         "YOUR RPC NAME",
         "YOUR PASSWORD HERE"
       ]
     }
   },
   "emulator_nodes": {
     "enabled": false,
     "emulators": [],
     "threshold": 1
   },
   "plugin_map": {}
 },
 "regtest": null
}

8. 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
9. Get a proposed funding & binding of the template to that utxo:

cat UNBOUND.json| ./target/release/sapio-cli contract bind | jq > BOUND.json
10. 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"

11. Review the hex transaction/make sure you want this contract... and then send to network:

./bitcoin-cli -signet sendrawtransaction 020000000001015e69106b2eb00d668d945101ed3c0102cf35aba738ee6520fc2603bd60a872ea0000000000feffffff02e8c5eb0b000000002200203d00d88fd664cbfaf8a1296d3f717625595d2980976bbf4feeb
10ab090180ccdcb3faefd020000002251208f7e5e50ce7f65debe036a90641a7e4d719d65d621426fd6589e5ec1c5969e200140a348a8711cb389bdb3cc0b1050961e588bb42cb5eb429dd0a415b7b9c712748fa4d5d
fe2bb9c4dc48b31a7e3d1a66d9104bbb5936698f8ef8a92ac27a650663500000000



12. 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?

- Maybe load up the Sapio Studio and try it through the GUI?
- Modify the congestion control tree code and recompile it?
- How big of a tree can you make (I did about 6000 last night)?
- Try out other contracts?


On Mon, Feb 21, 2022 at 7:36 PM Jeremy Rubin <jeremy.l.rubin@gmail.com> wrote:
Hi All,

Apologies for the late posting of the agenda. The 4th CTV meeting will be held tomorrow at 12:00 PT in ##ctv-bip-review in Libera.chat.

Tomorrow the conversation will be slightly more tutorial focused. If you have time in advance of the meeting, it might be good to do some of this in advance.

1) Discussion: What is the goal of Signet? (20 minutes)
    - Do we have a "decision function" of observations from a test network?
    - What applications should be prototyped/fleshed out?
    - What level of fleshed out matters?
    - Should we add other experiments in the mix on this net, like APO/Sponsors?
    - Should we get e.g. lightning working on this signet?
2) Connecting to CTV Signet Tutorial (10 mins)

We'll make sure everyone who wants to be on it is on it & debug any issues.


Connect to:
```
[signet]
signetchallenge=512102946e8ba8eca597194e7ed90377d9bbebc5d17a9609ab3e35e706612ee882759351ae
addnode=50.18.75.225
```

3) Receiving Coins / Sending Coins (5 mins)
There's now a faucet for this signet: https://faucet.ctvsignet.com
And also an explorer: https://explorer.ctvsignet.com

4) Sapio tutorial (25 minutes)

Ahead of meeting, if you have time: skim https://learn.sapio-lang.org & download/build the sapio cli & plugin examples

We'll try to get everyone building and sending a basic application (e.g. congestion control tree or vault) on the signet (instructions to be posted before meeting).

We won't use Sapio Studio, just the Sapio CLI. 

5) Sapio Q&A (30 mins)

After some experience playing with Sapio, more general discussion about the project and what it may accomplish

6) General Discussion (30 minutes)


Best,

Jeremy