Skip to main content
This guide gets you from zero to borrowing USDC in five minutes. You’ll register an agent identity, deposit collateral into Morpho Blue, and borrow USDC — all through the @agether/sdk.

Prerequisites

  • Node.js 18+ and npm/yarn/pnpm
  • A wallet private key with:
    • Some ETH on Base (chain ID 8453) for gas (~$0.50 worth)
    • Collateral tokens (WETH, wstETH, or cbETH) on Base
Never use your main wallet’s private key. Create a dedicated agent wallet with only the funds needed for testing.

Step 1: Install the SDK

npm install @agether/sdk

Step 2: Register Your Agent

Every agent starts with an ERC-8004 identity. Registration mints an NFT and deploys a Safe-based smart wallet for your agent.
import { MorphoClient } from '@agether/sdk';

const morpho = new MorphoClient({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  rpcUrl: 'https://base-rpc.publicnode.com',
});

// Register — mints an ERC-8004 NFT and deploys a Safe account
const { agentId, agentAccount } = await morpho.register();
console.log('Agent ID:', agentId);
console.log('Smart Wallet:', agentAccount);
Registration is a one-time operation. The agentId is permanent and follows the NFT — if you transfer it, the new owner controls the smart wallet.

Step 3: Check Markets

See what collateral types are available for borrowing USDC:
const markets = await morpho.getMarkets();
for (const market of markets) {
  console.log(`${market.collateralAsset.symbol}:`);
  console.log(`  LLTV: ${Number(market.lltv) / 1e16}%`);
  console.log(`  Utilization: ${(market.utilization * 100).toFixed(1)}%`);
}
Typical markets:
CollateralLLTVNotes
WETH86%Most liquid, lowest rates
wstETH86%Earns staking yield while used as collateral
cbETH77%Coinbase ETH staking

Step 4: Deposit & Borrow

Deposit collateral and borrow USDC in a single atomic transaction:
// Deposit 0.1 WETH and borrow $100 USDC
const result = await morpho.depositAndBorrow('WETH', '0.1', '100');
console.log('TX:', result.tx);

// Check your position
const status = await morpho.getStatus();
console.log('Total debt:', status.totalDebt, 'USDC');
for (const pos of status.positions) {
  console.log(`${pos.collateralToken}: ${pos.collateral}`);
  console.log(`Debt: ${pos.debt} USDC`);
}
Keep your Health Factor above 1.1 at minimum. Below 1.0, your position can be liquidated by anyone.

Step 5: Make x402 Payments

Use your borrowed USDC to pay for API calls via the x402 protocol:
import { X402Client } from '@agether/sdk';

const x402 = new X402Client({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  rpcUrl: 'https://base-rpc.publicnode.com',
  backendUrl: process.env.AGETHER_BACKEND_URL || 'http://95.179.189.214:3001',
  agentId: agentId.toString(),
  accountAddress: agentAccount,
});

// This automatically handles 402 → payment → retry
const response = await x402.get('https://api.example.com/inference');
if (response.success) {
  console.log('Data:', response.data);
}

Step 6: Repay & Withdraw

When you’re done:
// Repay all USDC debt
await morpho.repay('all');

// Withdraw your collateral
await morpho.withdrawCollateral('WETH', 'all');

console.log('Position closed');

Full Example

import { MorphoClient, X402Client } from '@agether/sdk';

async function main() {
  // Initialize
  const morpho = new MorphoClient({
    privateKey: process.env.AGENT_PRIVATE_KEY!,
    rpcUrl: 'https://base-rpc.publicnode.com',
  });

  // Register agent
  const { agentId, agentAccount } = await morpho.register();

  // Deposit 0.05 WETH, borrow $50 USDC
  await morpho.depositAndBorrow('WETH', '0.05', '50');

  // Set up x402 for paid API calls
  const x402 = new X402Client({
    privateKey: process.env.AGENT_PRIVATE_KEY!,
    rpcUrl: 'https://base-rpc.publicnode.com',
    backendUrl: process.env.AGETHER_BACKEND_URL || 'http://95.179.189.214:3001',
    agentId: agentId.toString(),
    accountAddress: agentAccount,
    autoDraw: true, // Auto-borrow when low on USDC
    dailySpendLimitUsdc: '10',
  });

  // Make paid requests
  const resp = await x402.get('https://api.example.com/data');
  if (resp.success) {
    console.log('Data:', resp.data);
  }

  // Clean up
  await morpho.repay('all');
  await morpho.withdrawCollateral('WETH', 'all');
}

main().catch(console.error);

Checking Your Credit Score

Once you have some borrowing history, check your credit score:
import { ScoringClient } from '@agether/sdk';

const scoring = new ScoringClient({
  endpoint: process.env.AGETHER_BACKEND_URL || 'http://95.179.189.214:3001',
});

// Free — reads the current onchain score
const score = await scoring.getCurrentScore(agentId);
console.log(`Score: ${score.score} (${score.fresh ? 'fresh' : 'stale'})`);
New agents start at 300 (thin file). This is expected — build history by borrowing and repaying on time, and your score will improve.

Using via OpenClaw Plugin

If your AI agent runs on OpenClaw, you can skip the TypeScript code above. The Agether OpenClaw plugin exposes every operation as a natural language tool — your agent can say “Deposit 0.1 WETH and borrow $100 USDC” in Telegram, and the plugin handles everything.
# Install the plugin
openclaw plugins install @agether/agether

# Add to ~/.openclaw/openclaw.json:
# {
#   "plugins": {
#     "entries": {
#       "agether": {
#         "enabled": true,
#         "config": {
#           "privateKey": "0xYourPrivateKey",
#           "rpcUrl": "https://base-rpc.publicnode.com",
#           "backendUrl": "http://95.179.189.214:3001"
#         }
#       }
#     }
#   }
# }

# Restart the gateway
openclaw gateway restart
Once installed, talk to your agent naturally:
  • “What is my balance?”
  • “Register me on Agether”
  • “Deposit 0.05 WETH and borrow $50 USDC”
  • “What is my credit score?”
  • “Repay all my debt”
The plugin supports 15 tools across identity, lending, and scoring. See the Plugin Overview and Tools Reference for details.

What’s Next?