Get Started
Getting Started with Doppler V4 SDK
This section guides you through setting up and using the Doppler V4 SDK to interact with the latest version of the Doppler protocol.
Prerequisites
Node.js: Version
18.14
or highernpm or yarn: Package manager for installing dependencies
Web3 Provider: Access to Ethereum RPC endpoints (Infura, Alchemy, etc.)
Wallet: MetaMask or similar wallet for transaction signing
Installation
Install the Doppler V4 SDK package:
npm install doppler-v4-sdk
# or
yarn add doppler-v4-sdk
Basic Setup
1. Import the SDK
import {
ReadFactory,
ReadWriteFactory,
Lens,
DOPPLER_V4_ADDRESSES
} from 'doppler-v4-sdk';
2. Initialize Drift Client
The SDK uses Drift for blockchain interactions. Set up your Drift client with both read and write capabilities:
import { Drift } from 'drift';
// For read-only operations
const drift = new Drift({
rpcUrl: 'https://sepolia.base.org',
chainId: 84532 // Base Sepolia
});
// For read-write operations (with wallet)
const driftWithWallet = new Drift({
rpcUrl: 'https://sepolia.base.org',
chainId: 84532,
wallet: yourWalletProvider // MetaMask, WalletConnect, etc.
});
3. Get Protocol Addresses
// Get addresses for the current network
const chainId = 84532; // Base Sepolia (change to 8453 for Base Mainnet, 130 for Unichain Mainnet, etc.)
const addresses = DOPPLER_V4_ADDRESSES[chainId];
const airlockAddress = addresses.airlock;
Core Concepts
Factory Classes
The V4 SDK provides two main factory classes:
ReadFactory
: For querying protocol state and reading dataReadWriteFactory
: For creating tokens with hooks
Key V4 Features
Dynamic bonding curves: Custom hooks supporting dynamic bonding curves
Asset Lifecycle
Token Creation: Deploy new tokens with custom hooks
Price Discovery: Initial liquidity provision and price discovery phase
Trading: Enhanced trading with V4 features
Quick Start Examples
Reading Protocol Data
// Create a read factory instance
const factory = new ReadFactory(airlockAddress, drift);
// Get information about a deployed asset
const assetData = await factory.getAssetData(tokenAddress);
console.log('Asset details:', {
numeraire: assetData.numeraire,
governance: assetData.governance,
pool: assetData.pool,
migrationPool: assetData.migrationPool,
totalSupply: assetData.totalSupply.toString()
});
// Check module state
const moduleState = await factory.getModuleState(moduleAddress);
console.log('Module state:', moduleState);
Creating a New Token with Hooks
// Create a read-write factory instance
const factory = new ReadWriteFactory(airlockAddress, driftWithWallet);
// Define pre-deployment configuration
const preDeploymentConfig = {
integrator: integratorAddress,
userAddress: userAddress,
numeraire: numeraireAddress, // USDC, WETH, etc.
tokenConfig: {
name: "My V4 Token",
symbol: "MTK4",
decimals: 18
},
saleConfig: {
// Custom sale configuration
},
v4PoolConfig: {
// V4 pool configuration
},
vestingConfig: {
// Vesting configuration
},
governanceConfig: {
// Governance configuration
}
};
// Build the complete configuration
const { createParams, hook, token } = factory.buildConfig(
preDeploymentConfig,
addresses
);
// Simulate the creation transaction
const simulation = await factory.simulateCreate(createParams);
console.log('Gas estimate:', simulation.gasEstimate);
// Execute the creation transaction
const txHash = await factory.create(createParams);
console.log('Transaction hash:', txHash);
// Wait for transaction confirmation and get the deployed asset address
const receipt = await drift.waitForTransactionReceipt({ hash: txHash });
const createEvent = receipt.logs.find(log =>
log.topics[0] === '0x...' // Create event signature
);
const deployedTokenAddress = `0x${createEvent.topics[1].slice(26)}`;
console.log('Deployed token address:', deployedTokenAddress);
Using the Doppler Lens for Advanced Queries
After creating your token, you can use the DopplerLensQuoter to get detailed information about your pool:
// Get the asset data to find the pool information
const assetData = await factory.getAssetData(deployedTokenAddress);
// Create a doppler lens instance
const lens = new ReadDopplerLens(addresses.dopplerLensQuoter, drift);
// Define pool key for the created token
const poolKey = {
currency0: assetData.numeraire,
currency1: deployedTokenAddress,
fee: 20_000, // 2% fee tier
tickSpacing: 2,
hooks: assetData.hook // Hook address from asset data
};
// Get comprehensive pool state data
const poolData = await lens.quoteDopplerLensData({
poolKey,
zeroForOne: true,
exactAmount: 1n, // Minimal amount for state query
hookData: "0x"
});
console.log('Pool state:', {
sqrtPriceX96: poolData.sqrtPriceX96.toString(),
tick: poolData.tick,
totalToken0: poolData.amount0.toString(),
totalToken1: poolData.amount1.toString()
});
Environment Configuration
Required Environment Variables
# RPC Endpoint
RPC_URL="https://sepolia.base.org"
# Wallet Private Key (for automated transactions)
PRIVATE_KEY="your-private-key"
# Network Configuration
CHAIN_ID=84532
Network Support
The V4 SDK supports multiple networks:
Base Sepolia (chainId: 84532) - Testnet
Base Mainnet (chainId: 8453) - Production
Unichain Mainnet (chainId: 130) - Production
Unichain Sepolia (chainId: 1301) - Testnet
Ink (chainId: 57073) - Production
For complete network addresses and additional supported networks, see the Contract Addresses documentation.
You can get free Base Sepolia ETH from the Base Sepolia faucet to test your applications.
Error Handling
The SDK provides comprehensive error handling for V4-specific scenarios:
try {
const { createParams } = factory.buildConfig(config, addresses);
} catch (error) {
if (error.message.includes('Invalid tick range')) {
console.log('Tick range is invalid for the specified fee tier');
} else if (error.message.includes('Hook mining failed')) {
console.log('Could not find suitable hook address');
} else {
console.error('Unexpected error:', error);
}
}
Next Steps
Explore the Factory Reference for detailed API documentation
Learn about Doppler Lens Usage for advanced data querying
Understand Quoter Usage for price calculations
Review Token Launch Examples for comprehensive deployment scenarios
Support
For additional help and examples:
Check the Token Launch Examples for comprehensive deployment scenarios
Review the Implementation Guide for protocol details
Join the community for discussions and support
Last updated