XChainPy2 is a library of Python packages that provides a common interface for multiple blockchains, built for simple and fast integration for wallets and more. It enables you to interact with THORChain and MayaChain DeFi protocols, as well as other blockchains like Bitcoin, Ethereum, Binance Smart Chain, and more. It is a free-style interpretation of XChainJS.
Documentation is available here: https://xchainpy2.readthedocs.io/en/latest/
The library is divided into several packages. You can only use the ones you need.
Utility helpers for XChainPy2 components. Asset, amount, formatting, math and more.
Keystore management and crypto utilities.
This is a base blockchain client interface. Used by all specific blockchain clients. Each blockchain client allows you to read your balance, query transactions, broadcast your transactions to the network. Normally, you would not use this package directly, but use the specific blockchain client packages.
Client for the THORChain Midgard API. Documentation: https://midgard.ninerealms.com/v2/doc
It is automatically generated from the Swagger specification. Just a basic client with asyncio support, does not contain any special features like retries or fallbacks. Please use the xchainpy_thorchain_query package for a more advanced interface.
Client for the THORNode API. Documentation: https://thornode.ninerealms.com/thorchain/doc
It is automatically generated from the Swagger specification. Just a basic client with asyncio support. Please use the xchainpy_thorchain_query package for a more advanced interface.
Client for the MayaNode API. Documentation: https://mayanode.mayachain.info/mayachain/doc
It is automatically generated from the Swagger specification. Just a basic client with asyncio support.
Cosmos chain client. Based on the xchainpy_client interface.
THORChain client. Based on the xchainpy_cosmos. Supports both native transfer transactions and deposit transactions.
High level interface to Midgard and THORNode/MayaNode. It has many useful features like retry, fallback servers, caching and more. Liquidity math functions are included.
UTXO providers for Bitcoin and other UTXO based chains. Currently, supports Haskoin, Sochain and Blockcypher APIs.
High level interface to THORChain Automated Market Maker (AMM). It includes a wallet class, swap, deposit, withdraw, pool status and more. (Work in progress)
Bitcoin client.
Ethereum client.
Binance Chain client. Deprecated. See: https://www.bnbchain.org/en/blog/bep2-bep8-asset-sunset-announcement
Litecoin client.
Dogecoin client.
Bitcoin Cash client.
Arbitrum client. Based on the xchainpy_ethereum.
Avalanche client. Based on the xchainpy_ethereum.
Binance Smart Chain client. Based on the xchainpy_ethereum.
The project is available on PyPI.
Installation guide can be found in here.
After cloning the repository, you can run the code samples in the ./examples
folder.
First, install the XChainPy2 packages. For example, for running THORChain examples, run the following commands.
python3 -m pip install --editable packages/xchainpy_crypto
python3 -m pip install --editable packages/xchainpy_utils
python3 -m pip install --editable packages/xchainpy_client
python3 -m pip install --editable packages/xchainpy_cosmos
python3 -m pip install --editable packages/xchainpy_thorchain
Or just make tc_env
which does the same thing.
You can install the packages manually from GitHub with the following commands.
Utils:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy2_utils&subdirectory=packages/xchainpy_utils"
Crypto utils:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy2_crypto&subdirectory=packages/xchainpy_crypto"
Base clients:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_client&subdirectory=packages/xchainpy_client"
Cosmos:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_cosmos&subdirectory=packages/xchainpy_cosmos"
THORChain:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_thorchain&subdirectory=packages/xchainpy_thorchain"
THORNode:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_thornode&subdirectory=packages/xchainpy_thornode"
MayaNode:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_mayanode&subdirectory=packages/xchainpy_mayanode"
Midgard:
pip install "git+https://github.com/tirinox/xchainpy.git@develop#egg=xchainpy_mayanode&subdirectory=packages/xchainpy_midgard"
And so on.
First install the dependencies:
make dev_tools
Then run the tests:
make test
Mandatory items.
- MayaProtocol AMM
- ERC20 debugging
- Documentation
- More tests
- Utils package
- Crypto utils package
- Base blockchain client package
- THORChain package
- Cosmos package
- UTXO providers (Haskoin, Sochain, Blockcypher)
- Tests for the Query Package
- Examples for Query Package
- Mayachain client
- Bitcoin client
- Ethereum client
- Other UTXO clients
- Other EVM clients
- Loans
The list goes on.
- MRC20 and M-NFT support
- ERC20 token discovery
- Block-timestamp conversion
- Retry/fallback for the generated Midgard/THORNode clients
- Wait for the tx to be completed
- Utils for DEX aggregators
The list goes on.