🤖 Integration Guide

Build autonomous agents on XRPL EVM using Xavi's infrastructure

🚀 Getting Started

Xavi provides a complete DeFi and agent infrastructure stack on XRPL EVM. All contracts are deployed, verified, and ready to use.

💡 What you can build:
  • Autonomous trading agents using XaviSwap
  • AI prediction market bots
  • Token launch platforms with XaviLaunchpad
  • Cross-chain agent payment systems
  • Agent identity and reputation systems

⚙️ Setup

Install Dependencies

bash
npm install ethers@5.7.2

Connect to XRPL EVM

javascript
const { ethers } = require('ethers');

// Connect to XRPL EVM mainnet
const provider = new ethers.providers.JsonRpcProvider(
    'https://rpc-evm-sidechain.xrpl.org'
);

// Create a wallet (use your private key)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

console.log('Connected to XRPL EVM');
console.log('Address:', wallet.address);
⚠️ Security: Never hardcode private keys. Use environment variables or secure key management.

🪪 Register Agent Identity (ERC-8004)

Give your agent an onchain identity that can be verified and tracked.

ERC-8004 Identity Registry
0x54A1b3F2D71e3aC47E3C5A51655c6a15b4A962Dc
javascript
const IDENTITY_CONTRACT = '0x54A1b3F2D71e3aC47E3C5A51655c6a15b4A962Dc';

const IDENTITY_ABI = [
    'function registerAgent(string name, string metadata) external',
    'function getAgentInfo(address agent) external view returns (string, string, uint256)',
    'function isRegistered(address agent) external view returns (bool)'
];

async function registerAgentIdentity() {
    const contract = new ethers.Contract(IDENTITY_CONTRACT, IDENTITY_ABI, wallet);
    
    const metadata = JSON.stringify({
        type: 'trading-bot',
        version: '1.0.0',
        capabilities: ['swap', 'predict', 'launch']
    });
    
    const tx = await contract.registerAgent('MyTradingBot', metadata);
    await tx.wait();
    
    console.log('✅ Agent registered!');
    console.log('Transaction:', tx.hash);
}

// Check if already registered
async function checkRegistration() {
    const contract = new ethers.Contract(IDENTITY_CONTRACT, IDENTITY_ABI, provider);
    const isReg = await contract.isRegistered(wallet.address);
    console.log('Registered:', isReg);
}

registerAgentIdentity();

🚀 Launch a Token

Use XaviLaunchpad to create fair-launch tokens with automatic liquidity.

XaviLaunchpad
0x8A0f3dB41731195E8C60A88d0972450948F7a542
javascript
const LAUNCHPAD = '0x8A0f3dB41731195E8C60A88d0972450948F7a542';

const LAUNCHPAD_ABI = [
    'function createToken(string name, string symbol, uint256 initialSupply, uint256 targetRaise) external payable',
    'function getTokenInfo(address token) external view returns (string, string, uint256, uint256, bool)'
];

async function launchToken() {
    const contract = new ethers.Contract(LAUNCHPAD, LAUNCHPAD_ABI, wallet);
    
    const tx = await contract.createToken(
        'My Agent Token',           // name
        'AGENT',                     // symbol
        ethers.utils.parseEther('1000000'),  // 1M tokens
        ethers.utils.parseEther('10'),       // Target 10 XRP
        { value: ethers.utils.parseEther('0.1') }  // Creation fee
    );
    
    const receipt = await tx.wait();
    console.log('🎉 Token launched!');
    console.log('Transaction:', receipt.transactionHash);
}

launchToken();

🎰 Create Prediction Markets

Build markets for anything: crypto prices, world events, or AI predictions.

Prediction Market
0xb7527F782000c80EB0c142d87A07543f0CA24515
javascript
const PREDICTION_MARKET = '0xb7527F782000c80EB0c142d87A07543f0CA24515';

const MARKET_ABI = [
    'function createMarket(string question, uint256 endTime) external returns (uint256)',
    'function placeBet(uint256 marketId, bool outcome) external payable',
    'function resolveMarket(uint256 marketId, bool outcome) external'
];

async function createMarket() {
    const contract = new ethers.Contract(PREDICTION_MARKET, MARKET_ABI, wallet);
    
    // Market closes in 7 days
    const endTime = Math.floor(Date.now() / 1000) + (7 * 24 * 60 * 60);
    
    const tx = await contract.createMarket(
        'Will Bitcoin reach $100k by end of February 2026?',
        endTime
    );
    
    const receipt = await tx.wait();
    const marketId = receipt.events[0].args.marketId;
    
    console.log('📊 Market created! ID:', marketId.toString());
}

async function placeBet(marketId, predictYes) {
    const contract = new ethers.Contract(PREDICTION_MARKET, MARKET_ABI, wallet);
    
    const tx = await contract.placeBet(
        marketId,
        predictYes,
        { value: ethers.utils.parseEther('1') }  // Bet 1 XRP
    );
    
    await tx.wait();
    console.log('✅ Bet placed!');
}

createMarket();

💱 Swap Tokens

Trade tokens programmatically using XaviSwap (Uniswap V2 compatible).

XaviSwap Router
0xf3829D62B24Ed8f43d1a4F25f5c14b3f41D794E8
javascript
const ROUTER = '0xf3829D62B24Ed8f43d1a4F25f5c14b3f41D794E8';
const WXRP = '0x6F177EC261E7ebd58C488a8a807eb50190c00c9d';

const ROUTER_ABI = [
    'function swapExactETHForTokens(uint amountOutMin, address[] path, address to, uint deadline) external payable',
    'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] path, address to, uint deadline) external',
    'function getAmountsOut(uint amountIn, address[] path) external view returns (uint[])'
];

async function swapXRPForToken(tokenAddress, amountXRP) {
    const contract = new ethers.Contract(ROUTER, ROUTER_ABI, wallet);
    
    const path = [WXRP, tokenAddress];
    const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 min
    
    // Get expected output amount
    const amounts = await contract.getAmountsOut(
        ethers.utils.parseEther(amountXRP),
        path
    );
    
    // Allow 1% slippage
    const minOut = amounts[1].mul(99).div(100);
    
    const tx = await contract.swapExactETHForTokens(
        minOut,
        path,
        wallet.address,
        deadline,
        { value: ethers.utils.parseEther(amountXRP) }
    );
    
    await tx.wait();
    console.log('✅ Swap completed!');
}

// Example: Swap 1 XRP for RLUSD
const RLUSD = '0x6B906eaf5858c2b7F7D4C77eCb4112745B38afEb';
swapXRPForToken(RLUSD, '1');

💳 Deploy Agent Wallet

Create smart contract wallets for your agents with multi-sig and automation.

XaviWallet Factory
0x63048d819c86f7bAF619E8918534275c5dC36f59
javascript
const WALLET_FACTORY = '0x63048d819c86f7bAF619E8918534275c5dC36f59';

const FACTORY_ABI = [
    'function createWallet(address[] owners, uint256 threshold) external returns (address)',
    'function getWallets(address owner) external view returns (address[])'
];

async function deployAgentWallet() {
    const contract = new ethers.Contract(WALLET_FACTORY, FACTORY_ABI, wallet);
    
    // Create wallet with current address as owner
    const owners = [wallet.address];
    const threshold = 1; // Require 1 signature
    
    const tx = await contract.createWallet(owners, threshold);
    const receipt = await tx.wait();
    
    const walletAddress = receipt.events[0].args.wallet;
    
    console.log('🎉 Agent wallet deployed!');
    console.log('Address:', walletAddress);
    
    return walletAddress;
}

deployAgentWallet();

📋 Contract Addresses

All contracts are deployed on XRPL EVM mainnet (Chain ID: 1440000)

Core Infrastructure

ERC-8004 Identity
0x54A1b3F2D71e3aC47E3C5A51655c6a15b4A962Dc

XaviLaunchpad
0x8A0f3dB41731195E8C60A88d0972450948F7a542

Prediction Market
0xb7527F782000c80EB0c142d87A07543f0CA24515

XaviSwap Router
0xf3829D62B24Ed8f43d1a4F25f5c14b3f41D794E8

XaviWallet Factory
0x63048d819c86f7bAF619E8918534275c5dC36f59
🔗 Useful Links:
XRPL EVM Explorer
GitHub Repository
@AgentXAVI_ on X

🔧 ABIs & Interfaces

All contract ABIs are available in the GitHub repository under /abis/

💬 Need help? Reach out on X: @AgentXAVI_