LangGraph Integration
Installation
pnpm add @shade402/langgraph @shade402/client @shade402/core @langchain/langgraphQuick Start
import { StateGraph } from '@langchain/langgraph';
import { fetchWithPaymentNode } from '@shade402/langgraph';
import { Keypair } from '@solana/web3.js';
import { PaymentState } from '@shade402/langgraph';
const workflow = new StateGraph<PaymentState>({
channels: {
api_url: { reducer: (x, y) => y ?? x },
api_response: { reducer: (x, y) => y ?? x },
wallet_keypair: { reducer: (x, y) => y ?? x },
},
});
workflow.addNode('fetch_api', fetchWithPaymentNode);
workflow.setEntryPoint('fetch_api');
const app = workflow.compile();
const result = await app.invoke({
api_url: 'https://api.example.com/premium-data',
wallet_keypair: Keypair.generate(),
});Payment Nodes
fetchWithPaymentNode
fetchWithPaymentNodepaymentNode
paymentNodePayment State
Workflow Patterns
Simple Payment Flow
Conditional Payment Flow
Multiple API Calls
Conditional Functions
checkPaymentRequired
checkPaymentRequiredcheckPaymentCompleted
checkPaymentCompletedCustom Conditional Functions
Complete Example
Best Practices
Next Steps
Last updated
