API Reference
Complete reference for the Sponge SDK classes and methods.
SpongeWallet
The primary class for wallet operations.
Constructor
import { SpongeWallet } from "@spongewallet/sdk";Static Methods
connect(options?)
Connect and authenticate a wallet.
const wallet = await SpongeWallet.connect({
testnet?: boolean; // Request test or live key
agentName?: string; // Custom agent name
keyType?: "agent" | "master"; // Key type to request
onVerification?: (info: VerificationInfo) => void;
credentialStorage?: CredentialStorage;
});Returns: Promise<SpongeWallet>
fromApiKey(apiKey)
Create wallet instance from existing API key.
const wallet = await SpongeWallet.fromApiKey("sponge_test_...");Returns: Promise<SpongeWallet>
Instance Properties
agentId
The unique agent identifier.
wallet.agentId // "agent_abc123"isTestMode
Whether the wallet is in test mode.
wallet.isTestMode // trueWallet Methods
getAddresses()
Get all wallet addresses.
const addresses = await wallet.getAddresses();
// { evm: "0x...", solana: "7nYB..." }Returns: Promise<{ evm: string; solana: string }>
getAddress(chain)
Get address for specific chain.
const address = await wallet.getAddress("base");
// "0x1234..."Parameters:
chain- Chain identifier
Returns: Promise<string>
Balance Methods
getBalances()
Get balances across all chains.
const balances = await wallet.getBalances();Returns: Promise<Balance[]>
interface Balance {
chain: string;
chainId: number;
address: string;
balance: string;
symbol: string;
usdValue: string;
tokenBalances?: TokenBalance[];
}
interface TokenBalance {
tokenAddress: string;
symbol: string;
name: string;
decimals: number;
balance: string;
formatted: string;
usdValue?: string;
}getBalance(chain)
Get balance for specific chain.
const balance = await wallet.getBalance("ethereum");Parameters:
chain- Chain identifier
Returns: Promise<Balance>
getSolanaTokens()
Get all SPL tokens in Solana wallet.
const tokens = await wallet.getSolanaTokens();Returns: Promise<SolanaToken[]>
Transfer Methods
transfer(options)
Transfer crypto to an address.
const tx = await wallet.transfer({
chain: "base",
to: "0x...",
amount: "10.0",
currency: "USDC"
});Parameters:
interface TransferOptions {
chain: string; // Chain identifier
to: string; // Recipient address
amount: string; // Amount as decimal string
currency: string; // Token symbol (ETH, USDC, SOL, etc.)
}Returns: Promise<Transaction>
interface Transaction {
id: string;
hash: string; // EVM tx hash or Solana signature
status: "pending" | "confirmed" | "failed";
explorerUrl: string;
chain: string;
from: string;
to: string;
amount: string;
currency: string;
gasUsed?: string;
timestamp: string;
}Swap Methods
swap(options)
Swap tokens on Solana.
const swap = await wallet.swap({
chain: "solana",
fromToken: "SOL",
toToken: "USDC",
amount: "1.0",
slippage: 0.5
});Parameters:
interface SwapOptions {
chain: "solana" | "solana-devnet";
fromToken: string; // Token symbol or mint address
toToken: string; // Token symbol or mint address
amount: string; // Amount of fromToken
slippage?: number; // Slippage tolerance in % (default: 0.5)
}Returns: Promise<SwapResult>
getSwapQuote(options)
Get a swap quote without executing.
const quote = await wallet.getSwapQuote({
chain: "solana",
fromToken: "SOL",
toToken: "USDC",
amount: "1.0"
});Returns: Promise<SwapQuote>
interface SwapQuote {
fromToken: string;
toToken: string;
fromAmount: string;
expectedOutput: string;
minimumOutput: string;
priceImpact: string;
route: string[];
}Transaction Methods
getTransactionStatus(options)
Check transaction status.
const status = await wallet.getTransactionStatus({
hash: "0x...", // or signature for Solana
chain: "ethereum"
});Returns: Promise<TransactionStatus>
interface TransactionStatus {
status: "pending" | "confirmed" | "failed";
confirmations: number;
blockNumber?: number;
error?: string;
}getTransactionHistory(options?)
Get transaction history.
const history = await wallet.getTransactionHistory({
limit?: number; // Max results (default: 50)
offset?: number; // Pagination offset
chain?: string; // Filter by chain
});Returns: Promise<Transaction[]>
Funding Methods
requestFunding(options)
Request funds from wallet owner.
const request = await wallet.requestFunding({
chain: "base",
amount: "100.0",
currency: "USDC",
reason: "Trading operations"
});Returns: Promise<FundingRequest>
withdraw(options)
Withdraw to owner's main wallet.
const withdrawal = await wallet.withdraw({
chain: "base",
amount: "50.0",
currency: "USDC"
});Returns: Promise<Transaction>
requestFaucet(options)
Request testnet tokens (test keys only).
const faucet = await wallet.requestFaucet({
chain: "tempo"
});Returns: Promise<FaucetResult>
Claude Integration
mcp()
Get MCP server configuration.
const config = wallet.mcp();
// Use with Anthropic SDK mcp_servers optionReturns: McpServerConfig
tools(options?)
Get Anthropic tool definitions and executor.
const tools = wallet.tools({
include?: string[]; // Only these tools
exclude?: string[]; // Exclude these tools
debug?: boolean; // Enable debug logging
beforeExecute?: (name: string, input: any) => Promise<void>;
});Returns: Tools
interface Tools {
definitions: AnthropicTool[];
execute: (name: string, input: any) => Promise<any>;
}Utility Methods
getAvailableChains()
List available chains for this API key.
const chains = await wallet.getAvailableChains();Returns: Promise<ChainConfig[]>
isChainAvailable(chain)
Check if chain is available.
const available = await wallet.isChainAvailable("ethereum");Returns: Promise<boolean>
disconnect()
Clear stored credentials.
await wallet.disconnect();refresh()
Force credential refresh.
await wallet.refresh();SpongeAdmin
Admin class for programmatic agent management.
Static Methods
connect(options?)
Connect with master key via device flow.
const admin = await SpongeAdmin.connect();Returns: Promise<SpongeAdmin>
fromApiKey(masterKey)
Create from existing master key.
const admin = await SpongeAdmin.fromApiKey("master_xxx_...");Returns: Promise<SpongeAdmin>
Agent Methods
createAgent(options)
Create a new agent.
const agent = await admin.createAgent({
name: string;
description?: string;
testnet?: boolean;
dailySpendingLimit?: string;
weeklySpendingLimit?: string;
monthlySpendingLimit?: string;
metadata?: Record<string, unknown>;
});Returns: Promise<CreateAgentResponse>
interface CreateAgentResponse {
id: string;
name: string;
apiKey: string; // Only shown on creation
wallets: {
evm: string;
solana: string;
};
}listAgents(options?)
List all agents.
const agents = await admin.listAgents({
includeBalances?: boolean;
testMode?: boolean;
});Returns: Promise<Agent[]>
getAgent(agentId)
Get agent details.
const agent = await admin.getAgent("agent_abc123");Returns: Promise<Agent>
deleteAgent(agentId)
Delete an agent.
await admin.deleteAgent("agent_abc123");Returns: Promise<void>
pauseAgent(agentId)
Pause an agent.
await admin.pauseAgent("agent_abc123");Returns: Promise<void>
resumeAgent(agentId)
Resume a paused agent.
await admin.resumeAgent("agent_abc123");Returns: Promise<void>
Key Management
rotateAgentKey(agentId)
Rotate agent's API key.
const result = await admin.rotateAgentKey("agent_abc123");
// { apiKey: "sponge_test_new...", previousKeyRevoked: true }Returns: Promise<KeyRotationResult>
Spending Limits
setSpendingLimit(agentId, options)
Set spending limit on agent.
await admin.setSpendingLimit("agent_abc123", {
type: "daily" | "weekly" | "monthly" | "per_transaction" | "per_minute" | "hourly";
amount: string;
currency: "USD";
});Returns: Promise<SpendingLimit>
getSpendingLimits(agentId)
Get agent's spending limits.
const limits = await admin.getSpendingLimits("agent_abc123");Returns: Promise<SpendingLimit[]>
Allowlist
addToAllowlist(agentId, options)
Add address to allowlist.
await admin.addToAllowlist("agent_abc123", {
chain: "base";
address: "0x...";
label?: string;
});Returns: Promise<AllowlistEntry>
getAgentAllowlist(agentId)
Get agent's allowlist.
const allowlist = await admin.getAgentAllowlist("agent_abc123");Returns: Promise<AllowlistEntry[]>
removeFromAllowlist(agentId, entryId)
Remove from allowlist.
await admin.removeFromAllowlist("agent_abc123", "entry_id");Returns: Promise<void>
Audit
getAgentAuditLogs(agentId, options?)
Get agent audit logs.
const logs = await admin.getAgentAuditLogs("agent_abc123", {
limit?: number;
offset?: number;
});Returns: Promise<AuditLog[]>
interface AuditLog {
id: string;
action: string;
entityType: string;
entityId: string;
changes?: { before?: any; after?: any };
metadata?: Record<string, unknown>;
timestamp: string;
}Types
ChainName
type ChainName =
| "ethereum"
| "base"
| "solana"
| "sepolia"
| "base-sepolia"
| "solana-devnet"
| "tempo";ChainType
type ChainType = "evm" | "solana";TransactionStatus
type TransactionStatus = "pending" | "confirmed" | "failed";AgentStatus
type AgentStatus = "active" | "paused" | "suspended";Errors
SpongeError
Base error class.
import { SpongeError } from "@spongewallet/sdk";
try {
await wallet.transfer(...);
} catch (error) {
if (error instanceof SpongeError) {
console.log(error.code); // "INSUFFICIENT_FUNDS"
console.log(error.message); // "Insufficient balance"
}
}Error Codes
| Code | Description |
|---|---|
UNAUTHORIZED | Invalid or expired API key |
INSUFFICIENT_FUNDS | Not enough balance |
INVALID_ADDRESS | Invalid recipient address |
INVALID_CHAIN | Chain not available for key type |
SPENDING_LIMIT_EXCEEDED | Transaction exceeds limit |
ADDRESS_NOT_ALLOWLISTED | Recipient not on allowlist |
AGENT_PAUSED | Agent is paused |
RATE_LIMITED | Too many requests |
NETWORK_ERROR | Blockchain network error |
Specific Error Classes
import {
InsufficientFundsError,
InvalidAddressError,
SpendingLimitError,
AllowlistError
} from "@spongewallet/sdk";Environment Variables
| Variable | Description |
|---|---|
SPONGE_API_KEY | Default agent API key |
SPONGE_MASTER_KEY | Default master key |
SPONGE_DEBUG | Enable debug logging |
SPONGE_API_URL | Custom API URL (advanced) |