>AgentChain

Quick Start Guide

This guide walks you through connecting to AgentChain and sending your first transaction. All examples are provided in both Python and JavaScript so you can use whichever fits your stack.

Prerequisites

You need one of the following installed:

  • Python 3.8+ (for web3.py)
  • Node.js 16+ (for ethers.js)

You also need a running AgentChain node accessible at http://localhost:8545. See the node setup guide for instructions on running your own node.

Step 1: Install the Client Library

Python

pip install web3

JavaScript

npm install ethers

Step 2: Connect to the Network

Python

from web3 import Web3
 
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
 
if w3.is_connected():
    print("Connected to AgentChain!")
else:
    print("Connection failed. Is your node running?")

JavaScript

import { ethers } from "ethers";
 
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
console.log("Provider created. Verifying connection...");

Step 3: Verify the Chain ID

Always verify that you are connected to AgentChain (chain ID 7331) and not a different network.

Python

from web3 import Web3
 
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
assert w3.eth.chain_id == 7331, "Not connected to AgentChain"
print(f"Connected! Latest block: {w3.eth.block_number}")

JavaScript

import { ethers } from "ethers";
 
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
const network = await provider.getNetwork();
console.log(`Chain ID: ${network.chainId}`); // 7331n
 
if (network.chainId !== 7331n) {
  throw new Error("Not connected to AgentChain");
}
 
const blockNumber = await provider.getBlockNumber();
console.log(`Latest block: ${blockNumber}`);

Step 4: Check an Address Balance

Python

from web3 import Web3
 
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
 
address = "0xYourAddressHere"
balance_wei = w3.eth.get_balance(address)
balance_crd = w3.from_wei(balance_wei, "ether")
print(f"Balance: {balance_crd} CRD")

JavaScript

import { ethers } from "ethers";
 
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
 
const address = "0xYourAddressHere";
const balanceWei = await provider.getBalance(address);
const balanceCrd = ethers.formatEther(balanceWei);
console.log(`Balance: ${balanceCrd} CRD`);

Step 5: Send a Transaction

There are two ways to send transactions on AgentChain:

Option A: Agent API (Recommended for AI Agents)

The agent API lets you create wallets and send transactions without handling any private keys. This is the recommended approach for LLM-based agents because keys never appear in RPC calls.

import requests
 
rpc = "http://localhost:8545"
 
def call(method, params=[]):
    r = requests.post(rpc, json={
        "jsonrpc": "2.0", "method": method,
        "params": params, "id": 1
    })
    return r.json()["result"]
 
# Create a wallet — no keys, no passwords
addr = call("agent_createWallet")
print(f"Wallet: {addr}")
 
# Send 1 CRD (after mining some)
tx = call("agent_send", [addr, "0xRecipient...", "0xDE0B6B3A7640000"])
print(f"TX: {tx}")
async function call(method, params = []) {
  const res = await fetch("http://localhost:8545", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ jsonrpc: "2.0", method, params, id: 1 }),
  });
  return (await res.json()).result;
}
 
// Create a wallet — no keys, no passwords
const addr = await call("agent_createWallet");
console.log("Wallet:", addr);
 
// Send 1 CRD (after mining some)
const tx = await call("agent_send", [addr, "0xRecipient...", "0xDE0B6B3A7640000"]);
console.log("TX:", tx);

See the Agent API Reference for the complete method list.

Option B: Standard Ethereum Libraries (for developers managing keys locally)

If you manage keys locally (not through an LLM), you can use standard web3.py or ethers.js:

from web3 import Web3
 
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
 
private_key = "0xYourPrivateKeyHere"
account = w3.eth.account.from_key(private_key)
 
tx = {
    "from": account.address,
    "to": "0xRecipientAddressHere",
    "value": w3.to_wei(1.0, "ether"),  # 1 CRD
    "gas": 21000,
    "gasPrice": w3.eth.gas_price,
    "nonce": w3.eth.get_transaction_count(account.address),
    "chainId": 7331,
}
 
signed_tx = w3.eth.account.sign_transaction(tx, private_key)
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Confirmed in block {receipt.blockNumber}")

Warning: Never use private keys in code that runs through an LLM API. Use the Agent API instead.

Important Notes

  • AI agents should use the agent_* API. It handles keys internally so nothing leaks to LLM providers. The personal_* namespace is disabled on HTTP/WS for this reason.
  • Legacy transactions only. AgentChain does not support EIP-1559. Always use transaction type 0 (legacy).
  • Chain ID 7331. Always include the chain ID when signing transactions.
  • Block time is 6 seconds. Transactions typically confirm within one block.
  • Solidity version. Use Solidity 0.8.19 or earlier for Berlin EVM compatibility.

Next Steps