Skip to content

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.

  • 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)
Terminal window
mkdir my-agent && cd my-agent
npm init -y
npm install @0xgasless/agentkit @langchain/openai @langchain/langgraph @langchain/core dotenv

Create .env:

OPENAI_API_KEY="sk-..."
OXGAS_API_KEY="0xgas_live_sk_..."

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
});
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 });
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.

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.

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.