defichain


Namedefichain JSON
Version 3.1.3 PyPI version JSON
download
home_pagehttps://github.com/eric-volz/DefichainPython
SummaryDefichain Python Library
upload_time2024-02-02 14:36:25
maintainer
docs_urlNone
authorIntr0c
requires_python
license
keywords python defichain node ocean mnemonic wallet privatekey transactions raw transactions p2pkh p2sh p2wpkh defitx custom transaction
VCS
bugtrack_url
requirements requests six ecdsa base58 pycryptodome
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://github.com/eric-volz/DefichainPython/blob/main/docs/source/logo/readme/defichainpython-logo-big.png?raw=true
    :align: center
    :alt: DefichainPython Logo

\

|PyPI Version| |PyPI Python Version| |Downloads|

|Docs Build| |Tests|

|Telegram Group| |Twitter / X| |Status Page|

This library is a community funded project. The objective is to interact
with the defichain blockchain as effortlessly as possible. This can be archived by
utilizing a variety of methods:

1. `Node / RPC <#node-rpc>`__
2. `Ocean <#ocean>`__
3. `HDWallet <#hdwallet>`__
4. `Transactions <#transactions>`__

Installation
------------

Download the PyPi package:

.. code:: bash

   pip install defichain -U

Clone the GitHub Repository:

.. code:: bash

   git clone https://github.com/eric-volz/DefichainPython.git

Features
--------

1. `Node / RPC <https://docs.defichain-python.de/build/html/api/node/index.html>`__:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The node implementation empowers you to easily connect to your defichain
node without having to deal with everything else. You can execute any
function witch is supported by your defichain node.

Make a poolswap via your node:

.. code:: python

   # Import node object
   from defichain import Node

   # Specify connection
   node =  Node("user", "password", url="127.0.0.1", port=8554)

   addressFrom = "df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8"
   tokenFrom = "BTC"
   amount = 0.1
   addressTo = "df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8"
   tokenTo = "DFI"
   maxprice = 3000

   # Execute poolswap
   txid = node.poolpair.poolswap(addressFrom, tokenFrom, amount, addressTo, tokenTo, maxprice)

   # Print txid
   print(txid)

2. `Ocean <https://docs.defichain-python.de/build/html/api/ocean/index.html>`__:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ocean is an API infrastructure, which is operated by Birthday Research.
You can use it to retrieve a lot of information about the blockchain and
to interact with it.

Ask for the utxo balance of an address:

.. code:: python

   # Import ocean object
   from defichain import Ocean

   # Specify connection
   ocean =  Ocean(network="mainnet")

   # Execute getBalace method
   utxo_balance = ocean.address.getBalance("df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8")

   # Print the utxo balance of the requested address
   print(utxo_balance)

3. `HDWallet <https://docs.defichain-python.de/build/html/sdk/hdwallet/index.html>`__:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HDWallet (Hierarchical Deterministic Wallet) is a special wallet
implementation for defichain. You can use it to derive your private /
public keys from your mnemonic seed. This implementation is used in
combination with the following feature: `Transactions <#transactions>`__

Create a wallet for mainnet from mnemonic seed:

.. code:: python

   # Import wallet and network
   from defichain import Wallet
   from defichain.networks import DefichainMainnet

   #  Mnemonic seed
   mnemonic = "avocado key fan step egg engage winter upper attitude carry regret mixed utility body party trip valid oppose gas ensure deputy suspect blur trade"

   # Create wallet for specified network and insert mnemonic seed
   wallet = Wallet(DefichainMainnet)
   wallet.from_mnemonic(mnemonic)

   # Derive first account from the wallet
   account = wallet.get_account(0)

   # Print every address type
   print(account.get_p2pkh())  # 8KvWa4oCfAhdyUNK8pXJS8XnddsxY6ZY7J
   print(account.get_p2sh())  # dUiMDov5Jxg3qKcy9yi6petuUtrvBRezUS
   print(account.get_p2wpkh())  # df1qx52ql637w4t7uk2vjdatj3a24cnvuu4fkxryrr

   # Print every private key type
   print(account.get_privateKey())  # c72f08c17b475d641a711ef1e16bcdb0cc0c1210e6da846060b2e04d5c2299b3
   print(account.get_wif())  # L3tu3Bx5n8aWgcDd14btMPgxQ8H5VYbbNoodrNESaonom64YPnr9

4. `Transactions <https://docs.defichain-python.de/build/html/sdk/transactions/index.html>`__:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This transaction implementation enables you to create, sign and
broadcast your own transaction just within python. It supports native
utxo (send, sendall, …), as well as defi transactions (poolswap,
takeloan, …) for mainnet and testnet.

.. code:: python

   # Import ocean, wallet, network and txbuilder
   from defichain import Ocean
   from defichain import Wallet
   from defichain.networks import DefichainMainnet
   from defichain import TxBuilder

   # Specify ocean connection
   ocean =  Ocean(network="mainnet")

   # Create wallet and account
   mnemonic = "avocado key fan step egg engage winter upper attitude carry regret mixed utility body party trip valid oppose gas ensure deputy suspect blur trade"

   wallet = Wallet(DefichainMainnet)
   wallet.from_mnemonic(mnemonic)

   account = wallet.get_account(0)

   # Create TxBuilder
   builder = TxBuilder(account.get_p2wpkh(), account, ocean)

   addressFrom = account.get_p2wpkh()
   tokenFrom = "BTC"
   amount = 0.1
   addressTo = account.get_p2wpkh()
   tokenTo = "DFI"
   maxprice = 3000

   # Build poolswap transaction
   tx = builder.pool.poolswap(addressFrom, tokenFrom, amount, addressTo, tokenTo, maxprice)

   # Send transaction into the blockchain
   txid = builder.send_tx(tx)

   # Print txid
   print(txid)

`Community <https://docs.defichain-python.de/build/html/legal/community.html>`__
--------------------------------------------------------------------------------

This `project <https://github.com/eric-volz/DefichainPython>`_ is funded by the Defichain Community:

**Thank you for your trust!**

Because of that the community has the right to know about the progress and status of the project. You can view the
status of each module yourself on the
`status page <https://docs.defichain-python.de/build/html/main/statusAndTasks.html>`_!

All official updates and CFPs are listed on
`this page <https://docs.defichain-python.de/build/html/legal/community.html>`_!

If you have suggestions for improvement or other ideas, open an
`issue <https://github.com/eric-volz/DefichainPython/issues>`_, write me on
`Twitter / X <https://twitter.com/defichainpython>`_, leave a comment in the
`telegram group <https://t.me/DefichainPython>`_ or write me oldschool via email
(`defichainpython@volz.link <defichainpython@volz.link>`_)!


`License & Disclaimer <https://docs.defichain-python.de/build/html/legal/licenseAndDisclaimer.html>`__
------------------------------------------------------------------------------------------------------

By using (this repo), you (the user) agree to be bound by the `terms of this
license <https://github.com/eric-volz/defichainLibrary/blob/main/LICENSE>`__
(MIT License).

.. |PyPI Version| image:: https://img.shields.io/pypi/v/defichain.svg?color=green
   :target: https://pypi.org/project/defichain
.. |PyPI Python Version| image:: https://img.shields.io/pypi/pyversions/defichain.svg
   :target: https://pypi.org/project/defichain
.. |Downloads| image:: https://static.pepy.tech/personalized-badge/defichain?period=total&units=international_system&left_color=grey&right_color=green&left_text=Downloads
   :target: https://pepy.tech/project/defichain
.. |Docs Build| image:: https://github.com/eric-volz/DefichainPython/actions/workflows/publish_docs.yml/badge.svg
   :target: https://github.com/eric-volz/DefichainPython/actions/workflows/publish_docs.yml
.. |Tests| image:: https://github.com/eric-volz/DefichainPython/actions/workflows/tests.yml/badge.svg
   :target: https://github.com/eric-volz/DefichainPython/actions/workflows/tests.yml
.. |Telegram Group| image:: https://img.shields.io/badge/Telegram-Group-blue.svg?style=flat-square
   :target: https://t.me/DefichainPython
.. |Twitter / X| image:: https://img.shields.io/badge/Twitter / X-@DefichainPython-lightblue.svg?style=flat-square
   :target: https://twitter.com/defichainpython
.. |Status Page| image:: https://img.shields.io/badge/Status-Page-black.svg?style=flat-square
   :target: https://docs.defichain-python.de/build/html/main/statusAndTasks.html

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eric-volz/DefichainPython",
    "name": "defichain",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,defichain,node,ocean,mnemonic,wallet,privateKey,transactions,raw transactions,P2PKH,P2SH,P2WPKH,DefiTx,custom transaction",
    "author": "Intr0c",
    "author_email": "introc@volz.link",
    "download_url": "https://files.pythonhosted.org/packages/f1/ea/912b6ffd39702b4f8bc7386461f5d986f69123e5142e3e8396340bc6803c/defichain-3.1.3.tar.gz",
    "platform": null,
    "description": ".. image:: https://github.com/eric-volz/DefichainPython/blob/main/docs/source/logo/readme/defichainpython-logo-big.png?raw=true\n    :align: center\n    :alt: DefichainPython Logo\n\n\\\n\n|PyPI Version| |PyPI Python Version| |Downloads|\n\n|Docs Build| |Tests|\n\n|Telegram Group| |Twitter / X| |Status Page|\n\nThis library is a community funded project. The objective is to interact\nwith the defichain blockchain as effortlessly as possible. This can be archived by\nutilizing a variety of methods:\n\n1. `Node / RPC <#node-rpc>`__\n2. `Ocean <#ocean>`__\n3. `HDWallet <#hdwallet>`__\n4. `Transactions <#transactions>`__\n\nInstallation\n------------\n\nDownload the PyPi package:\n\n.. code:: bash\n\n   pip install defichain -U\n\nClone the GitHub Repository:\n\n.. code:: bash\n\n   git clone https://github.com/eric-volz/DefichainPython.git\n\nFeatures\n--------\n\n1. `Node / RPC <https://docs.defichain-python.de/build/html/api/node/index.html>`__:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe node implementation empowers you to easily connect to your defichain\nnode without having to deal with everything else. You can execute any\nfunction witch is supported by your defichain node.\n\nMake a poolswap via your node:\n\n.. code:: python\n\n   # Import node object\n   from defichain import Node\n\n   # Specify connection\n   node =  Node(\"user\", \"password\", url=\"127.0.0.1\", port=8554)\n\n   addressFrom = \"df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8\"\n   tokenFrom = \"BTC\"\n   amount = 0.1\n   addressTo = \"df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8\"\n   tokenTo = \"DFI\"\n   maxprice = 3000\n\n   # Execute poolswap\n   txid = node.poolpair.poolswap(addressFrom, tokenFrom, amount, addressTo, tokenTo, maxprice)\n\n   # Print txid\n   print(txid)\n\n2. `Ocean <https://docs.defichain-python.de/build/html/api/ocean/index.html>`__:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOcean is an API infrastructure, which is operated by Birthday Research.\nYou can use it to retrieve a lot of information about the blockchain and\nto interact with it.\n\nAsk for the utxo balance of an address:\n\n.. code:: python\n\n   # Import ocean object\n   from defichain import Ocean\n\n   # Specify connection\n   ocean =  Ocean(network=\"mainnet\")\n\n   # Execute getBalace method\n   utxo_balance = ocean.address.getBalance(\"df1qn6utdvuaq0yshc4sah6puzf0dnlfkc2c8ryme8\")\n\n   # Print the utxo balance of the requested address\n   print(utxo_balance)\n\n3. `HDWallet <https://docs.defichain-python.de/build/html/sdk/hdwallet/index.html>`__:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nHDWallet (Hierarchical Deterministic Wallet) is a special wallet\nimplementation for defichain. You can use it to derive your private /\npublic keys from your mnemonic seed. This implementation is used in\ncombination with the following feature: `Transactions <#transactions>`__\n\nCreate a wallet for mainnet from mnemonic seed:\n\n.. code:: python\n\n   # Import wallet and network\n   from defichain import Wallet\n   from defichain.networks import DefichainMainnet\n\n   #  Mnemonic seed\n   mnemonic = \"avocado key fan step egg engage winter upper attitude carry regret mixed utility body party trip valid oppose gas ensure deputy suspect blur trade\"\n\n   # Create wallet for specified network and insert mnemonic seed\n   wallet = Wallet(DefichainMainnet)\n   wallet.from_mnemonic(mnemonic)\n\n   # Derive first account from the wallet\n   account = wallet.get_account(0)\n\n   # Print every address type\n   print(account.get_p2pkh())  # 8KvWa4oCfAhdyUNK8pXJS8XnddsxY6ZY7J\n   print(account.get_p2sh())  # dUiMDov5Jxg3qKcy9yi6petuUtrvBRezUS\n   print(account.get_p2wpkh())  # df1qx52ql637w4t7uk2vjdatj3a24cnvuu4fkxryrr\n\n   # Print every private key type\n   print(account.get_privateKey())  # c72f08c17b475d641a711ef1e16bcdb0cc0c1210e6da846060b2e04d5c2299b3\n   print(account.get_wif())  # L3tu3Bx5n8aWgcDd14btMPgxQ8H5VYbbNoodrNESaonom64YPnr9\n\n4. `Transactions <https://docs.defichain-python.de/build/html/sdk/transactions/index.html>`__:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis transaction implementation enables you to create, sign and\nbroadcast your own transaction just within python. It supports native\nutxo (send, sendall, \u2026), as well as defi transactions (poolswap,\ntakeloan, \u2026) for mainnet and testnet.\n\n.. code:: python\n\n   # Import ocean, wallet, network and txbuilder\n   from defichain import Ocean\n   from defichain import Wallet\n   from defichain.networks import DefichainMainnet\n   from defichain import TxBuilder\n\n   # Specify ocean connection\n   ocean =  Ocean(network=\"mainnet\")\n\n   # Create wallet and account\n   mnemonic = \"avocado key fan step egg engage winter upper attitude carry regret mixed utility body party trip valid oppose gas ensure deputy suspect blur trade\"\n\n   wallet = Wallet(DefichainMainnet)\n   wallet.from_mnemonic(mnemonic)\n\n   account = wallet.get_account(0)\n\n   # Create TxBuilder\n   builder = TxBuilder(account.get_p2wpkh(), account, ocean)\n\n   addressFrom = account.get_p2wpkh()\n   tokenFrom = \"BTC\"\n   amount = 0.1\n   addressTo = account.get_p2wpkh()\n   tokenTo = \"DFI\"\n   maxprice = 3000\n\n   # Build poolswap transaction\n   tx = builder.pool.poolswap(addressFrom, tokenFrom, amount, addressTo, tokenTo, maxprice)\n\n   # Send transaction into the blockchain\n   txid = builder.send_tx(tx)\n\n   # Print txid\n   print(txid)\n\n`Community <https://docs.defichain-python.de/build/html/legal/community.html>`__\n--------------------------------------------------------------------------------\n\nThis `project <https://github.com/eric-volz/DefichainPython>`_ is funded by the Defichain Community:\n\n**Thank you for your trust!**\n\nBecause of that the community has the right to know about the progress and status of the project. You can view the\nstatus of each module yourself on the\n`status page <https://docs.defichain-python.de/build/html/main/statusAndTasks.html>`_!\n\nAll official updates and CFPs are listed on\n`this page <https://docs.defichain-python.de/build/html/legal/community.html>`_!\n\nIf you have suggestions for improvement or other ideas, open an\n`issue <https://github.com/eric-volz/DefichainPython/issues>`_, write me on\n`Twitter / X <https://twitter.com/defichainpython>`_, leave a comment in the\n`telegram group <https://t.me/DefichainPython>`_ or write me oldschool via email\n(`defichainpython@volz.link <defichainpython@volz.link>`_)!\n\n\n`License & Disclaimer <https://docs.defichain-python.de/build/html/legal/licenseAndDisclaimer.html>`__\n------------------------------------------------------------------------------------------------------\n\nBy using (this repo), you (the user) agree to be bound by the `terms of this\nlicense <https://github.com/eric-volz/defichainLibrary/blob/main/LICENSE>`__\n(MIT License).\n\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/defichain.svg?color=green\n   :target: https://pypi.org/project/defichain\n.. |PyPI Python Version| image:: https://img.shields.io/pypi/pyversions/defichain.svg\n   :target: https://pypi.org/project/defichain\n.. |Downloads| image:: https://static.pepy.tech/personalized-badge/defichain?period=total&units=international_system&left_color=grey&right_color=green&left_text=Downloads\n   :target: https://pepy.tech/project/defichain\n.. |Docs Build| image:: https://github.com/eric-volz/DefichainPython/actions/workflows/publish_docs.yml/badge.svg\n   :target: https://github.com/eric-volz/DefichainPython/actions/workflows/publish_docs.yml\n.. |Tests| image:: https://github.com/eric-volz/DefichainPython/actions/workflows/tests.yml/badge.svg\n   :target: https://github.com/eric-volz/DefichainPython/actions/workflows/tests.yml\n.. |Telegram Group| image:: https://img.shields.io/badge/Telegram-Group-blue.svg?style=flat-square\n   :target: https://t.me/DefichainPython\n.. |Twitter / X| image:: https://img.shields.io/badge/Twitter / X-@DefichainPython-lightblue.svg?style=flat-square\n   :target: https://twitter.com/defichainpython\n.. |Status Page| image:: https://img.shields.io/badge/Status-Page-black.svg?style=flat-square\n   :target: https://docs.defichain-python.de/build/html/main/statusAndTasks.html\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Defichain Python Library",
    "version": "3.1.3",
    "project_urls": {
        "Homepage": "https://github.com/eric-volz/DefichainPython"
    },
    "split_keywords": [
        "python",
        "defichain",
        "node",
        "ocean",
        "mnemonic",
        "wallet",
        "privatekey",
        "transactions",
        "raw transactions",
        "p2pkh",
        "p2sh",
        "p2wpkh",
        "defitx",
        "custom transaction"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f1c62523c45af3bf66face8bba19d534807e3cf43164d45d36f0e29104acff1",
                "md5": "c8bf3610ecf47946659eed82dda7c1b2",
                "sha256": "bce5e65e096ef6d73f2d9fd9c163f3e68a5f54cab549fba2c8b6e37e2617684f"
            },
            "downloads": -1,
            "filename": "defichain-3.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8bf3610ecf47946659eed82dda7c1b2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 277970,
            "upload_time": "2024-02-02T14:36:24",
            "upload_time_iso_8601": "2024-02-02T14:36:24.229817Z",
            "url": "https://files.pythonhosted.org/packages/8f/1c/62523c45af3bf66face8bba19d534807e3cf43164d45d36f0e29104acff1/defichain-3.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1ea912b6ffd39702b4f8bc7386461f5d986f69123e5142e3e8396340bc6803c",
                "md5": "cfa51b96a61d15a85b013e57eeadc332",
                "sha256": "c44c16191786a18d5e6f436552e1c6bce7f7ea8ead75027ae69458a18c7b49f3"
            },
            "downloads": -1,
            "filename": "defichain-3.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "cfa51b96a61d15a85b013e57eeadc332",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 222908,
            "upload_time": "2024-02-02T14:36:25",
            "upload_time_iso_8601": "2024-02-02T14:36:25.704078Z",
            "url": "https://files.pythonhosted.org/packages/f1/ea/912b6ffd39702b4f8bc7386461f5d986f69123e5142e3e8396340bc6803c/defichain-3.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-02 14:36:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eric-volz",
    "github_project": "DefichainPython",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    ">=",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "ecdsa",
            "specs": [
                [
                    ">=",
                    "0.18.0"
                ]
            ]
        },
        {
            "name": "base58",
            "specs": [
                [
                    ">=",
                    "2.1.1"
                ]
            ]
        },
        {
            "name": "pycryptodome",
            "specs": [
                [
                    ">=",
                    "3.18.0"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "defichain"
}
        
Elapsed time: 0.33567s