💰Vault Operations

Guide for managing agent funds using the AgentVault contract.

Overview

The AgentVault allows agents to securely store and manage funds on-chain. The vault uses agent addresses (not agent IDs) for all operations.

circle-exclamation

Initialize SDK

import { SomniaAgentKit, SOMNIA_NETWORKS } from 'somnia-agent-kit';
import { ethers } from 'ethers';

const kit = new SomniaAgentKit({
  network: SOMNIA_NETWORKS.testnet,
  contracts: {
    agentRegistry: '0xC9f3452090EEB519467DEa4a390976D38C008347',
    agentManager: '0x77F6dC5924652e32DBa0B4329De0a44a2C95691E',
    agentExecutor: '0x157C56dEdbAB6caD541109daabA4663Fc016026e',
    agentVault: '0x7cEe3142A9c6d15529C322035041af697B2B5129',
  },
  privateKey: process.env.PRIVATE_KEY,
});

await kit.initialize();

Get Agent Address

First, get the agent address from the registry:

Create Vault

Create a new vault for an agent (only contract owner):

Deposit Native Tokens

Deposit STT (native tokens) into an agent's vault:

Deposit ERC20 Tokens

Deposit ERC20 tokens into vault:

Withdraw Native Tokens

Withdraw STT from agent vault (only agent owner or contract owner):

Withdraw ERC20 Tokens

Withdraw ERC20 tokens from vault:

Check Balances

Native Token Balance

ERC20 Token Balance

Daily Limit Management

Get Daily Limit Info

Update Daily Limit

Token Management

Get Allowed Tokens

Allow Token

Disallow Token

Vault Status

Check if Vault is Active

Activate Vault

Deactivate Vault

Listen to Events

Native Deposit Event

Native Withdraw Event

Token Deposit Event

Token Withdraw Event

Transfer Event

See Also

Last updated