Skip to main content

python boltz client

Project description

Boltz Python Client

Boltz Client in Python, implementing mainchain and liquid submarine swaps. Used by e.g. https://github.com/lnbits/boltz.

CLI

$ boltz --help
Usage: boltz [OPTIONS] COMMAND [ARGS]...

  Python CLI of boltz-client-python, enjoy submarine swapping. :)

Options:
  --help  Show this message and exit.

Commands:
  calculate-swap-send-amount     calculate the amount of the invoice you...
  claim-reverse-swap             claims a reverse swap
  create-reverse-swap            create a reverse swap
  create-reverse-swap-and-claim  create a reverse swap and claim
  create-swap                    create a swap boltz will pay your...
  refund-swap                    refund a swap
  show-pairs                     show pairs of possible assets to swap
  swap-status                    get swap status retrieves the status of...

install the latest release from PyPI via pip install boltz_client.

LIB

initialize the client

from boltz_client import BoltzClient, BoltzConfig
config = BoltzConfig() # default config
client = BoltzClient(config, "BTC/BTC")

lifecycle swap

pr = create_lightning_invoice(100000) # example function to create a lightning invoice
refund_privkey_wif, swap = client.create_swap(pr)
print(f"pay this amount: {swap.expectedAmount}")
print(f"to this address: {swap.address}")
# when you pay the amount the invoice will be settled after the boltz claimed the swap

if swap fails you can refund like this

# example function to create an onchain address
onchain_address = create_onchain_address()
txid = await client.refund_swap(
    boltz_id=swap.id,
    privkey_wif=refund_privkey_wif,
    lockup_address=swap.address,
    receive_address=onchain_address,
    redeem_script_hex=swap.redeemScript,
    timeout_block_height=swap.timeoutBlockHeight,
)

lifecycle reverse swap

claim_privkey_wif, preimage_hex, swap = client.create_reverse_swap(50000)
# example function to pay the invoice
pay_task = asyncio.create_task(pay_invoice(swap.invoice))
# example function to create an onchain address
new_address = create_onchain_address()
task = asyncio.create_task(client.claim_reverse_swap(
    boltz_id=swap.id,
    receive_address=new_address,
    lockup_address=swap.lockupAddress,
    redeem_script_hex=swap.redeemScript,
    blinding_key=swap.blindingKey,
    privkey_wif=claim_privkey_wif,
    preimage_hex=preimage_hex,
    zeroconf=True,
))
txid = await task
await pay_task

development

installing

poetry install

running cli

poetry run boltz

starting regtest

cd docker
chmod +x regtest
./regtest

running tests

poetry run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boltz_client-0.2.2.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

boltz_client-0.2.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file boltz_client-0.2.2.tar.gz.

File metadata

  • Download URL: boltz_client-0.2.2.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for boltz_client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 17dd3a704ee8305e01ffa55690e489d875d12e1ba25be13f6117df093a111371
MD5 b53fd409403dc1699075bc461db68d1e
BLAKE2b-256 50aba874690d81316a87ec21cf1c623eed2c545d0f99545494e9345971f42428

See more details on using hashes here.

File details

Details for the file boltz_client-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: boltz_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for boltz_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e82003001f6d8d721184950c2cc8ea26100dcc42ab795f0e913a5d07ba9eb75b
MD5 31cbf47b768de7a6153d74320bcb4dc9
BLAKE2b-256 9b3d97248fd5a70c4b4b75ed167873fc3a604e3e60797f90ab165d54e0612b84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page