Bankless Onchain
ทางการสอบถามข้อมูล Onchain เช่น ERC20 tokens, ประวัติธุรกรรม, สถานะ smart contract
คุณทำอะไรได้บ้างด้วย Bankless Onchain MCP?
- อ่านสถานะสัญญาแบบเรียลไทม์ — เรียกใช้เมธอด read ใดๆ บนสัญญาที่ได้รับการยืนยันข้ามเครือข่ายที่รองรับโดยใช้
read_contract - แก้ไขการใช้งาน proxy — ดึงที่อยู่ implementation ที่อยู่เบื้องหลังสัญญา proxy ด้วย
get_proxy - ดึง ABI และซอร์สโค้ดของสัญญา — รับ ABI เต็มผ่าน
get_abiหรือซอร์สโค้ดและข้อมูลเมตาที่ได้รับการยืนยันผ่านget_source - สอบถามเหตุการณ์ในอดีต — ดึงบันทึกเหตุการณ์ที่กรองแล้วสำหรับที่อยู่สัญญาหนึ่งรายการขึ้นไปโดยใช้
get_events - สร้างแฮชหัวข้อเหตุการณ์ — สร้างหัวข้อเหตุการณ์ keccak256 จากชื่อเหตุการณ์และประเภทอาร์กิวเมนต์ด้วย
build_event_topic - ตรวจสอบประวัติและรายละเอียดธุรกรรม — แสดงรายการธุรกรรมที่ผ่านมาสำหรับที่อยู่ด้วย
get_transaction_historyหรือค้นหาธุรกรรมเฉพาะด้วยget_transaction_info
เอกสาร
Bankless Onchain MCP Server
โปรเจกต์นี้ไม่ได้รับการอัปเดตอีกต่อไป
เซิร์ฟเวอร์ MCP (Model Context Protocol) สำหรับการโต้ตอบข้อมูลบล็อกเชนผ่าน Bankless API
ภาพรวม
Bankless Onchain MCP Server มอบเฟรมเวิร์กสำหรับการโต้ตอบกับข้อมูลบนเชนผ่าน Bankless API โดยนำ Model Context Protocol (MCP) มาใช้เพื่อให้โมเดล AI สามารถเข้าถึงสถานะบล็อกเชนและข้อมูลเหตุการณ์ในรูปแบบที่มีโครงสร้าง
https://github.com/user-attachments/assets/95732dff-ae5f-45a6-928a-1ae17c0ddf9d
ฟีเจอร์
เซิร์ฟเวอร์มีการดำเนินการข้อมูลบนเชนดังต่อไปนี้:
การดำเนินการเกี่ยวกับคอนแทร็กต์
-
อ่านสถานะคอนแทร็กต์ (
read_contract): อ่านสถานะจากสมาร์ทคอนแทร็กต์บนเครือข่ายบล็อกเชนต่างๆ- พารามิเตอร์: network, contract address, method, inputs, outputs
- ส่งคืน: ผลลัพธ์การเรียกคอนแทร็กต์พร้อมค่าที่มีชนิดข้อมูล
-
รับพร็อกซี (
get_proxy): เรียกดูที่อยู่คอนแทร็กต์การนำไปใช้ของพร็อกซี- พารามิเตอร์: network, contract address
- ส่งคืน: ที่อยู่คอนแทร็กต์การนำไปใช้
-
รับ ABI (
get_abi): ดึงข้อมูล ABI (Application Binary Interface) สำหรับคอนแทร็กต์- พารามิเตอร์: network, contract address
- ส่งคืน: ABI ของคอนแทร็กต์ในรูปแบบ JSON
-
รับซอร์สโค้ด (
get_source): เรียกดูซอร์สโค้ดสำหรับคอนแทร็กต์ที่ผ่านการตรวจสอบแล้ว- พารามิเตอร์: network, contract address
- ส่งคืน: ซอร์สโค้ด, ABI, เวอร์ชันคอมไพเลอร์ และเมทาดาทาอื่นๆ ของคอนแทร็กต์
การดำเนินการเกี่ยวกับเหตุการณ์
-
รับเหตุการณ์ (
get_events): ดึงข้อมูลบันทึกเหตุการณ์สำหรับคอนแทร็กต์ตามหัวข้อ- พารามิเตอร์: network, addresses, topic, optional topics
- ส่งคืน: บันทึกเหตุการณ์ที่กรองแล้ว
-
สร้างหัวข้อเหตุการณ์ (
build_event_topic): สร้างลายเซ็นหัวข้อเหตุการณ์จากชื่อเหตุการณ์และชนิดอาร์กิวเมนต์- พารามิเตอร์: network, event name, argument types
- ส่งคืน: แฮชหัวข้อเหตุการณ์
การดำเนินการเกี่ยวกับธุรกรรม
-
รับประวัติธุรกรรม (
get_transaction_history): เรียกดูประวัติธุรกรรมสำหรับที่อยู่ผู้ใช้- พารามิเตอร์: network, user address, optional contract, optional method ID, optional start block, include data flag
- ส่งคืน: รายการธุรกรรมพร้อมแฮช, ข้อมูล, เครือข่าย และเวลาประทับ
-
รับข้อมูลธุรกรรม (
get_transaction_info): รับข้อมูลรายละเอียดเกี่ยวกับธุรกรรมที่ระบุ- พารามิเตอร์: network, transaction hash
- ส่งคืน: รายละเอียดธุรกรรมรวมถึงหมายเลขบล็อก, เวลาประทับ, ที่อยู่จาก/ถึง, มูลค่า, ข้อมูลแก๊ส, สถานะ และข้อมูลใบเสร็จ
เครื่องมือ
-
read_contract
- อ่านสถานะคอนแทร็กต์จากบล็อกเชน
- อินพุต:
network(string, required): เครือข่ายบล็อกเชน (เช่น "ethereum", "polygon")contract(string, required): ที่อยู่คอนแทร็กต์method(string, required): เมธอดของคอนแทร็กต์ที่จะเรียกinputs(array, required): พารามิเตอร์อินพุตสำหรับการเรียกเมธอด แต่ละรายการประกอบด้วย:type(string): ชนิดของพารามิเตอร์อินพุต (เช่น "address", "uint256")value(any): ค่าของพารามิเตอร์อินพุต
outputs(array, required): ชนิดเอาต์พุตที่คาดหวัง แต่ละรายการประกอบด้วย:type(string): ชนิดเอาต์พุตที่คาดหวัง
- ส่งคืนอาร์เรย์ของผลลัพธ์การเรียกคอนแทร็กต์
-
get_proxy
- รับที่อยู่พร็อกซีสำหรับเครือข่ายและคอนแทร็กต์ที่กำหนด
- อินพุต:
network(string, required): เครือข่ายบล็อกเชน (เช่น "ethereum", "base")contract(string, required): ที่อยู่คอนแทร็กต์
- ส่งคืนที่อยู่การนำไปใช้สำหรับคอนแทร็กต์พร็อกซี
-
get_events
- ดึงข้อมูลบันทึกเหตุการณ์สำหรับเครือข่ายและเกณฑ์การกรองที่กำหนด
- อินพุต:
network(string, required): เครือข่ายบล็อกเชน (เช่น "ethereum", "base")addresses(array, required): รายการที่อยู่คอนแทร็กต์เพื่อกรองเหตุการณ์topic(string, required): หัวข้อหลักเพื่อกรองเหตุการณ์optionalTopics(array, optional): หัวข้อเพิ่มเติมที่เป็นทางเลือก (สามารถรวมค่า null ได้)
- ส่งคืนออบเจ็กต์ที่มีบันทึกเหตุการณ์ที่ตรงกับเกณฑ์การกรอง
-
build_event_topic
- สร้างลายเซ็นหัวข้อเหตุการณ์ตามชื่อเหตุการณ์และอาร์กิวเมนต์
- อินพุต:
network(string, required): เครือข่ายบล็อกเชน (เช่น "ethereum", "base")name(string, required): ชื่อเหตุการณ์ (เช่น "Transfer(address,address,uint256)")arguments(array, required): ชนิดอาร์กิวเมนต์ของเหตุการณ์ แต่ละรายการประกอบด้วย:type(string): ชนิดอาร์กิวเมนต์ (เช่น "address", "uint256")
- ส่งคืนสตริงที่มีแฮช keccak256 ของลายเซ็นเหตุการณ์
การติดตั้ง
npm install @bankless/onchain-mcp
การใช้งาน
การตั้งค่าสภาพแวดล้อม
ก่อนใช้เซิร์ฟเวอร์ ให้ตั้งค่าโทเค็น Bankless API ของคุณ สำหรับรายละเอียดเกี่ยวกับวิธีรับโทเค็น Bankless API ของคุณ ไปที่ https://docs.bankless.com/bankless-api/other-services/onchain-mcp
export BANKLESS_API_TOKEN=your_api_token_here
การรันเซิร์ฟเวอร์
เซิร์ฟเวอร์สามารถรันได้โดยตรงจากบรรทัดคำสั่ง:
npx @bankless/onchain-mcp
การใช้งานกับเครื่องมือ LLM
เซิร์ฟเวอร์นี้ใช้ Model Context Protocol (MCP) ซึ่งช่วยให้สามารถใช้เป็นผู้ให้บริการเครื่องมือสำหรับโมเดล AI ที่เข้ากันได้ นี่คือตัวอย่างการเรียกสำหรับแต่ละเครื่องมือ:
read_contract
// Example call
{
"name": "read_contract",
"arguments": {
"network": "ethereum",
"contract": "0x1234...",
"method": "balanceOf",
"inputs": [
{ "type": "address", "value": "0xabcd..." }
],
"outputs": [
{ "type": "uint256" }
]
}
}
// Example response
[
{
"value": "1000000000000000000",
"type": "uint256"
}
]
get_proxy
// Example call
{
"name": "get_proxy",
"arguments": {
"network": "ethereum",
"contract": "0x1234..."
}
}
// Example response
{
"implementation": "0xefgh..."
}
get_events
// Example call
{
"name": "get_events",
"arguments": {
"network": "ethereum",
"addresses": ["0x1234..."],
"topic": "0xabcd...",
"optionalTopics": ["0xef01...", null]
}
}
// Example response
{
"result": [
{
"removed": false,
"logIndex": 5,
"transactionIndex": 2,
"transactionHash": "0x123...",
"blockHash": "0xabc...",
"blockNumber": 12345678,
"address": "0x1234...",
"data": "0x...",
"topics": ["0xabcd...", "0xef01...", "0x..."]
}
]
}
build_event_topic
// Example call
{
"name": "build_event_topic",
"arguments": {
"network": "ethereum",
"name": "Transfer(address,address,uint256)",
"arguments": [
{ "type": "address" },
{ "type": "address" },
{ "type": "uint256" }
]
}
}
// Example response
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
การพัฒนา
การสร้างจากซอร์สโค้ด
# Clone the repository
git clone https://github.com/Bankless/onchain-mcp.git
cd onchain-mcp
# Install dependencies
npm install
# Build the project
npm run build
โหมดดีบัก
npm run debug
การผสานรวมกับโมเดล AI
เพื่อผสานรวมเซิร์ฟเวอร์นี้กับแอปพลิเคชัน AI ที่รองรับ MCP ให้เพิ่มสิ่งต่อไปนี้ในการกำหนดค่าเซิร์ฟเวอร์ของแอปของคุณ:
{
"mcpServers": {
"bankless": {
"command": "npx",
"args": [
"@bankless/onchain-mcp"
],
"env": {
"BANKLESS_API_TOKEN": "your_api_token_here"
}
}
}
}
การจัดการข้อผิดพลาด
เซิร์ฟเวอร์มีชนิดข้อผิดพลาดเฉพาะสำหรับสถานการณ์ต่างๆ:
BanklessValidationError: พารามิเตอร์อินพุตไม่ถูกต้องBanklessAuthenticationError: ปัญหาโทเค็น APIBanklessResourceNotFoundError: ไม่พบทรัพยากรที่ร้องขอBanklessRateLimitError: เกินขีดจำกัดอัตรา API
เคล็ดลับการพร้อมต์
เพื่อแนะนำโมเดล LLM ให้ใช้ Bankless Onchain MCP Server สามารถใช้พร้อมต์ต่อไปนี้:
ROLE:
• You are Kompanion, a blockchain expert and EVM sleuth.
• You specialize in navigating and analyzing smart contracts using your tools and resources.
HOW KOMPANION CAN HANDLE PROXY CONTRACTS:
• If a contract is a proxy, call your “get_proxy” tool to fetch the implementation contract.
• If that fails, try calling the “implementation” method on the proxy contract.
• If that also fails, try calling the “_implementation” function.
• After obtaining the implementation address, call “get_contract_source” with that address to fetch its source code.
• When reading or modifying the contract state, invoke implementation functions on the proxy contract address (not directly on the implementation).
HOW KOMPANION CAN HANDLE EVENTS:
• Get the ABI and Source of the relevant contracts
• From the event types in the ABI, construct the correct topics for the event relevant to the question
• use the "get_event_logs" tool to fetch logs for the contract
KOMPANION'S RULES:
• Do not begin any response with “Great,” “Certainly,” “Okay,” or “Sure.”
• Maintain a direct, technical style. Do not add conversational flourishes.
• If the user’s question is unrelated to smart contracts, do not fetch any contracts.
• If you navigate contracts, explain each step in bullet points.
• Solve tasks iteratively, breaking them into steps.
• Use bullet points for lists of steps.
• Never assume a contract’s functionality. Always verify with examples using your tools to read the contract state.
• Before responding, consider which tools might help you gather better information.
• Include as much relevant information as possible in your final answer, depending on your findings.
HOW KOMPANION CAN USE TOOLS:
• You can fetch contract source codes, ABIs, and read contract data by using your tools and functions.
• Always verify the source or ABI to understand the contract rather than making assumptions.
• If you need to read contract state, fetch its ABI (especially if the source is lengthy).
FINAL INSTRUCTION:
• Provide the best possible, concise answer to the user’s request. If it's not an immediate question but an instruction, follow it directly.
• Use your tools to gather any necessary clarifications or data.
• Offer a clear, direct response and add a summary of what you did (how you navigated the contracts) at the end.
ใบอนุญาต
MIT