Build your own Bankrbot-Style AI Agent (DIY) using NeuyRouter + Openclaw

Updated Feb 11, 2026 - Build your own "Bankr-like" agent using OpenClaw + NeuyRouter (Verbose, Mac + Windows)

This tutorial shows how to build a simple "Bankrbot-style" AI trading agent that can execute on-chain swaps using NeuyRouter. We will go slow and explain every step. Assume you know how to use a computer, but you are new to wallets, terminals, and crypto dev tools. By the end, you will have: (1) a dedicated wallet for your agent, (2) a safe test plan with tiny trades, (3) an OpenClaw project that can quote and swap using NeuyRouter, and (4) a clear path to expand into routing verification and automation.

0. Goal

We are building a "Bankr-style" agent. That means:

  • You (the human) give the agent an instruction like: "Swap 0.01 WETH to USDC."
  • The agent turns that instruction into a safe, step-by-step plan.
  • The agent checks the route and computes a slippage-protected minOut.
  • The agent submits the on-chain transaction using NeuyRouter.
  • The agent reports the result with a transaction hash and a clear success/failure message.
Important: this tutorial is intentionally verbose. If you are experienced, it may feel slow. That is on purpose. One small "first-run snag" causes many people to quit. We are building confidence.

1. What "Bankr-style" means (simple)

"Bankr-style" is not one special technology. It is a pattern:

  • Chat/commands: a way to tell the agent what to do (text prompt, UI, Discord, etc.)
  • Agent brain: turns a command into concrete steps (quote, approve, swap, confirm)
  • Wallet: the agent has a wallet key so it can sign transactions
  • Execution engine: a smart contract or tool that performs the swap

In our setup:

  • OpenClaw is the "agent brain" framework.
  • NeuyRouter is the on-chain execution engine for swaps (quotes + swaps).
  • Your dedicated wallet is the signer that sends transactions.

2. Safety first (read this)

An AI agent can lose funds quickly if it is careless. We will use these safety rules:

  • Dedicated wallet: do not use your main wallet. Create a separate wallet only for the agent.
  • Small funding: fund it with a small amount (think "test budget").
  • Tiny test trades: first swap should be very small.
  • Quote-only mode first: first we test quoting without swapping.
  • Hard limits: the agent should refuse large trades unless you explicitly allow it.
  • Clear logging: every action should be written to a log (what token, how much, what route, what minOut).
Non-custodial rule: never paste your private key into random websites or unknown tools. Only put your agent key in your local environment variables (on your own computer).

3. Requirements

Before we start, you need:

  • A computer (Mac or Windows)
  • An internet connection
  • A web browser (Chrome is easiest; Brave works too)
  • A wallet extension (MetaMask recommended)
  • A small amount of ETH for gas (because this example is Ethereum)
  • Optional but helpful: some WETH to swap (or you can swap ETH > WETH first)

What chain are we using?

This guide uses Ethereum mainnet for the examples. You can later repeat the same steps for Base, Arbitrum, etc. (Only the router and token addresses change.)

4. Create a dedicated agent wallet (MetaMask)

We want a wallet that is ONLY for the agent. If something goes wrong, you protect your main funds.

4.1 Install MetaMask

  • Open your browser
  • Install MetaMask extension
  • Create a new wallet (MetaMask will give you a secret recovery phrase)
Write down your recovery phrase on paper. Do not screenshot it. Do not email it. Do not store it in cloud notes.

4.2 Create a new account inside MetaMask for the agent

In MetaMask you can have multiple accounts. Create a new one and name it:

NeuyAgent (Dedicated)

This is the account you will fund and use for the agent.

5. Fund the wallet safely

Fund your agent wallet with a small amount first. Example: $20-$100 worth of ETH (whatever you are comfortable testing with).

5.1 Copy your agent wallet address

  • Open MetaMask
  • Select NeuyAgent (Dedicated)
  • Copy the public address (it starts with 0x)

5.2 Send ETH to the agent wallet

  • From your exchange or your main wallet, send a small amount of ETH to that address
  • Wait for confirmations (you will see the ETH appear in MetaMask)
Start small: your first goal is "prove the agent works". After it works reliably, you can increase funding later.

6. Install tools (Mac + Windows)

We are going to run OpenClaw locally on your computer. That means we need:

  • Node.js (so we can run JavaScript scripts)
  • Git (so we can download code projects)
  • A terminal (Mac: Terminal, Windows: Command Prompt or PowerShell)

6.1 Open a terminal

On Mac:

  • Press Command + Space
  • Type Terminal
  • Press Enter

On Windows:

  • Press the Windows key
  • Type PowerShell (or Command Prompt)
  • Press Enter

6.2 Install Node.js

Install Node.js (LTS version). After installation, close and re-open your terminal.

6.3 Verify installation

In your terminal, run:

node -v
npm -v

If you see version numbers (like v20.x.x), you are good.

6.4 Install Git (if needed)

Check if Git exists:

git --version

If that command fails:

  • Mac: installing Xcode Command Line Tools usually fixes it (your Mac may prompt you automatically).
  • Windows: install Git for Windows, then reopen your terminal.

7. Create your OpenClaw project (folder by folder)

We are going to create a new folder on your computer where your agent code will live. We will do it using the terminal so it is repeatable.

7.1 Choose a folder location

A simple place is your Desktop. We will create a folder called:

neuyrouter-agent

Mac (Terminal):

cd ~/Desktop
mkdir neuyrouter-agent
cd neuyrouter-agent

Windows (PowerShell):

cd $HOME\Desktop
mkdir neuyrouter-agent
cd neuyrouter-agent

Explanation: cd means "change directory". mkdir means "make directory" (create a folder).

7.2 Initialize a Node.js project

In the same folder, run:

npm init -y

This creates a package.json file (it describes your project).

7.3 Install ethers v5

We will use ethers v5 to talk to Ethereum and call NeuyRouter.

npm install ethers@5

7.4 Create a file for your agent script

Create a file named:

agent.js

Mac (Terminal):

touch agent.js

Windows (PowerShell):

New-Item agent.js -ItemType File

Now open that file in a text editor (VS Code recommended).

8. Add environment variables (your private key safely)

Your agent needs a private key to sign transactions. We will store it as an environment variable. That means it is stored locally on your machine, not inside your code file.

Do not hardcode private keys in your JavaScript file. If you accidentally share the file, you lose the wallet.

8.1 Get the private key for the dedicated agent account

  • Open MetaMask
  • Select the NeuyAgent (Dedicated) account
  • Account details > Export private key
  • Copy it temporarily (we will paste it into your local environment variable)

8.2 Set environment variables

We need two values:

  • AGENT_PRIVATE_KEY (your agent wallet private key)
  • ETH_RPC_URL (an Ethereum RPC endpoint)

For ETH_RPC_URL, you can use a provider like Infura, Alchemy, QuickNode, etc. You must paste your own endpoint URL here.

Mac (Terminal):

export AGENT_PRIVATE_KEY="PASTE_PRIVATE_KEY_HERE"
export ETH_RPC_URL="PASTE_YOUR_ETH_RPC_URL_HERE"

Windows (PowerShell):

$env:AGENT_PRIVATE_KEY="PASTE_PRIVATE_KEY_HERE"
$env:ETH_RPC_URL="PASTE_YOUR_ETH_RPC_URL_HERE"
Important: these variables are set for your current terminal session. If you close the terminal, you must set them again. Later you can store them in a .env file, but for first-time success, we keep it simple.

9. Add NeuyRouter config (Ethereum)

These addresses are the "constants" your agent will use. On other chains the values change, but the idea stays the same.

Item Value Notes
Chain Ethereum Mainnet
Chain ID 0x1 Ethereum mainnet
NeuyRouter
0xD3E73c2563fFCE65401DfdEcf66b699D4ce41fB9
V3 beta 4
WETH
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
18 decimals
USDC
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
6 decimals

10. First action: Quote only (no swapping yet)

First we test the safest thing: quoting. A quote reads blockchain state and returns numbers, but does not move funds.

10.1 Paste this into agent.js (quote-only version)

Copy and paste the full code below into your agent.js file. Then we will run it.

const { ethers } = require("ethers");

// ========== CONFIG (Ethereum mainnet) ==========
const NEUY_ROUTER = "0xD3E73c2563fFCE65401DfdEcf66b699D4ce41fB9";
const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; // 18
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // 6

// NeuyRouter ABI subset (quote + swap)
const routerAbi = [
  "function getV2Quote(address tkIn, address tkOut, uint256 amountIn) external view returns (uint256,uint256)",
  "function dexV2Swap(uint256 route, uint256 amountIn, uint256 amountOut, address tkIn, address tkOut) external returns (uint256)"
];

function requireEnv(name) {
  const v = process.env[name];
  if (!v || String(v).trim() === "") {
    throw new Error(`Missing environment variable: ${name}`);
  }
  return v.trim();
}

// ========== MAIN ==========
async function main() {
  console.log("NeuyRouter Agent (Quote Only) - Starting...");

  const RPC = requireEnv("ETH_RPC_URL");
  const pk = requireEnv("AGENT_PRIVATE_KEY");

  const provider = new ethers.providers.JsonRpcProvider(RPC);
  const wallet = new ethers.Wallet(pk, provider);

  console.log("Agent address:", wallet.address);

  const router = new ethers.Contract(NEUY_ROUTER, routerAbi, provider); // read-only for quote

  // Example input: 0.01 WETH
  const amountInHuman = "0.01";
  const amountIn = ethers.utils.parseUnits(amountInHuman, 18);

  console.log("Quoting getV2Quote(WETH, USDC, amountIn)...");
  const [amountOut, route] = await router.getV2Quote(WETH, USDC, amountIn);

  console.log("Quote result:");
  console.log("- amountIn (WETH):", amountInHuman);
  console.log("- amountOut (USDC):", ethers.utils.formatUnits(amountOut, 6));
  console.log("- route:", route.toString());

  console.log("Done");
}

main().catch((e) => {
  console.error("Error", e.message || e);
  process.exit(1);
});

10.2 Run the quote script

Go back to your terminal (Mac Terminal or Windows PowerShell). Make sure you are inside the neuyrouter-agent folder. Then run:

node agent.js

If everything is correct, you will see:

  • Your agent wallet address
  • A quote output
  • A route number
If this step works: you have proven your wallet + RPC + NeuyRouter quote call is working. That is a big milestone.

11. Second action: Approve + Swap (small amount)

Now we will perform the full flow:

  • Quote
  • Compute minOut (slippage protection)
  • Approve WETH for NeuyRouter (if needed)
  • Swap using the quoted route
Before you swap: confirm your agent wallet has: (1) ETH for gas, and (2) WETH to sell. If you only have ETH, you must wrap to WETH first using a normal wallet UI.

11.1 Replace agent.js with the full swap version

Copy/paste the code below into agent.js (replace everything).

const { ethers } = require("ethers");

// ========== CONFIG (Ethereum mainnet) ==========
const NEUY_ROUTER = "0xD3E73c2563fFCE65401DfdEcf66b699D4ce41fB9";
const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; // 18
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // 6

const routerAbi = [
  "function getV2Quote(address tkIn, address tkOut, uint256 amountIn) external view returns (uint256,uint256)",
  "function dexV2Swap(uint256 route, uint256 amountIn, uint256 amountOut, address tkIn, address tkOut) external returns (uint256)"
];

const erc20Abi = [
  "function approve(address spender, uint256 amount) external returns (bool)",
  "function allowance(address owner, address spender) external view returns (uint256)"
];

function requireEnv(name) {
  const v = process.env[name];
  if (!v || String(v).trim() === "") {
    throw new Error(`Missing environment variable: ${name}`);
  }
  return v.trim();
}

// minOut = amountOut * (10000 - bps) / 10000
function bpsMinOut(amountOutBn, bps) {
  const keep = ethers.BigNumber.from(10000 - Number(bps));
  return amountOutBn.mul(keep).div(10000);
}

async function ensureApproval(tokenAddr, ownerWallet, spenderAddr, amountIn) {
  const token = new ethers.Contract(tokenAddr, erc20Abi, ownerWallet);
  const allowance = await token.allowance(ownerWallet.address, spenderAddr);
  if (allowance.gte(amountIn)) {
    return { didApprove: false };
  }

  console.log("Approval needed. Sending approve()...");
  const tx = await token.approve(spenderAddr, amountIn);
  console.log("Approve tx:", tx.hash);
  const receipt = await tx.wait();
  if (receipt.status !== 1) {
    throw new Error("Approval failed / reverted");
  }
  return { didApprove: true, txHash: tx.hash };
}

async function main() {
  console.log("NeuyRouter Agent (Quote + Approve + Swap) - Starting...");

  const RPC = requireEnv("ETH_RPC_URL");
  const pk = requireEnv("AGENT_PRIVATE_KEY");

  const provider = new ethers.providers.JsonRpcProvider(RPC);
  const wallet = new ethers.Wallet(pk, provider);

  console.log("Agent address:", wallet.address);
  console.log("Router:", NEUY_ROUTER);

  // --- User instruction (example) ---
  // Keep this small for the first test.
  const amountInHuman = "0.005";  // tiny test
  const slippageBps = 200;        // 200 = 2%

  const amountIn = ethers.utils.parseUnits(amountInHuman, 18);

  // 1) Quote
  const routerRead = new ethers.Contract(NEUY_ROUTER, routerAbi, provider);
  console.log("Quoting getV2Quote...");
  const [amountOut, route] = await routerRead.getV2Quote(WETH, USDC, amountIn);

  console.log("Quote OK:");
  console.log("- amountIn (WETH):", amountInHuman);
  console.log("- amountOut (USDC):", ethers.utils.formatUnits(amountOut, 6));
  console.log("- route:", route.toString());

  // 2) Slippage protection
  const minOut = bpsMinOut(amountOut, slippageBps);
  console.log("- minOut (USDC):", ethers.utils.formatUnits(minOut, 6), `(slippage ${slippageBps} bps)`);

  // 3) Approve (WETH -> NeuyRouter) if needed
  const approvalRes = await ensureApproval(WETH, wallet, NEUY_ROUTER, amountIn);
  if (approvalRes.didApprove) {
    console.log("Approval confirmed", approvalRes.txHash);
  } else {
    console.log("Approval already sufficient");
  }

  // 4) Swap
  const routerWrite = new ethers.Contract(NEUY_ROUTER, routerAbi, wallet);
  console.log("Sending dexV2Swap...");
  const swapTx = await routerWrite.dexV2Swap(route, amountIn, minOut, WETH, USDC);

  console.log("Swap tx:", swapTx.hash);
  console.log("Waiting confirmation...");
  const receipt = await swapTx.wait();

  if (receipt.status === 1) {
    console.log("Swap success", swapTx.hash);
  } else {
    console.log("Swap reverted", swapTx.hash);
  }

  console.log("Done");
}

main().catch((e) => {
  console.error("Error", e.message || e);
  process.exit(1);
});

11.2 Run the swap script

In your terminal (in the project folder), run:

node agent.js

You should see:

  • A quote result
  • Optional approval transaction hash
  • A swap transaction hash
  • Swap success

12. Testing checklist (tiny trades)

Do not skip these. This is how you build confidence and avoid expensive mistakes.

  • Test 1: Quote-only mode works (no swap)
  • Test 2: Swap tiny amount (example 0.005 WETH)
  • Test 3: Repeat swap (approval should not be needed the second time)
  • Test 4: Increase slippage bps slightly if a swap fails (200 > 300)
  • Test 5: Confirm balances changed as expected in MetaMask
Tip: If you get "revert" or "swap failed", do not panic. Re-run quote (prices move), then swap again. Start with higher slippage bps if needed.

13. Logging + guardrails (what makes it "agent-safe")

A real AI agent should not be allowed to do anything it wants. Add these simple guardrails:

  • Max trade size: refuse trades above a safe limit (example: 0.02 WETH) unless you override.
  • Allowed tokens list: only allow swaps between known tokens.
  • Allowed chains: refuse transactions if chainId is wrong.
  • Write logs: log every instruction + quote + route + minOut + tx hash.

Here is a simple max-trade check you can add near the top:

// Example: block trades bigger than 0.02 WETH unless you change this.
const MAX_WETH_TRADE = ethers.utils.parseUnits("0.02", 18);
if (amountIn.gt(MAX_WETH_TRADE)) {
  throw new Error("Refusing trade: amount exceeds MAX_WETH_TRADE");
}

14. Next upgrades (V3, Split, verification)

Once your "V2 quote + V2 swap" agent works reliably, your next steps are:

  • Upgrade to V3: use getV3Quote + dexV3Swap (same flow)
  • Try Split swaps: use getSplitV2Quote + dexSplitV2Swap (token<>token only)
  • Add static verification: after quoting, run callStatic to remove routes that revert
Big idea: the agent mental model stays the same:
quote > minOut > approve > swap > confirm

15. FAQ / Troubleshooting

"I ran node agent.js and it says missing environment variable"

That means you did not set AGENT_PRIVATE_KEY or ETH_RPC_URL in your terminal session. Re-run the export commands in section 8.

"I got a quote, but swap failed"

  • Make sure the wallet has ETH for gas
  • Make sure the wallet has WETH to sell
  • Re-run the quote (prices move quickly)
  • Increase slippage bps slightly (200 > 300)

"What is the safest first swap amount?"

Something tiny that you do not care about losing. Example: 0.001-0.005 WETH.

Reference: NeuyRouter for AI Agents and NeuyRouter Dev Docs.