Remote Procedure Call (RPC)

Bitcoin remote procedure call.

swap.providers.bitcoin.rpc.get_balance(address: str, network: str = 'mainnet', headers: dict = {}, timeout: int = 60) → int

Get Bitcoin balance.

Parameters
  • address (str) – Bitcoin address.

  • network (str) – Bitcoin network, defaults to testnet.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

int – Bitcoin balance (SATOSHI amount).

>>> from swap.providers.bitcoin.rpc import get_balance
>>> get_balance(address="mkFWGt4hT11XS8dJKzzRFsTrqjjAwZfQAC", network="testnet")
25800000
swap.providers.bitcoin.rpc.get_utxos(address: str, network: str = 'mainnet', include_script: bool = True, limit: int = 15, headers: dict = {}, timeout: int = 60) → list

Get Bitcoin unspent transaction outputs (UTXO’s).

Parameters
  • address (str) – Bitcoin address.

  • network (str) – Bitcoin network, defaults to testnet.

  • include_script (bool) – Bitcoin include script, defaults to True.

  • limit (int) – Bitcoin utxo’s limit, defaults to 15.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

list – Bitcoin unspent transaction outputs (UTXO’s).

>>> from swap.providers.bitcoin.rpc import get_utxos
>>> get_utxos(address="mkFWGt4hT11XS8dJKzzRFsTrqjjAwZfQAC", network="testnet")
[...]
swap.providers.bitcoin.rpc.get_transaction(transaction_id: str, network: str = 'mainnet', headers: dict = {}, timeout: int = 60) → dict

Get Bitcoin transaction detail.

Parameters
  • transaction_id (str) – Bitcoin transaction id/hash.

  • network (str) – Bitcoin network, defaults to testnet.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

dict – Bitcoin transaction detail.

>>> from swap.providers.bitcoin.rpc import get_transaction
>>> get_transaction(transaction_id="4e91bca76db112d3a356c17366df93e364a4922993414225f65390220730d0c1", network="testnet")
{...}
swap.providers.bitcoin.rpc.decode_raw(raw: str, network: str = 'mainnet', offline: bool = True, headers: dict = {}, timeout: int = 60) → dict

Decode original Bitcoin raw.

Parameters
  • raw (str) – Bitcoin transaction raw.

  • network (str) – Bitcoin network, defaults to testnet.

  • offline (bool) – Offline decode, defaults to True.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

dict – Bitcoin decoded transaction raw.

>>> from swap.providers.bitcoin.rpc import decode_raw
>>> decode_raw(raw="02000000011823f39a8c5f6f27845dd13a65e03fe2ef5108d235e7a36edb6eb267b0459c5a010000006a47304402207018b7fd1ba6624fe9bb0f16cd65fa243d202e32fdff452699f56465b61ab648022009f0dc1a0a63109246c45e120fc0d34b40e789dfc4d05e64f269602c7d67d9210121027f0dc0894bd690635412af782d05e4f79d3d40bf568978c650f3f1ca1a96cf36ffffffff02102700000000000017a9149418feed4647e156d6663db3e0cef7c050d038678734330100000000001976a91433ecab3d67f0e2bde43e52f41ec1ecbdc73f11f888ac00000000", network="testnet")
{...}
swap.providers.bitcoin.rpc.submit_raw(raw: str, network: str = 'mainnet', headers: dict = {}, timeout: int = 60) → str

Submit original Bitcoin raw into blockchain.

Parameters
  • raw (str) – Bitcoin transaction raw.

  • network (str) – Bitcoin network, defaults to testnet.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

dict – Bitcoin submitted transaction id/hash.

>>> from swap.providers.bitcoin.rpc import submit_raw
>>> submit_raw(raw="02000000011823f39a8c5f6f27845dd13a65e03fe2ef5108d235e7a36edb6eb267b0459c5a010000006a47304402207018b7fd1ba6624fe9bb0f16cd65fa243d202e32fdff452699f56465b61ab648022009f0dc1a0a63109246c45e120fc0d34b40e789dfc4d05e64f269602c7d67d9210121027f0dc0894bd690635412af782d05e4f79d3d40bf568978c650f3f1ca1a96cf36ffffffff02102700000000000017a9149418feed4647e156d6663db3e0cef7c050d038678734330100000000001976a91433ecab3d67f0e2bde43e52f41ec1ecbdc73f11f888ac00000000", network="testnet")
"167faa4043ff622e7860ee5228d1ad6d763c5a6cfce79dbc3b9b5fc7bded6394"