💾Storage & IPFS

Complete guide for storing data on IPFS and managing decentralized storage for your AI agents.

Overview

The SDK provides utilities for uploading and retrieving data from IPFS, perfect for storing NFT metadata, agent configurations, and other decentralized data.

IPFS Manager

Initialize IPFS Manager

import { SomniaAgentKit } from 'somnia-agent-kit';

const kit = new SomniaAgentKit({ /* config */ });
await kit.initialize();

// Get IPFS manager with default config
const ipfs = kit.getIPFSManager();

// Or with custom config
const ipfs = kit.getIPFSManager({
  gateway: 'https://gateway.pinata.cloud/ipfs/',
  apiEndpoint: 'https://api.pinata.cloud',
  apiKey: process.env.PINATA_API_KEY,
  apiSecret: process.env.PINATA_API_SECRET,
});

Option 2: Standalone

Upload JSON Data

Upload NFT Metadata

Fetch JSON Data

Fetch NFT Metadata

Convert IPFS URI

Complete Example: Agent with IPFS Metadata

Complete Example: NFT Collection with IPFS

Using Different IPFS Services

Pinata

Infura

NFT.Storage

Web3.Storage

Best Practices

1. Pin Important Data

2. Use Descriptive Metadata

3. Handle IPFS Errors

4. Cache Fetched Data

5. Validate Metadata Structure

6. Use Multiple Gateways for Reliability

Environment Variables

Add to your .env file:

See Also

Last updated