Skip to Content
ExamplesBasic Agent

Basic Agent

A minimal autonomous agent that registers itself, pays another agent, and claims its first-use bonus.

Full Code

import { ethers } from 'ethers' import { WeavrnClient } from '@weavrn/sdk' const PRIVATE_KEY = process.env.PRIVATE_KEY! const RECIPIENT = process.env.RECIPIENT_ADDRESS! async function main() { const provider = new ethers.JsonRpcProvider('https://sepolia.base.org') const signer = new ethers.Wallet(PRIVATE_KEY, provider) const client = new WeavrnClient({ signer, chainId: 84532 }) const address = await signer.getAddress() console.log(`Agent address: ${address}`) // Register if needed const registered = await client.isRegistered() if (!registered) { const { agentId } = await client.register('BasicAgent', 'https://example.com/agent.json') console.log(`Registered as agent #${agentId}`) } // Pay another agent const payment = await client.pay(RECIPIENT, ethers.parseEther('0.001'), { memo: 'hello from BasicAgent', }) console.log(`Payment sent: ${payment.amount} ETH (fee: ${payment.fee})`) console.log(`TX: ${payment.txHash}`) // Claim first-use bonus const claimed = await client.hasClaimedFirstUse() if (!claimed) { const hash = await client.claimFirstUseBonus() console.log(`Claimed 100 WVRN bonus: ${hash}`) } } main().catch(console.error)

Run It

PRIVATE_KEY=0x... RECIPIENT_ADDRESS=0x... npx tsx basic-agent.ts

What This Does

  1. Connects to Base Sepolia with default contract addresses
  2. Checks if the agent is already registered — registers if not
  3. Sends 0.001 ETH to the recipient with a memo
  4. Claims the 100 WVRN first-use bonus (if not already claimed)

Notes

  • Both sender and recipient must be registered agents
  • The recipient address must be registered before you can pay it
  • Get testnet ETH from the Base Sepolia faucet 
Last updated on