Langchain extension for BNB Chain
Project description
BNB-chain-agentkit
This is a Langchain extension for BNB Chain.
This toolkit equips LLM agents with the ability to interact with BNB Chain and execute on-chain operations, including getting balances, transferring tokens, swapping tokens, staking, bridging, and deploying different types of ERC tokens.
Setup
Prerequisites
- Python 3.12+
Installation
pip install bnb-chain-agentkit
Environment Variables
cp .env.example .env
PRIVATE_KEY: Your private key for the BNB Chain account.BSC_PROVIDER_URL: The URL of the BNB Smart Chain provider.OPBNB_PROVIDER_URL: The URL of the Optimism BNB Smart Chain provider.
You can set your own RPC endpoint or use a public one listed here: https://docs.bnbchain.org/bnb-smart-chain/developers/json_rpc/json-rpc-endpoint/
Usage
Basic Setup
from bnb_chain_agentkit.agent_toolkits import BnbChainToolkit
from bnb_chain_agentkit.utils import BnbChainAPIWrapper
# Configure BNB Chain Langchain Extension.
bnb_chain = BnbChainAPIWrapper()
# Initialize BNB Chain Toolkit and get tools.
bnb_chain_toolkit = BnbChainToolkit.from_bnb_chain_api_wrapper(bnb_chain)
View available tools:
tools = bnb_chain_toolkit.get_tools()
print('Supported tools:')
for tool in tools:
print(tool.name)
The toolkit provides the following tools:
- get_balance - Get balance for a specific token of given account
- transfer - Transfer tokens to a specific address
- faucet - Request test tokens from faucet
- swap - Swap tokens on PancakeSwap
- stake - Stake BNB to ListaDao
- bridge - Bridge tokens between BSC and opBNB
- deploy - Deploy a new ERC20/ERC7721/ERC1155 token
Using with an Agent
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
# Initialize LLM
llm = ChatOpenAI(model="gpt-4o-mini")
# Get tools and create agent
tools = bnb_chain_toolkit.get_tools()
agent_executor = create_react_agent(llm, tools)
# Example usage
events = agent_executor.stream(
{"messages": [("user", "Check BNB balance of 0x1234")]},
stream_mode="values"
)
for event in events:
event["messages"][-1].pretty_print()
Expected output:
================================ Human Message =================================
Check my BNB balance
================================== Ai Message ==================================
Tool Calls:
get_balance (call_w4HfhOLX9d5lH7emf1QKQCF4)
Call ID: call_w4HfhOLX9d5lH7emf1QKQCF4
Args:
account: 0x1234
token: BNB
================================= Tool Message =================================
Name: get_balance
Balances for account 0x1234 of BNB:
6145615640500000000 (decimals: 18)
================================== Ai Message ==================================
Your BNB balance is 6.1456156405 BNB.
Please refer to examples/chatbot for more detailed usage.
Credits
Special thanks to CDP (Coinbase Developer Platform). The architecture and implementation patterns of this toolkit were inspired by their excellent work in building AI agent.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bnb_chain_agentkit-0.0.2.tar.gz.
File metadata
- Download URL: bnb_chain_agentkit-0.0.2.tar.gz
- Upload date:
- Size: 135.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc494b9ca76e09293b035c98304e9f716b469eb879ba1f110fbacc25bde7fbd2
|
|
| MD5 |
b59af6662df7a1458b2b62c2906dca24
|
|
| BLAKE2b-256 |
5ad737142b08083003b8b71e4ae38231c5cbb53e70faceb63d55503838960370
|
File details
Details for the file bnb_chain_agentkit-0.0.2-py3-none-any.whl.
File metadata
- Download URL: bnb_chain_agentkit-0.0.2-py3-none-any.whl
- Upload date:
- Size: 82.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa85f970610a32f13d3f21bb9bd0d3ea2caad153b77ab3919f82481a75a5874a
|
|
| MD5 |
a935952626c4cd1848824188f38c87eb
|
|
| BLAKE2b-256 |
2514dbba66de85e765420eb5cd7b11bcf6e1c71b1638e1995694ad501f6ec82a
|