DEV Community

Cover image for I Forked Abstract's Global Wallet to Give AI Agents Their Own Wallets on Base
Mr Hamlin
Mr Hamlin

Posted on

I Forked Abstract's Global Wallet to Give AI Agents Their Own Wallets on Base

The Problem: AI Agents Need Wallets, and Nobody's Making It Easy

If you're building AI agents that interact with blockchain — trading bots, payment agents, autonomous task runners — you hit the same wall everyone hits: the agent needs a wallet.

Your options today are pretty bad:

Option 1: Hardcode a private key in .env. This is what most tutorials show you. It's also a disaster waiting to happen. One leaked key and your agent's funds are gone.

Option 2: Use a custodial wallet provider. Phantom has a Server SDK that lets you create wallets programmatically. Great concept. But you need to apply to their developer program and wait for approval. I've been waiting. And waiting.

Option 3: Manual setup. A human creates a MetaMask wallet, funds it, and pastes the key into the agent config. This works for demos. It does not work at scale when you need to spin up 100 agents.

None of these give you what agents actually need: a wallet with spending limits, time-bound sessions, and automatic expiry. You know, the kind of safety rails you'd want before letting an autonomous AI handle real money.

The Inspiration: Abstract Global Wallet

While building Spraay (a multi-chain batch payment protocol), I started exploring Abstract chain as a potential addition to our supported networks. Abstract is an L2 built by the Pudgy Penguins team, and their standout feature is the Abstract Global Wallet (AGW).

AGW is elegant. You sign up with an email, and a smart contract wallet gets deployed for you behind the scenes. No seed phrases. No browser extensions. The wallet travels with you across every app on Abstract. Under the hood, it uses:

  • A factory contract that deploys wallet instances via CREATE2
  • Native account abstraction for gasless transactions
  • Session keys for pre-authorized actions without repeated signing
  • Privy for key management (splitting the private key into three shards)

The architecture is adapted from Clave's zkSync contracts, and it's open source under GPL-3.0.

I looked at this and thought: this is exactly what AI agents need. But the SDK only works in browsers, and the chain is locked to Abstract.

The Fork: What I Kept and What I Changed

The AGW contracts repo gave me the blueprint. Here's what I adapted:

What I Kept

  • Factory pattern with CREATE2 — deterministic wallet addresses, minimal proxy clones (EIP-1167). Each wallet deployment costs roughly $0.01-0.05 in gas on Base.
  • Smart contract wallet architecture — the wallet is a contract, not an EOA. This enables programmable rules.
  • Session keys — the feature that makes this work for agents. A session key is a temporary signer with a spending limit, expiry time, and optional target restrictions.

What I Changed

  • Removed Privy key-sharding — AGW splits the private key into three shards (device, server, recovery cloud). Agents don't have devices or iCloud. In our version, agents either hold their own keys (self-custody) or the provisioning service generates and encrypts keys server-side (managed mode).
  • Deployed on Base instead of Abstract — Abstract's SDK is chain-locked due to their native account abstraction implementation. Our contracts are standard Solidity that works on any EVM chain. We deployed on Base because that's where the rest of the Spraay ecosystem lives.
  • Added agent metadata — Each wallet stores an agentId and agentType (e.g., "eliza", "langchain", "crewai"). This feeds into our trust scoring system.
  • Exposed via x402 gateway — Instead of a browser SDK, wallet provisioning happens through API endpoints on our payment gateway. An agent pays $0.05 USDC and gets a wallet.

The Architecture

AI Agent (ElizaOS / LangChain / CrewAI / etc.)
    │
    │  x402 USDC micropayment ($0.05)
    ▼
Spraay Gateway (gateway.spraay.app)
    │
    │  POST /v1/wallet/provision
    ▼
SpraayWalletFactory (Base)
    │
    │  CREATE2 deploy (EIP-1167 minimal proxy)
    ▼
SpraayAgentWallet
    ├── Session Keys (spending limits + time bounds)
    ├── Batch Execution (multi-call in one tx)
    └── Agent Metadata (identity + trust scoring)
Enter fullscreen mode Exit fullscreen mode

The factory deploys minimal proxy clones — just 45 bytes of runtime bytecode that delegate all calls to the implementation contract. This keeps deployment gas costs extremely low.

The Contracts

SpraayAgentWallet.sol

The core wallet supports three main capabilities:

1. Session Keys

function addSessionKey(
    address sessionKey,
    uint256 spendLimitWei,
    uint256 validUntil,
    address[] calldata allowedTargets
) external onlyOwner;
Enter fullscreen mode Exit fullscreen mode

An agent creates a session key with a spending cap, expiry, and optional contract whitelist. The session key can then sign transactions on behalf of the wallet within those bounds. If the key is compromised, damage is capped at the spending limit.

2. Batch Execution

function executeBatch(
    address[] calldata targets,
    uint256[] calldata values,
    bytes[] calldata datas
) external onlyOwnerOrValidSession;
Enter fullscreen mode Exit fullscreen mode

Agents often need to do multiple things in one action — approve a token, then swap it, then send the result somewhere. Batch execution handles this atomically.

3. Agent Metadata

function setAgentMetadata(
    string calldata agentId,
    string calldata agentType
) external onlyOwner;
Enter fullscreen mode Exit fullscreen mode

Every wallet knows what agent framework created it and carries a unique identifier. This connects to our ProofLayer trust scoring system — agents build reputation over time based on their on-chain behavior.

SpraayWalletFactory.sol

The factory takes an implementation address in its constructor and deploys clones:

constructor(address _implementation) {
    require(_implementation != address(0), "SWF: zero impl");
    admin = msg.sender;
    walletImplementation = _implementation;
}

function createWallet(
    address owner,
    string calldata agentId,
    string calldata agentType,
    bytes32 salt
) external whenNotPaused returns (address wallet) {
    bytes32 finalSalt = keccak256(abi.encodePacked(owner, salt));
    wallet = _deployClone(walletImplementation, finalSalt);
    SpraayAgentWallet(payable(wallet)).initialize(owner, agentId, agentType);
    _wallets.push(wallet);
    _isWallet[wallet] = true;
    emit WalletCreated(wallet, owner, agentId, agentType);
}
Enter fullscreen mode Exit fullscreen mode

Deterministic addresses via CREATE2 mean you can predict a wallet's address before deploying it — useful for pre-funding scenarios.

Deployment

The contracts are live on Base Sepolia testnet:

Contract Address
Implementation 0xb6843955D914aD61dc6A4C819E0734d96467a391
Factory 0xe483F189af41FB5479cd8695DbbA16cc5CF1071D
Demo Wallet 0xcC74104d9d55889606e51FeD0f57c3AE23FC8054

The deployment process had its share of nonce collisions and "replacement transaction underpriced" errors from rapid-fire attempts on the testnet RPC. Pro tip: when deploying multiple contracts in sequence, explicitly manage your nonces:

const nonce = await ethers.provider.getTransactionCount(deployer.address, 'pending');
const impl = await Impl.deploy({ nonce: nonce });
const factory = await Factory.deploy(implAddr, { nonce: nonce + 1 });
Enter fullscreen mode Exit fullscreen mode

The SDK (Coming Soon)

Agent frameworks will be able to provision wallets with a few lines:

import { SpraayWallet } from 'spraay-agent-wallet';

const wallet = await SpraayWallet.provision({
  agentId: 'my-trading-agent',
  agentType: 'langchain',
  mode: 'managed',
}, {
  x402PaymentHeader: process.env.X402_HEADER,
});

// Add a session key: 0.5 ETH limit, 24 hours
const session = await wallet.addSessionKey({
  spendLimitEth: '0.5',
  durationHours: 24,
  allowedTargets: ['0x...BatchContract'],
});
Enter fullscreen mode Exit fullscreen mode

The goal is one npm install and three lines of code. If it's harder than that, developers won't use it.

Why This Matters

The intersection of AI agents and crypto is heating up fast. Coinbase has x402 for agent-to-agent payments. Virtuals Protocol has an agent economy. Every major framework is adding tool-use capabilities that include blockchain interactions.

But the wallet layer has been ignored. Everyone assumes the agent already has a wallet. Nobody's asking: how does the agent get the wallet in the first place? And how do you put guardrails on it so it doesn't drain its funds on a bad decision?

Session keys are the answer. An agent with a session key that caps spending at 0.5 ETH per day, expires in 24 hours, and can only interact with three specific contracts is a fundamentally different risk profile than an agent holding an unrestricted private key.

What's Next

  • Base mainnet deployment — same contracts, real money
  • Gateway integration — wallet endpoints join the existing 76+ paid endpoints on Spraay's x402 gateway
  • Agent framework PRs — ElizaOS plugin, LangChain tool, CrewAI integration
  • ProofLayer scoring — wallet behavior feeds into agent trust scores
  • npm publishspraay-agent-wallet package for drop-in SDK usage

Try It

The code is open source: github.com/plagtech/spraay-agent-wallet

Contracts are GPL-3.0, same license as the AGW contracts we forked from. If you're building agents that need wallets, take a look. If you have ideas for how session key policies should work for different agent types, open an issue.


Built by @lostpoet — building Spraay 💧, a multi-chain batch payment protocol with 76+ x402 gateway endpoints across 13 chains.

Thanks to the Abstract Foundation and Clave for the open source smart contract wallet architecture that made this possible.

Top comments (0)