Getting Started
Installation
Create a new project:
mkdir keypo-project
cd keypo-project
npm init -yInstall the SDK and dependencies:
npm install @keypo/synapse-storage-sdk @filoz/synapse-sdk ethers viemEnvironment Setup
Create a .env file:
# Your wallet private key (with or without 0x prefix)
PRIVATE_KEY=your_private_key_here
# Smart contract settings:
# An RPC URL that is compatible with smart accounts. We use zerodev, but Pimlico, Coinbase and many others will work too.
BUNDLER_RPC_URL=your_rpc_url
# Keypo smart contracts:
REGISTRY_ADDRESS=0x8370eE1a51B5F31cc10E2f4d786Ff20198B10BBE
VALIDATION_ADDRESS=0x35ADB6b999AbcD5C9CdF2262c7190C7b96ABcE4C
# Filecoin RPC URL for paying for storage
FILECOIN_RPC_URL=https://api.calibration.node.glif.io/rpc/v1
FILECOIN_NETWORK=calibrationQuick Start Example
Create index.js:
import { Synapse } from '@filoz/synapse-sdk';
import { SynapseStorageSDK } from '@keypo/synapse-storage-sdk';
import { ethers } from 'ethers';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
// Initialize Synapse
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
const provider = new ethers.JsonRpcProvider(process.env.FILECOIN_NETWORK);
const signer = wallet.connect(provider);
const synapse = await Synapse.create({
signer,
withCDN: true,
});
// Initialize Keypo SDK
const sdk = new SynapseStorageSDK(synapse, {
network: process.env.FILECOIN_NETWORK,
rpcUrl: process.env.FILECOIN_RPC_URL,
encryption: {
registryAddress: process.env.REGISTRY_ADDRESS,
validationAddress: process.env.VALIDATION_ADDRESS,
bundlerRpcUrl: process.env.BUNDLER_RPC_URL
},
storage: {
capacityGB: parseInt(process.env.STORAGE_CAPACITY_GB) || 10,
persistenceDays: parseInt(process.env.STORAGE_PERSISTENCE_DAYS) || 30,
withCDN: process.env.STORAGE_WITH_CDN !== 'false'
}
}, process.env.PRIVATE_KEY);
// Upload encrypted file
const fileData = new TextEncoder().encode("Hello, Filecoin!");
const result = await sdk.upload(fileData, {
fileName: 'hello.txt',
isPublic: false, // Private - requires NFT to decrypt
onProgress: (progress) => console.log(progress.message)
});
console.log('File uploaded:', result.pieceCid);
console.log('Data identifier:', result.dataIdentifier);
// Download the file
const downloaded = await sdk.download(result.pieceCid, {
decrypt: true,
onProgress: (progress) => console.log(progress.message)
});
console.log('Downloaded:', new TextDecoder().decode(downloaded.data));
}
main().catch(console.error);Run it:
node index.jsWhat’s Next?
- Configuration - Learn about SDK configuration options
- Concepts - Understand core concepts like access control and file modes
- Functions - Explore all available SDK methods
Common Use Cases
Public File Storage: Upload files that anyone can decrypt (great for content distribution)
Private Document Sharing: Upload private files and share access via NFT minting
File Management: List, download, and manage your stored files with full metadata