Configuration
Configure the GrapevineClient with your network and authentication settings. The SDK supports two authentication methods: private key (for backend/scripts) and wagmi wallet adapter (for frontend dApps).
Authentication Methods
Method 1: Private Key (Backend/Scripts)
Best for server-side applications, scripts, and CLI tools.
import { GrapevineClient } from '@pinata/grapevine-sdk';
const grapevine = new GrapevineClient({
network: 'testnet', // or 'mainnet'
privateKey: process.env.PRIVATE_KEY
});Method 2: Wagmi Adapter (Frontend/dApps)
Best for React applications with wallet connection (MetaMask, WalletConnect, etc).
import { useGrapevine, useGrapevineReady } from '@pinata/grapevine-sdk/react';
import { useWalletClient } from 'wagmi';
function MyComponent() {
const { data: walletClient } = useWalletClient();
// Address is automatically extracted from walletClient.account.address
const grapevine = useGrapevine({
walletClient,
network: 'testnet'
});
const isReady = useGrapevineReady(grapevine);
// Use grapevine client when ready...
}Configuration Options
network
- Type:
'testnet' | 'mainnet' - Default:
'testnet'
Network to connect to:
'testnet'- Base Sepolia testnet (api.grapevine.markets)'mainnet'- Base mainnet (api.grapevine.fyi)
const grapevine = new GrapevineClient({
network: 'mainnet'
});privateKey
- Type:
string - Required: For write operations (when not using wagmi)
- Format: Must start with
0xand be 66 characters
Wallet private key for authentication.
const grapevine = new GrapevineClient({
network: 'testnet',
privateKey: '0x...'
});walletAdapter
- Type:
WalletAdapter - Required: For write operations (when not using privateKey)
- Usage: Pass wagmi wallet client through adapter
Wallet adapter for browser wallet integration.
import { WagmiAdapter } from '@pinata/grapevine-sdk/adapters';
// Address is automatically extracted from walletClient.account.address
const adapter = new WagmiAdapter(walletClient);
const grapevine = new GrapevineClient({
network: 'testnet',
walletAdapter: adapter
});debug
- Type:
boolean - Default:
false
Enable detailed logging for requests and responses.
const grapevine = new GrapevineClient({
network: 'testnet',
privateKey: '0x...',
debug: true // Logs all API calls
});Wagmi Integration
Setup with React
Complete example of wagmi integration in a React app:
import { useGrapevine, useGrapevineReady } from '@pinata/grapevine-sdk/react';
import { useWalletClient, useAccount } from 'wagmi';
export function GrapevineApp() {
const { data: walletClient } = useWalletClient();
const { isConnected } = useAccount();
// Initialize Grapevine with wagmi
// Address is automatically extracted from walletClient.account.address
const grapevine = useGrapevine({
walletClient,
network: 'testnet'
});
// Check if client is ready
const isReady = useGrapevineReady(grapevine);
const createFeed = async () => {
if (!isReady) return;
const feed = await grapevine.feeds.create({
name: 'My Feed',
description: 'Created with wagmi'
});
console.log('Created feed:', feed);
};
return (
<div>
{isConnected ? (
<button onClick={createFeed} disabled={!isReady}>
Create Feed
</button>
) : (
<p>Connect wallet to use Grapevine</p>
)}
</div>
);
}Manual Adapter Usage
For more control, create the adapter manually:
import { GrapevineClient } from '@pinata/grapevine-sdk';
import { WagmiAdapter } from '@pinata/grapevine-sdk/adapters';
// Assuming you have walletClient from wagmi
// Address is automatically extracted from walletClient.account.address
const adapter = new WagmiAdapter(walletClient);
const grapevine = new GrapevineClient({
network: 'testnet'
});
// Initialize auth with adapter
grapevine.initializeAuthWithAdapter(adapter);Private Key vs Wagmi
When to Use Private Key
✅ Use private key when:
- Building backend services or APIs
- Creating CLI tools or scripts
- Running automated tasks or cron jobs
- Testing in development environments
- Need consistent wallet address
- Content management systems
- Automated feed updaters
- Bot or scraper services
- CI/CD pipelines
When to Use Wagmi
✅ Use wagmi when:
- Building frontend dApps
- Users connect their own wallets
- Need wallet UI integration
- Supporting multiple wallet providers
- Building decentralized applications
- Social media dApps
- Content marketplaces
- Creator platforms
- User-generated content sites
Feature Comparison
| Feature | Private Key | Wagmi Adapter |
|---|---|---|
| Environment | Backend/Node.js | Frontend/Browser |
| Wallet Control | Full control | User controls |
| Security | Must secure key | User secures wallet |
| User Experience | No UI needed | Wallet UI integration |
| Transaction Signing | Automatic | User approves |
| Multiple Wallets | One per instance | User can switch |
| Setup Complexity | Simple | Requires wagmi setup |
Environment Variables
Use environment variables for secure configuration:
PRIVATE_KEY=0x_your_private_key_here
Network Configuration
The SDK automatically sets the API URL based on the network option:
| Network | API URL | Chain |
|---|---|---|
testnet | https://api.grapevine.markets | Base Sepolia (84532) |
mainnet | https://api.grapevine.fyi | Base (8453) |
// Testnet (default) - uses https://api.grapevine.markets
const grapevine = new GrapevineClient({
network: 'testnet',
privateKey: '0x...'
});
// Mainnet - uses https://api.grapevine.fyi
const grapevine = new GrapevineClient({
network: 'mainnet',
privateKey: '0x...'
});Late Authentication
Initialize client without authentication for read-only operations:
// No auth needed for reading
const grapevine = new GrapevineClient({
network: 'mainnet'
});
const feeds = await grapevine.feeds.list();
// Add auth later for writing (private key)
grapevine.initializeAuth(process.env.PRIVATE_KEY);
// Or add auth with wagmi adapter
const adapter = new WagmiAdapter(walletClient);
grapevine.initializeAuthWithAdapter(adapter);
// Now can write
const feed = await grapevine.feeds.create({ name: 'My Feed' });Network Mapping
| Network | API URL | Chain ID |
|---|---|---|
testnet | api.grapevine.markets | 84532 (Base Sepolia) |
mainnet | api.grapevine.fyi | 8453 (Base) |
Next Steps
- feeds.create() - Create your first feed
- entries.create() - Add content
- Installation - Setup guide