Getting Started
In this guide we’ll build an agent that can find a tool, run it, and pay for it — from a custodied wallet, gaslessly, under a spending policy you control.
Prerequisites
Section titled “Prerequisites”- Node.js 18+
- An LLM API key (OpenAI in the example — any LangChain-supported model works)
- A 0xGasless API key from your Dashboard project (Project → API Key)
1. Install
Section titled “1. Install”mkdir my-agent && cd my-agentnpm init -ynpm install @0xgasless/agentkit @langchain/openai @langchain/langgraph @langchain/core dotenvCreate .env:
OPENAI_API_KEY="sk-..."OXGAS_API_KEY="0xgas_live_sk_..."2. Configure — platform mode
Section titled “2. Configure — platform mode”The API key authenticates every action; the wallet lives in 0xGasless KMS. No private key ever touches your process.
import { Agentkit, AgentkitToolkit } from "@0xgasless/agentkit";import "dotenv/config";
const agentkit = await Agentkit.configureWithPlatform({ apiKey: process.env.OXGAS_API_KEY!, agentId: "my-first-agent", // created on first use, or via the dashboard chain: "avalanche-fuji", // Avalanche is the primary network});3. Hand the tools to your agent
Section titled “3. Hand the tools to your agent”import { ChatOpenAI } from "@langchain/openai";import { createReactAgent } from "@langchain/langgraph/prebuilt";
const tools = new AgentkitToolkit(agentkit).getTools();const app = createReactAgent({ llm: new ChatOpenAI({ model: "gpt-4o" }), tools });4. Let it work
Section titled “4. Let it work”const result = await app.invoke({ messages: [{ role: "user", content: "Find a tool that can read a web page, then read https://example.com and summarize it." }],});console.log(result.messages.at(-1)?.content);Behind that one prompt: the agent calls search_tools (free), picks the web
reader, calls browse_web → which pays ~$0.05 in USDC from its custodied
wallet via x402, settled on Avalanche by the 0xGasless facilitator → and gets
the page back. All under the spending policy set on your project.
Funding the agent
Section titled “Funding the agent”The agent spends stablecoin only — it needs zero AVAX. Send a little USDC
(Fuji test USDC works on the free tier) to the agent’s address — ask the agent
itself (“what’s your wallet address?”, it calls get_agent_wallet) or copy it
from Dashboard → Onchain Agents.
Self-custody mode
Section titled “Self-custody mode”If you hold the key yourself and want the classic gasless DeFi actions (transfers, swaps, bridges through an ERC-4337 smart account):
const agentkit = await Agentkit.configureWithWallet({ apiKey: process.env.OXGAS_API_KEY!, privateKey: process.env.PRIVATE_KEY as `0x${string}`, chainID: 43113,});Same toolkit — actions that require the platform (payments, tools, identity) will say so at runtime.
Next steps
Section titled “Next steps”- Payments actions — pay recipients and paid APIs, read spend caps.
- Tool actions — the Tool Gateway from the agent’s side.
- Trust actions — on-chain identity and reputation.
- How Agents Work — how the LLM ↔ tools loop functions.