Setting Up Referrals
The DuckyDux referral program allows developers and integrators to earn passive income by integrating the DuckyDux API into their applications. Earn fees from every swap executed through your integration with no upfront investment required.
Earn Continuously: Once integrated, your referral address automatically earns fees from every swap made by users through your application or integration.
How Referrals Work
Get Your Referral ID
Your Ethereum address serves as your unique referral identifier - no registration required.
// Your referral ID is simply your Ethereum address
const myReferralId = '0x123...abc'Integrate the Referral Parameter
Add your address as a referral parameter to all DuckyDux API calls in your application:
API Integration
// Include referral in API calls
const swapQuote = await fetch('https://api.duckydux.com/v1/swap/quote?' + new URLSearchParams({
sources: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
sinks: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
supplies: '1000000000000000000',
demands: '-1',
slippage: '0.5',
sender: userAddress,
referral: '0x123...abc' // Your referral address
}));Automatic Fee Collection
When users complete swaps through your integration, you automatically earn a percentage of the swap fees. No action required on your part - fees are credited to your address automatically.
Track and Withdraw Earnings
Monitor your earnings and withdraw fees using the DuckyDux Affiliates API.
Referral Economics
Fee Structure
You earn a fixed 0.05% referral fee on the total volume of every swap made through your API integration. This fee is automatically collected and credited to your address.
| Fee Type | Rate | Example |
|---|---|---|
| Referral Fee | 0.05% | On a $10,000 swap, you earn $5. |
| Router Fee | 0.05% | DuckyDux collects a 0.05% router fee. |
| Total Fee | 0.1% | The user pays a total fee of 0.1% on the swap. |
Real-time Earnings Example
// Example: User swaps $10,000 worth through your referral
const swapVolume = 10000; // $10,000 USD
const referralFeeRate = 0.0005; // 0.05%
const earnings = swapVolume * referralFeeRate; // $5.00
console.log(`You earned: $${earnings} from this referral`);Implementation Guide
API Integration
Integrate referral tracking into your API calls:
async function getSwapQuoteWithReferral(swapParams, referralAddress) {
const params = new URLSearchParams({
...swapParams,
referral: referralAddress,
})
const response = await fetch(`https://api.duckydux.com/v1/swap/quote?${params}`)
return response.json()
}
// Usage
const quote = await getSwapQuoteWithReferral(
{
sources: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
sinks: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
supplies: '1000000000000000000',
demands: '-1',
slippage: '0.5',
sender: userAddress,
},
'0x123...abc'
)Advanced Integration
Build referral tracking into your own application:
React Hook
// React hook for referral management
import { useState, useEffect } from 'react';
export function useReferralTracking(referralAddress) {
const [earnings, setEarnings] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchEarnings();
}, [referralAddress]);
const fetchEarnings = async () => {
try {
const response = await fetch(
`https://api.duckydux.com/v1/affiliates/${referralAddress}/summary`
);
const data = await response.json();
setEarnings(data);
} catch (error) {
console.error('Failed to fetch earnings:', error);
} finally {
setLoading(false);
}
};
return { earnings, loading, refresh: fetchEarnings };
}Track Performance
Monitor your referral program effectiveness:
class ReferralAnalytics {
constructor(referralAddress) {
this.referralAddress = referralAddress
this.metrics = {
totalEarnings: 0,
totalVolume: 0,
referralCount: 0,
conversionRate: 0,
}
}
async updateMetrics() {
const earnings = await this.fetchEarnings()
const history = await this.fetchHistory()
this.metrics = {
totalEarnings: earnings.currentBalanceUsd,
totalVolume: this.calculateTotalVolume(history),
referralCount: history.items.length,
conversionRate: this.calculateConversionRate(history),
}
}
calculateTotalVolume(history) {
// The router fee is 0.05%, so we can estimate total volume from it.
const ROUTER_FEE_RATE = 0.0005
return history.items.reduce((total, item) => {
return total + item.routerFeeUsd / ROUTER_FEE_RATE
}, 0)
}
generateReport() {
return {
...this.metrics,
averageEarningsPerReferral: this.metrics.totalEarnings / this.metrics.referralCount,
effectiveRate: this.metrics.totalEarnings / this.metrics.totalVolume,
}
}
}Earnings Management
Multi-token Earnings: DuckyDux referral fees are earned in the same tokens as the swap fees - no need to convert to a single currency.
Check Your Balance
JavaScript
async function checkReferralBalance(referralAddress) {
const response = await fetch(
`https://api.duckydux.com/v1/affiliates/${referralAddress}/summary`
);
const summary = await response.json();
console.log('Total Earned (USD):', summary.totalEarnedUsd);
console.log('Current Balance (USD):', summary.currentBalanceUsd);
console.log('Balances by Token:', summary.balancesByToken);
return summary;
}Withdraw Earnings
Generate withdrawal transactions for your earned fees:
async function withdrawReferralFees(referralAddress, tokens, amounts) {
const response = await fetch(
`https://api.duckydux.com/v1/swap/fees/withdraw?` +
new URLSearchParams({
account: referralAddress,
tokens: tokens.join(','),
amounts: amounts.join(','),
})
)
const withdrawalTx = await response.json()
// Sign and submit the withdrawal transaction
const signedTx = await web3.eth.accounts.signTransaction(withdrawalTx, privateKey)
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log('Withdrawal successful:', receipt.transactionHash)
return receipt
}
// Example: Withdraw all USDC earnings
await withdrawReferralFees(
'0x123...abc',
['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'], // USDC
['1000000000'] // Amount to withdraw
)