Skip to content

Latest commit

 

History

History
301 lines (275 loc) · 6.9 KB

File metadata and controls

301 lines (275 loc) · 6.9 KB
marp true
<style> html, section, div { background: orange; } section, span, li { color: black; clear: both; } pre { color: black; background: white; clear: both; } hr { background: #3468C0; clear: both; } h1, h2 { color: black; font-family: monospace; } a, a:hover { color: #3468C0; font-family: monospace; text-decoration: none; } img { float: right; margin: 0.25rem; } </style>

Swiss Bitcoin Conference | 27. April 2024

Nerd Academy

BTC & LN Schnittstellen (API)

beat@bitagent.ch | bitagent.ch | github.com/bitagentch/sbcapi24


  • Bitcoin kaufen, sparen und verkaufen
  • Technische Beratung zu Kauf, Eigenverwahrung und Verkauf
  • Kaufen u.a. via Pocket REST API und 10% Gebühren sparen
  • Weitere Dienste: Lightning Adresse, Nostr Identifier

APIs und Protokolle im Bitcoin Umfeld

  1. Bitcoin RPC API (JSON-RPC)
  2. Lightning Network Daemon LND API (gRPC, REST)
  3. LNURL Documents LUDs
  4. Nostr Implementation Possibilities NIPs
  5. LnPay Api und App https://lnpay.onrender.com

1 Bitcoin RPC API (JSON-RPC)

bitcoind
bitcoin-cli
  • Port 8332
  • vi ~/.bitcoin/bitcoin.conf (restart bitcoind)
rpcuser=myusername
rpcpassword=mypassword

bitcoin-cli getblockcount
834404
curl --user bitagent \
--data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' \
-H 'content-type: text/plain;' \
http://127.0.0.1:8332/

{"result":834404,"error":null,"id":"curltest"}
node bitcoind-getblockcount.js
{
  statusCode: 200,
  body: { result: 834404, error: null, id: 'js-test' }
}

bitcoin-cli getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
node bitcoind-getblockhash.js 0
{
  statusCode: 200,
  body: {
    result: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
    error: null,
    id: 'js-test'
  }
}

bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
height: 0, time: 1231006505
node bitcoind-getblock.js 0
Block 0 @ 2009-01-03T18:15:05.000Z

2 LND API (gRPC, REST)

lnd
lncli
  • Port 10009 gRpc
  • Port 10080 Rest (default 8080)
  • vi ~/.lnd/lnd.conf
bitcoind.rpcuser=myusername
bitcoind.rpcpass=mypassword

lncli state
{ "state": "SERVER_ACTIVE" }
node lnd-get-state-grpc.js
{ state: 'SERVER_ACTIVE' }
node lnd-get-state-rest.js
{ statusCode: 200, body: { state: 'SERVER_ACTIVE' } }

lncli addinvoice
{
    "r_hash": "b5feeb250fc6d5f658a753a28a5f71506a13bdf07e9b4537ab4213170fe6e196",
    "payment_request": "lnbc1pjlxh:t7cq6cezuw",
    "add_index": "1",
    "payment_addr": "25c28a4dfa111674ab22f5dfd24075d30f51621625fd1242eeedf479717e1b26"
}
node lnd-add-invoice.js
  • POST /v1/invoices

lncli listinvoices
node lnd-list-invoices.js
  • GET /v1/invoices

lncli lookupinvoice 2af97d6c27366863dafb14f5b417fc1f12c7999c93b40d36afaa45bcb99fb69b
node lnd-lookup-invoice.js 2af97d6c27366863dafb14f5b417fc1f12c7999c93b40d36afaa45bcb99fb69b
  • GET /v1/invoice/{r_hash_str}

https://bitagent.ch/.well-known/lnurlp/beat
node lightning-address.js beat@bitagent.ch

{
    tag: "payRequest"
    callback: "https://bitagent.ch:443/.well-known/lnurlp/beat"
}
https://bitagent.ch/.well-known/lnurlp/beat?amount=1000&comment=Test
node lightning-address-pay.js beat@bitagent.ch

https://bitagent.ch/.well-known/nostr.json?name=beat
{
  names: {
    beat: "c36ca730cee5de659d4c673e876ebbc128ee271df6bb328b561da8c03f3449ba"
  }
}

https://bitagent.ch/.well-known/lnurlp/beat
{
    allowsNostr: true
    nostrPubkey: "c36ca730cee5de659d4c673e876ebbc128ee271df6bb328b561da8c03f3449ba"
}

5. LnPay Api und App


5.1 Spec ln-pay-api.yaml


5.2 Doc redocly/cli / swagger-ui

npx redocly build-docs ln-pay-api.yaml --output ln-pay-api.html
npx yaml2json ln-pay-api.yaml > ln-pay-api.json

5.3 Gen javascript

npm install @openapitools/openapi-generator-cli --save-dev
npx @openapitools/openapi-generator-cli generate -i ln-pay-api.yaml -g javascript -o gen/javascript

5.4 Api und App mit expressjs

node app.js
App listening on http://localhost:3000

5.5 End-to-End Testing mit cypress

npx cypress open
npx cypress run

5.6 Deploy mit Render


Fragen?