跳转到主要内容

用于与各种加密货币和区块链交互的异步库

项目描述

AioTx

PyPI Downloads Ruff Python Versions OS Support

Bitcoin Litecoin Ethereum Binance Smart Chain Polygon TON TRON

MySQL Test Test Ruff lint check

AioTx是一个全面的Python包,旨在简化并自动化您的加密货币操作。无论您是在使用以太坊虚拟机(EVM)网络,还是像比特币和莱特币这样的基于UTXO网络,或者是TON,AioTx都提供了统一的、用户友好的接口来与这些区块链交互。

我创建了AioTx,因为我想要将我经常使用的所有加密操作整合到一个便捷的包中。目标是收集我经常使用的所有加密客户端,全部在一个地方,具有一致且直观的API。

加入Telegram频道和聊天以获取更新和帮助 https://t.me/aiotx_python https://t.me/aiotx_python_chat

主要功能

  1. EVM客户端: AioTx提供了一个支持以太坊、币安智能链、Polygon、Avalanche、Fantom、Cronos等流行EVM网络的EVM客户端。使用EVM客户端,您可以轻松生成地址、检索余额、发送交易、与智能合约交互以及执行各种其他操作。

  2. UTXO客户端: 针对基于UTXO的网络,如比特币和莱特币,AioTx提供了UTXO客户端。此客户端允许您轻松生成地址、导入地址进行监控、检索余额、估算费用以及发送交易。UTXO客户端还支持批量交易,使您能够一次性发送多个交易。

  3. TON客户端: 适用于Telegram Open Network的客户端 - 现在我们可以监控和发送TON代币,以及批量发送和检查jetton余额。

  4. TRON客户端: 适用于TRON (trx) 区块链的客户端 - 您可以监控交易并执行TRX/TRC20交易。

  5. 区块链监控: AioTx的突出功能之一是其区块链监控能力。您可以通过注册自定义处理程序轻松监控支持区块链上的新块和交易。AioTx提供了一种简单直观的方式来开始和停止监控,甚至允许您同时监控多个客户端。还支持与Aiogram库的集成,使您可以根据接收到的块和交易发送通知或执行操作。

  6. 数据库存储: AioTx内置了对数据库存储的支持,允许您高效监控和管理存储交易和UTXO数据。您可以选择SQLite和MySQL作为数据库后端,这两种数据库都已经过彻底测试,并且与AioTx无缝协作。

  7. 测试: 为了确保AioTx的可靠性和稳定性,该包经过广泛测试。测试套件包括针对各种场景、网络和操作的全面测试用例。AioTx利用VCR(视频磁带记录器)库记录和回放网络交互,使测试确定性和独立于外部服务。

获取节点URL

出于测试目的,您可以使用公共节点,但出于生产目的,最好获取一个私有节点或至少是共享节点。您可以在Get Block(https://account.getblock.io/sign-in?ref=NWUzNjUzNjktY2EzMy01YzI3LWFlZDUtZjYzYmM1OWU0NmFk)或Quick Node(https://www.quicknode.com/?via=aiotx)等平台上免费获取。

通过使用这些推荐URL,您将支持该项目,我将非常感激您的贡献。

入门指南

要开始使用AioTx,只需使用pip安装该包

在Ubuntu或其他Linux操作系统上,您可能需要安装libgmp才能开始

sudo apt-get install libgmp-dev

一些客户端需要子依赖项,如果您只想使用TON,例如,您可能不需要BTC/ETH的子依赖项。因此,它们被划分为附加组件。

要使用TON,请使用

pip install aiotx

要使用BTC/LTC(UTXO),请使用

pip install aiotx[utxo]

要使用ETH/MATIC/BSC/TRON(EVM),请使用

pip install aiotx[evm]

或全部使用

pip install aiotx[utxo,evm]

安装完成后,您可以导入所需的客户端并开始与相应的区块链交互。以下是一个使用EVM客户端的快速示例

发送批量交易(比特币)

from aiotx.clients import AioTxBTCClient

async def main():
    btc_client = AioTxBTCClient("NODE_URL")
    
    destinations = {
        "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 1000000,
        "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2": 500000
    }
    
    private_key = "YOUR_PRIVATE_KEY"
    txid = await btc_client.send_bulk(private_key, destinations)
    print(f"Transaction ID: {txid}")

asyncio.run(main())

发送代币(以太坊)

from aiotx.clients import AioTxETHClient

async def main():
    eth_client = AioTxETHClient("NODE_URL")
    
    private_key = "YOUR_PRIVATE_KEY"
    to_address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
    token_address = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"  # Example token address (Uniswap)
    amount = eth_client.to_wei(10, "ether")  # Sending 10 tokens
    
    tx_hash = await eth_client.send_token(private_key, to_address, token_address, amount)
    print(f"Transaction Hash: {tx_hash}")

asyncio.run(main())

发送TON(批量请查看/examples

    from aiotx.clients import AioTxTONClient
    import asyncio

    ton_client = AioTxTONClient("https://testnet.toncenter.com/api/v2", workchain=0)
    # We are adding workchain here because testnet.toncenter working bad and identify itself as -1 but it should be 0
    # If you are using any other provider it should work fine without workchain param

    amount = ton_client.to_nano(0.0001)
    mnemonic_str = "post web slim candy example glimpse other reduce layer way ordinary hidden dwarf marble fancy gym client soul speed enforce drift huge upset oblige"

    balance = asyncio.run(ton_client.get_balance("UQDU1hdX6SeHmrvzvyjIrLEWUAdJUJar2sw8haIuT_5n-FLh"))

    tx_id = asyncio.run(ton_client.send(mnemonic_str, "0QAEhA1CupMp7uMOUfHHoh7sqAMNu1xQOydf8fQf-ATpkbpT", amount))
    print(tx_id)

    

转移jetton

    from aiotx.clients import AioTxTONClient
    import asyncio

    ton_client = AioTxTONClient("https://testnet.toncenter.com/api/v2", workchain=0)

    mnemonic_str = "your wallet mnemonic phrase here"
    recipient_address = "EQCc39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2e"
    jetton_master_address = "EQAiboDEv_qRrcEdrYdwbVLNOXBHwShFbtKGbQVJ2OKxY_Di"
    amount = 1000000000  # 1 Jetton (assuming 9 decimal places)
    memo = "Payment for services"

    tx_hash = asyncio.run(ton_client.transfer_jettons(
        mnemonic_str,
        recipient_address,
        jetton_master_address,
        amount,
        memo
    ))
    print(f"Jetton transfer transaction hash: {tx_hash}")
    

发送原生货币(以太坊)

from aiotx.clients import AioTxETHClient

async def main():
    eth_client = AioTxETHClient("NODE_URL")
    
    private_key = "YOUR_PRIVATE_KEY"
    to_address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
    amount = eth_client.to_wei(0.5, "ether")  # Sending 0.5 ETH
    
    tx_hash = await eth_client.send(private_key, to_address, amount)
    print(f"Transaction Hash: {tx_hash}")

asyncio.run(main())

发送原生货币(比特币)

from aiotx.clients import AioTxBTCClient

async def main():
    btc_client = AioTxBTCClient("NODE_URL")
    
    private_key = "YOUR_PRIVATE_KEY"
    to_address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
    amount = 1000000  # Sending 0.01 BTC (amount is in satoshis)
    
    txid = await btc_client.send(private_key, to_address, amount)
    print(f"Transaction ID: {txid}")

asyncio.run(main())

Satoshi转换

from aiotx.clients import AioTxBTCClient

async def main():
    btc_client = AioTxBTCClient("NODE_URL")
    
    # Converting satoshis to BTC
    satoshis = 1000000
    btc = btc_client.from_satoshi(satoshis)
    print(f"{satoshis} satoshis = {btc} BTC")
    
    # Converting BTC to satoshis
    btc = 0.01
    satoshis = btc_client.to_satoshi(btc)
    print(f"{btc} BTC = {satoshis} satoshis")

asyncio.run(main())

这些示例展示了使用AioTx进行各种加密货币操作时的简单性和灵活性。无论您是发送批量交易、发送代币、发送原生货币还是在不同单位之间进行转换,AioTx都提供了一致且直观的API来与不同的区块链进行交互。

有关更详细的用法说明和示例,请参阅每个客户端和功能的文档。

希望您觉得AioTx很有用,并享受用它进行加密操作。如果您有任何问题、反馈或建议,请随时联系我们。祝您编码愉快!

有关更详细的用法示例和API参考,请参阅文档。

https://grommash9.github.io/aiotx/

贡献

AioTx欢迎贡献!如果您发现任何错误,有功能请求或想贡献改进,请在该GitHub仓库中提交问题或拉取请求。

许可

AioTx是开源软件,使用MIT许可证。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

aiotx-4.10.0.tar.gz (1.6 MB 查看哈希)

上传时间

构建分发

aiotx-4.10.0-py3-none-any.whl (75.0 kB 查看哈希)

上传时间 Python 3

支持者