BeraChainTools 一个为 BeraChain 生态系统设计的工具集,旨在帮助用户轻松地进行各种交互和操作。
在开始使用 BeraChainTools 之前,请确保安装了所有必要的依赖。
执行以下命令以安装依赖:
pip install -r requirements.txt
- 如果你还没有 YesCaptcha 账号,请先在这里注册:yescaptcha注册链接。
- 如果你还没有 2captcha 账号,请先在这里注册:2captcha注册链接。
Example 1 - 领水:
from eth_account import Account
from loguru import logger
from bera_tools import BeraChainTools
account = Account.create()
logger.debug(f'address:{account.address}')
logger.debug(f'key:{account.key.hex()}')
# TODO 填写你的 YesCaptcha client key 或者2Captcha API Key
client_key = '00000000000000'
# 使用yescaptcha solver googlev3
bera = BeraChainTools(private_key=account.key, client_key=client_key,solver_provider='yescaptcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 使用2captcha solver googlev3
# bera = BeraChainTools(private_key=account.key, client_key=client_key,solver_provider='2captcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 不使用代理
result = bera.claim_bera()
# 使用代理
# result = bera.claim_bera(proxies={'http':"http://127.0.0.1:8888","https":"http://127.0.0.1:8888"})
logger.debug(result.text)
Example 2 - Bex 交互:
from eth_account import Account
from loguru import logger
from bera_tools import BeraChainTools
from config.address_config import (
usdc_pool_address, usdc_address, weth_pool_address, weth_address, bex_approve_liquidity_address,
usdc_pool_liquidity_address, weth_pool_liquidity_address
)
account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')
# bex 使用bera交换usdc
bera_balance = bera.w3.eth.get_balance(account.address)
result = bera.bex_swap(int(bera_balance * 0.2), usdc_pool_address, usdc_address)
logger.debug(result)
# bex 使用bera交换weth
bera_balance = bera.w3.eth.get_balance(account.address)
result = bera.bex_swap(int(bera_balance * 0.3), weth_pool_address, weth_address)
logger.debug(result)
# 授权usdc
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# bex 增加 usdc 流动性
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(usdc_balance * 0.5), usdc_pool_liquidity_address, usdc_address)
logger.debug(result)
# 授权weth
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), weth_address)
logger.debug(approve_result)
# bex 增加 weth 流动性
weth_balance = bera.weth_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(weth_balance * 0.5), weth_pool_liquidity_address, weth_address)
logger.debug(result)
Example 3 - honey 交互:
from eth_account import Account
from loguru import logger
from bera_tools import BeraChainTools
from config.address_config import honey_swap_address, usdc_address, honey_address
account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')
# 授权usdc
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# 使用usdc mint honey
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.honey_mint(int(usdc_balance * 0.5))
logger.debug(result)
# 授权honey
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 赎回
honey_balance = bera.honey_contract.functions.balanceOf(account.address).call()
result = bera.honey_redeem(int(honey_balance * 0.5))
logger.debug(result)
支持创建地址领水或指定地址领水
- 访问链接:BeraChain领水
- 状态:已完成
支持代币交换和增加流动性
- 访问链接:bex交互
- 状态:已完成
支持mint和redeem
- 访问链接:honey交互
- 状态:已完成
用于与 BeraChain 的 bend 服务交互。
- 访问链接:bend交互
- 状态:进行中
用于与 BeraChain 的 berps 服务交互。
- 访问链接:berps交互
- 状态:待完成
用于与 BeraChain 的 station 服务交互。
- 访问链接:station交互
- 状态:待完成
感谢使用 BeraChainTools!如有任何问题或建议,请随时通过 GitHub Issues 提交。