LangChain പേയ്മെന്റ് ഇന്റഗ്രേഷൻ.
ഏതെങ്കിലും LangChain ഏജന്റിന് USDC പണമടച്ചുകൾ ചേർക്കുക. യഥാർത്ഥ Python പാക്കേജ് അതിന് വാലറ്റ് ഉപകരണങ്ങൾ നൽകുന്നു - അയക്കുക, സമാധാനിപ്പിക്കുക, വായിക്കുക - കുറച്ച് വരികളിൽ.
Blockchain0x ഒരു യഥാർത്ഥ Python package, , നൽകുന്നു; ഇത് ഒരു LangChain agent-ന് native wallet tools നൽകുന്നു: Base-ൽ USDC അയയ്ക്കുക, on-chain proof ഉപയോഗിച്ച് invoice settle ചെയ്യുക, wallets, transactions എന്നിവ വായിക്കുക. ഇത് install ചെയ്യുക, സജ്ജീകരിക്കുക, വിളിക്കുക, തുടർന്ന് tools നിങ്ങളുടെ agent-ന് നൽകുക. TypeScript-ൽ ആണോ? npm adapter ഇല്ല - x402 client-നെ ഒരു LangChain.js tool-ൽ wrap ചെയ്യുക.
Blockchain0x HTTP API യുടെ മുകളിൽ ഒരു തരം പാളി.
blockchain0x-langchain-ൽ ഓരോ ഉപകരണം ഔദ്യോഗിക blockchain0x കോർ SDK-യുടെ ഒരു തൂവലാണ്. പുനർനിർമ്മിത REST അല്ലെങ്കിൽ x402 ലാജിക് ഇല്ല, കീ കസ്റ്റഡി ഇല്ല: അഡാപ്റ്റർ നിങ്ങളുടെ API കീ ബാക്ക് എൻഡിലേക്ക് മുന്നോട്ട് അയക്കുന്നു, അതിന്റെ സ്വന്തം രഹസ്യം കൈവശം വയ്ക്കുന്നില്ല. create_blockchain0x_toolset(client) LangChain-ന് അഞ്ച് ഉപകരണങ്ങൾ കൈമാറുന്നു - പണമടച്ചയയിക്കുക, ഒരു ഇൻവോയിസ് തീർപ്പാക്കുക, ഒരു വാലറ്റ് വായിക്കുക, വാലറ്റുകൾ ലിസ്റ്റ് ചെയ്യുക, ഒരു ഇടപാട് വായിക്കുക - ഓരോന്നും ഇതിനകം ടൈപ്പ് ചെയ്തും സ്കോപ്പ് ചെയ്തും ഉണ്ട്.
നിങ്ങൾക്ക് ഇഷ്ടമുള്ളെങ്കിൽ, കച്ചവട API അല്ലെങ്കിൽ കോർ SDK നേരിട്ട് വിളിക്കാം. അഡാപ്റ്റർ കുറഞ്ഞ പ്രതിരോധത്തിന്റെ പാതയാണ്; API കരാറാണ്. blockchain0x-langchain-നെ അത് പിന്തുണയ്ക്കുന്ന langchain-core പരിധിയിലേക്ക് പിന്വലിക്കുക, ഇരുവരുടെയും ഏറ്റവും പുതിയവയെ പിന്തുടരുന്നതിന് പകരം.
ഒരു ഇൻസ്റ്റാൾ. ഒരു പരിസ്ഥിതി വ്യത്യാസം. തയ്യാറാണ്.
പാക്കേജിന് Python 3.9 അല്ലെങ്കിൽ പുതിയതും ആവശ്യമാണ്. ഇത് പ്രധാന blockchain0x SDK, langchain-core എന്നിവയെ ആശ്രയിക്കുന്നു; മറ്റൊന്നും ചേർക്കേണ്ടതില്ല.
pip install blockchain0x-langchainexport BLOCKCHAIN0X_API_KEY=sk_test_... # sk_test_ = Base Sepolia, sk_live_ = Base mainnet
BLOCKCHAIN0X_API_KEY നിങ്ങളുടെ Blockchain0x dashboard-ലുള്ള sk_test_ testnet അല്ലെങ്കിൽ sk_live_ mainnet കീ ആണ്. adapter-ിന് ആവശ്യമായ ഏക variable അതാണ്; അത് key backend-ലേക്ക് forward ചെയ്യുന്നു, സ്വതന്ത്ര secret ഒന്നും സൂക്ഷിക്കുന്നില്ല. താഴെ കാണിച്ചിരിക്കുന്ന webhook handler-ിന് നിങ്ങൾ BLOCKCHAIN0X_WEBHOOK_SECRET കൂടി set ചെയ്യണം, ഇത് ഒരു webhook create ചെയ്യുമ്പോഴോ rotate ചെയ്യുമ്പോഴോ dashboard ഒരിക്കൽ return ചെയ്യും.
പണമടയ്ക്കലിന് പിന്തുണയുള്ള ഒരു പ്രവർത്തനശീലമായ LangChain ഏജന്റ്.
താഴെ ഒരു പൂർണ്ണമായ LangChain ഏജന്റ് Python-ൽ ആണ്. create_blockchain0x_toolset വാലറ്റ് ഉപകരണങ്ങൾ തിരികെ നൽകുന്നു, create_react_agent അവയെ ReAct ലൂപ്പിലേക്ക് ബന്ധിപ്പിക്കുന്നു, മോഡൽ പ്രോംപ്റ്റിൽ നിന്ന് ശരിയായ ഉപകരണം തിരഞ്ഞെടുക്കുന്നു. BLOCKCHAIN0X_API_KEY ക്രമീകരിക്കുക, പ്രവർത്തിപ്പിക്കുക, ഏജന്റ് Base-ൽ USDC കൈമാറാനും വായിക്കാനും കഴിയും.
from blockchain0x import Client from blockchain0x_langchain import create_blockchain0x_toolset from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent client = Client() # reads BLOCKCHAIN0X_API_KEY from the environment tools = create_blockchain0x_toolset(client) llm = ChatOpenAI(model="gpt-4o") agent = create_react_agent(llm, tools) result = agent.invoke({ "messages": [{ "role": "user", "content": "Pay 0.01 USDC from my agent to 0xRecipient for the dataset.", }], })
Run it with the prompt above and the model picks the send-payment tool, the SDK submits the transfer on Base, and you get a transaction hash back. amount_wei is USDC base units (6 decimals), so 0.01 USDC is the string "10000". A sk_test_ key keeps you on Base Sepolia until you switch to sk_live_. Heads up: payments.create can answer 503 until the chain adapter is wired for your network.
ഉപയോക്താവ് പണം നൽകുന്നതിന് ശേഷം എന്താണ് സംഭവിക്കുന്നത്.
നിങ്ങളുടെ ഏജന്റിന്റെ വെബ്ഹുക്ക് URL (Blockchain0x ഡാഷ്ബോർഡിൽ സജ്ജീകരിച്ച) ഒരു പേയ്മെന്റ് തീരുമ്പോൾ ഒരു POST സ്വീകരിക്കുന്നു. വെബ്ഹുക്ക് സ്ഥിരീകരണ സഹായി Node SDK-യിൽ ആണ്, അതിനാൽ നിങ്ങളുടെ ഏജന്റ് പൈതൺ ആണെങ്കിലും ഈ ഹാൻഡ്ലർ TypeScript ആണ്. ഒപ്പം സിഗ്നേച്ചർ പരിശോധിക്കുന്ന ഒരു എക്സ്പ്രസ് ഹാൻഡ്ലർ ആണ്, പേയ്ഡ് ജോലികൾ പ്രവർത്തിക്കുന്നു. ഏതെങ്കിലും HTTP ഫ്രെയിംവർക്കിൽ ഒരേ പാറ്റേൺ ഉപയോഗിക്കുക.
import express from "express"; import { webhooks } from "@blockchain0x/node"; const app = express(); // Capture the RAW body. The HMAC is over the exact bytes on the wire. app.use(express.raw({ type: "application/json" })); app.post("/webhooks/payment", (req, res) => { const result = webhooks.verify({ headers: req.headers, rawBody: req.body, // Buffer, raw bytes secret: process.env.BLOCKCHAIN0X_WEBHOOK_SECRET!, }); if (!result.ok) return res.status(400).json({ code: result.code }); if (result.eventType === "payment.received") { // USDC landed in your agent wallet - do the paid work } res.status(200).send("ok"); });
webhooks.verify സ്ഥിരമായ സമയത്തിൽ HMAC-SHA256 നടത്തുകയും discriminated union തിരികെ നൽകുകയും ചെയ്യുന്നു, അതിനാൽ try/catch ഇല്ലാതെ result.ok പ്രകാരം branch ചെയ്ത് result.eventType വായിക്കാം. raw body തന്നെ വായിക്കുക, parsed copy അല്ല: parse ചെയ്ത് വീണ്ടും serialize ചെയ്യുന്നത് signature തകർക്കും. നൽകിയിരിക്കുന്ന events payment.received, payment.sent, wallet.deployed, webhook.test എന്നിവയാണ്; നിങ്ങളുടെ agent-ലേക്ക് വരുന്ന inbound charge payment.received ആണ്.
npm LangChain അഡാപ്റ്റർ ഇല്ല. ഇവിടെ സത്യസന്ധമായ റെസിപ്പി ആണ്.
അയച്ച LangChain അഡാപ്റ്റർ Python മാത്രം ആണ്. npm-ൽ LangChain അഡാപ്റ്റർ ഇല്ല. TypeScript LangChain അല്ലെങ്കിൽ LangGraph ഏജന്റിന്, നിങ്ങൾ യഥാർത്ഥ x402 ക്ലയന്റിനെ LangChain.js ഉപകരണത്തിൽ നിങ്ങൾ തന്നെ മൂടുന്നു. ഇത് കുറച്ച് വരികളാണ്, കൂടാതെ ഇത് ഒരു സമർപ്പിത അഡാപ്റ്റർ അടിക്കടിയിൽ ചെയ്യേണ്ടതായിരുന്നു.
import { createClient } from "@blockchain0x/node"; import { createX402Client } from "@blockchain0x/x402/client"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; const sdk = createClient({ apiKey: process.env.BLOCKCHAIN0X_API_KEY! }); const fetchWithPay = createX402Client({ sdk }); // There is no npm LangChain adapter. Wrap the x402 client in a LangChain.js tool. export const payAndFetch = tool( async ({ url }) => (await fetchWithPay(url)).text(), { name: "pay_and_fetch", description: "Fetch a URL, answering any x402 payment challenge automatically", schema: z.object({ url: z.string().url() }), }, );
Source ഉം testnet examples ഉം the Python SDK repo ൽ ലഭ്യമാണ്; SDK support matrix the docs ൽ ആണ്. Python smoke example LangChain tool wrap ചെയ്യുന്ന അതേ send-payment action വഴി Base Sepolia-യിൽ ഒരു യഥാർത്ഥ $0.01 USDC transfer അയയ്ക്കുന്നു.
ആദ്യ ഇന്റഗ്രേഷനിൽ കടിക്കാനുള്ള അഞ്ചു കാര്യങ്ങൾ.
ഇവ നമ്മുടെ പിന്തുണ ഇൻബോക്സിൽ നിന്നാണ്. ഇവയിൽ ഒന്നും ഇടപാടുകൾ തകരാൻ കാരണമല്ല, പക്ഷേ അവയെ മുൻകൂട്ടി അറിയുന്നത് ഓരോന്നിനും ഒരു മണിക്കൂർ തലച്ചോറിന്റെ കുഴപ്പങ്ങൾ സംരക്ഷിക്കുന്നു.
അളവുകൾ USDC അടിസ്ഥാന യൂണിറ്റുകൾ, സ്ട്രിംഗുകളായി
The payment tools take amount_wei: a string of USDC base units, not a float and not a dollar figure. USDC has 6 decimals, so 0.01 USDC is "10000" and 5 USDC is "5000000". Always pass a string; large integers lose precision as JSON numbers. Send "5.00" and you will either get a validation error or move a millionth of what you meant.
ഇൻവോയ്സ് ഉപകരണം നിശ്ചയിക്കുന്നു, അത് സൃഷ്ടിക്കുന്നില്ല
blockchain0x_settle_invoice ഒരു EXISTING payment request on-chain proof സഹിതം settle ചെയ്യുന്നു. പുതിയ invoice അല്ലെങ്കിൽ hosted checkout link ഉണ്ടാക്കുന്ന tool ഒന്നുമില്ല: payment requests dashboard-ൽ സൃഷ്ടിക്കപ്പെടുന്നു, core SDK settlement മാത്രം expose ചെയ്യുന്നു. agent on the fly ഒരു payable link ഉണ്ടാക്കുമെന്ന് നിങ്ങൾ പ്രതീക്ഷിച്ചുവെങ്കിൽ, അത് ഈ രൂപമല്ല. request out of band സൃഷ്ടിച്ച്, തുടർന്ന് agent-നെ അത് settle ചെയ്യാൻ അനുവദിക്കുക.
വെബ്ഹുക്കുകൾ കച്ചവട ബോഡി എതിരെ സ്ഥിരീകരിക്കുക
Webhooks നിങ്ങളുടെ URL-ലേക്ക് POST ചെയ്യുന്നു, ആ URL അറിയുന്ന ആരും മാലിന്യം POST ചെയ്യാൻ കഴിയും. ഒരു ഇവന്റ് വിശ്വസിക്കുന്നതിന് മുമ്പ് @blockchain0x/node-ൽ നിന്ന് webhooks.verify കച്ചവട അഭ്യർത്ഥന ബൈറ്റുകൾക്കായി പ്രവർത്തിപ്പിക്കുക. JSON ആദ്യം പാഴ്സുചെയ്യുക, HMAC പൊരുത്തപ്പെടില്ല, കാരണം ഒപ്പിടൽ എത്തിയ കൃത്യമായ ബൈറ്റുകൾ ഉൾക്കൊള്ളുന്നു. ഇത് 300-സെക്കൻഡ് റിപ്ലേ വിൻഡോയുള്ള HMAC-SHA256 ആണ്. ഇത് ഒഴിവാക്കുന്നത് ഏറ്റവും സാധാരണമായ ഉൽപ്പന്നം നഷ്ടമാണ്.
send_payment തുടക്കത്തിൽ 503 മറുപടി നൽകാം
blockchain0x_send_payment wrap ചെയ്യുന്ന payments.create ഡിഫോൾട്ടായി വീണ്ടും ശ്രമിക്കില്ല, കൂടാതെ നിങ്ങളുടെ network-നായി chain adapter ബന്ധിപ്പിക്കുന്നതുവരെ 503 തിരികെ നൽകാം. error വന്നപ്പോൾ LLM tool-നെ retry loop-ൽ ഇടിച്ച് hammer ചെയ്യാൻ വിടരുത്: അത് tokens ചോരിക്കുകയും നിങ്ങളുടെ intent log മങ്ങിയാക്കുകയും ചെയ്യും. built-in idempotency key-യിൽ ആശ്രയിക്കുക, failure തുറന്നുകാട്ടുക, മുന്നോട്ട് പോകുക.
langchain-core പതിപ്പ് പൊരുത്തപ്പെടുത്തുക
blockchain0x-langchain 0.1.x langchain-core >=0.2,<0.4 നെ ലക്ഷ്യമിടുന്നു. adapter പിന്തുണയ്ക്കുന്നതിനെക്കാൾ പുതിയ core നിങ്ങൾ ഉപയോഗിക്കുന്നുവെങ്കിൽ, രണ്ടിന്റെയും ഏറ്റവും പുതിയ പതിപ്പ് പിന്തുടരുന്നതിനുപകരം പൊരുത്തപ്പെടുന്ന pair pin ചെയ്യുക. support matrix docs-ൽ ആണ്.