Claim Rewards
Execute on-chain claims to collect trading fees from your tokens.
Overview
The /claim endpoint allows you to execute an on-chain transaction that collects accumulated trading fees from Uniswap V4 liquidity positions and distributes them to the appropriate recipients.
Key Features:
- Actually executes the claim transaction on Base
- Distributes token rewards to
feeReceiver - Distributes ETH rewards to
factoryCreator - Returns transaction hash for verification
- Waits for confirmation before responding
Endpoint
POST /claimNetwork: Base Mainnet (Chain ID: 8453)
Request
Headers
Content-Type: application/jsonRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
tokenAddress | string | Yes | Token contract address on Base |
apiKey | string | Yes | Your Digifi API key |
Example Request
curl -X POST https://api.digifi.fun/claim \
-H "Content-Type: application/json" \
-d '{
"tokenAddress": "0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
"apiKey": "dg_YOUR_API_KEY_HERE"
}'Response
Success Response (200)
{
"success": true,
"message": "Rewards claimed successfully",
"tokenAddress": "0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
"tokenName": "MyToken",
"tokenSymbol": "MTK",
"lpTokenId": "12345",
"network": {
"name": "base",
"chainId": "8453"
},
"transaction": {
"hash": "0xabc123...",
"blockNumber": 12345678,
"gasUsed": "150000",
"effectiveGasPrice": "1000000000"
},
"claimedRewards": {
"tokenRewards": "1.5",
"tokenRewardsWei": "1500000000000000000",
"ethRewards": "0.05",
"ethRewardsWei": "50000000000000000",
"feeReceiver": "0x...",
"factoryCreator": "0x..."
},
"claimedBy": "username",
"claimedAt": "2025-11-08T12:00:00.000Z"
}Error Response - LP Not Initialized (400)
{
"success": false,
"error": "LP not initialized",
"message": "Cannot claim rewards - LP not yet initialized for this token"
}Error Response - Transaction Failed (500)
{
"success": false,
"error": "Failed to claim rewards",
"details": "Detailed error message here"
}Response Fields
Success Response
| Field | Type | Description |
|---|---|---|
success | boolean | Always true for successful claims |
message | string | Human-readable success message |
tokenAddress | string | The token contract address |
tokenName | string | Name of the token |
tokenSymbol | string | Symbol of the token |
lpTokenId | string | Uniswap V4 position NFT ID |
network.name | string | Network name ("base") |
network.chainId | string | Chain ID ("8453") |
transaction.hash | string | Transaction hash on Basescan |
transaction.blockNumber | number | Block number where transaction was included |
transaction.gasUsed | string | Gas consumed by the transaction |
transaction.effectiveGasPrice | string | Gas price in wei |
claimedRewards.tokenRewards | string | Token rewards in human-readable format |
claimedRewards.tokenRewardsWei | string | Token rewards in wei |
claimedRewards.ethRewards | string | ETH rewards in human-readable format |
claimedRewards.ethRewardsWei | string | ETH rewards in wei |
claimedRewards.feeReceiver | string | Address that received token rewards |
claimedRewards.factoryCreator | string | Address that received ETH rewards |
claimedBy | string | Username who initiated the claim |
claimedAt | string | ISO timestamp of the claim |
How Rewards Distribution Works
When you call /claim, the following happens:
-
Master Wallet Calls Contract
- The deployment wallet calls
get_rewards()on your token contract
- The deployment wallet calls
-
Contract Collects LP Fees
- Your token contract interacts with Uniswap V4
- Collects accumulated fees from the liquidity position
-
Automatic Distribution
- Token fees → Sent to
feeReceiveraddress (set during deployment) - ETH fees → Sent to
factoryCreatoraddress (master wallet)
- Token fees → Sent to
-
Transaction Confirmation
- API waits for on-chain confirmation
- Returns transaction details and claimed amounts
Trading Fees Accumulated in LP
↓
Master Wallet calls get_rewards()
↓
┌───────────────┐
│ Token Contract│
└───────────────┘
↓
┌───────┴───────┐
↓ ↓
Token Rewards ETH Rewards
↓ ↓
feeReceiver factoryCreatorCode Examples
JavaScript / Node.js (fetch)
const claimRewards = async (tokenAddress, apiKey) => {
try {
const response = await fetch("https://api.digifi.fun/claim", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
tokenAddress: tokenAddress,
apiKey: apiKey,
}),
});
const data = await response.json();
if (data.success) {
console.log("✅ Rewards claimed successfully!");
console.log(`Transaction Hash: ${data.transaction.hash}`);
console.log(`Token Rewards: ${data.claimedRewards.tokenRewards}`);
console.log(`ETH Rewards: ${data.claimedRewards.ethRewards}`);
console.log(
`View on Basescan: https://basescan.org/tx/${data.transaction.hash}`
);
return data;
} else {
console.error("❌ Claim failed:", data.error);
throw new Error(data.error);
}
} catch (error) {
console.error("Error claiming rewards:", error);
throw error;
}
};
// Usage
claimRewards(
"0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
process.env.DIGIFI_API_KEY
);JavaScript / Node.js (axios)
const axios = require("axios");
const claimRewards = async (tokenAddress, apiKey) => {
try {
const response = await axios.post("https://api.digifi.fun/claim", {
tokenAddress: tokenAddress,
apiKey: apiKey,
});
if (response.data.success) {
console.log("✅ Rewards claimed successfully!");
console.log(`Transaction Hash: ${response.data.transaction.hash}`);
console.log(
`Token Rewards: ${response.data.claimedRewards.tokenRewards}`
);
console.log(`ETH Rewards: ${response.data.claimedRewards.ethRewards}`);
return response.data;
}
} catch (error) {
console.error("❌ Error:", error.response?.data || error.message);
throw error;
}
};
// Usage
claimRewards(
"0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
process.env.DIGIFI_API_KEY
);Python
import requests
import os
def claim_rewards(token_address, api_key):
url = 'https://api.digifi.fun/claim'
payload = {
'tokenAddress': token_address,
'apiKey': api_key
}
try:
response = requests.post(url, json=payload)
response.raise_for_status()
data = response.json()
if data['success']:
print('✅ Rewards claimed successfully!')
print(f"Transaction Hash: {data['transaction']['hash']}")
print(f"Token Rewards: {data['claimedRewards']['tokenRewards']}")
print(f"ETH Rewards: {data['claimedRewards']['ethRewards']}")
print(f"View on Basescan: https://basescan.org/tx/{data['transaction']['hash']}")
return data
else:
print(f"❌ Claim failed: {data['error']}")
raise Exception(data['error'])
except requests.exceptions.RequestException as e:
print(f'Error claiming rewards: {e}')
if hasattr(e.response, 'json'):
print(e.response.json())
raise
# Usage
claim_rewards(
'0x553531A46CCd3F8c6DD6Fb3008D162115680d366',
os.getenv('DIGIFI_API_KEY')
)TypeScript
interface ClaimRequest {
tokenAddress: string;
apiKey: string;
}
interface ClaimResponse {
success: boolean;
message: string;
tokenAddress: string;
tokenName: string;
tokenSymbol: string;
lpTokenId: string;
network: {
name: string;
chainId: string;
};
transaction: {
hash: string;
blockNumber: number;
gasUsed: string;
effectiveGasPrice: string;
};
claimedRewards: {
tokenRewards: string;
tokenRewardsWei: string;
ethRewards: string;
ethRewardsWei: string;
feeReceiver: string;
factoryCreator: string;
};
claimedBy: string;
claimedAt: string;
}
const claimRewards = async (
tokenAddress: string,
apiKey: string
): Promise<ClaimResponse> => {
const response = await fetch("https://api.digifi.fun/claim", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
tokenAddress,
apiKey,
}),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || "Failed to claim rewards");
}
const data: ClaimResponse = await response.json();
if (data.success) {
console.log("✅ Rewards claimed successfully!");
console.log(`Transaction Hash: ${data.transaction.hash}`);
console.log(`Token Rewards: ${data.claimedRewards.tokenRewards}`);
console.log(`ETH Rewards: ${data.claimedRewards.ethRewards}`);
}
return data;
};
// Usage
claimRewards(
"0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
process.env.DIGIFI_API_KEY!
)
.then((data) =>
console.log(
`View transaction: https://basescan.org/tx/${data.transaction.hash}`
)
)
.catch((error) => console.error("Error:", error));Recommended Workflow
Best Practice: Check Before Claiming
Always check rewards before claiming to avoid wasting gas on empty claims:
// Step 1: Check if rewards exist
const checkResponse = await fetch(
`https://api.digifi.fun/checkRewards?tokenAddress=${tokenAddress}&apiKey=${apiKey}`
);
const checkData = await checkResponse.json();
// Step 2: Only claim if rewards are worth it
const minEthWorthClaiming = 0.001; // Adjust based on gas costs
const minTokenWorthClaiming = 1.0;
if (
parseFloat(checkData.pendingRewards.ethRewards) > minEthWorthClaiming ||
parseFloat(checkData.pendingRewards.tokenRewards) > minTokenWorthClaiming
) {
// Step 3: Execute claim
const claimResponse = await fetch("https://api.digifi.fun/claim", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tokenAddress: tokenAddress,
apiKey: apiKey,
}),
});
const claimData = await claimResponse.json();
console.log("✅ Claimed:", claimData.claimedRewards);
} else {
console.log("⏸️ Rewards too small, waiting for more accumulation");
}Full Integration Example
class TokenRewardsManager {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = "https://api.digifi.fun";
}
async checkRewards(tokenAddress) {
const response = await fetch(
`${this.baseUrl}/checkRewards?tokenAddress=${tokenAddress}&apiKey=${this.apiKey}`
);
return await response.json();
}
async claimRewards(tokenAddress) {
const response = await fetch(`${this.baseUrl}/claim`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tokenAddress,
apiKey: this.apiKey,
}),
});
return await response.json();
}
async smartClaim(tokenAddress, minEthThreshold = 0.001) {
// Check first
const check = await this.checkRewards(tokenAddress);
if (!check.success) {
throw new Error("Failed to check rewards");
}
const ethRewards = parseFloat(check.pendingRewards.ethRewards);
// Only claim if above threshold
if (ethRewards >= minEthThreshold) {
console.log(`Found ${ethRewards} ETH in rewards, claiming...`);
return await this.claimRewards(tokenAddress);
} else {
console.log(`Only ${ethRewards} ETH available, skipping claim`);
return { skipped: true, reason: "Below threshold", check };
}
}
}
// Usage
const manager = new TokenRewardsManager(process.env.DIGIFI_API_KEY);
// Smart claim (checks first, only claims if worthwhile)
const result = await manager.smartClaim(
"0x553531A46CCd3F8c6DD6Fb3008D162115680d366",
0.001 // Minimum 0.001 ETH to claim
);
if (result.success) {
console.log("Transaction:", result.transaction.hash);
}Important Notes
Gas Costs
- Who pays? The master wallet (deployment wallet) pays all gas fees
- Cost estimate: ~150,000 gas (varies by network congestion)
- You don't pay: Users calling this API endpoint don't pay gas
Transaction Time
- The API waits for transaction confirmation
- Typical response time: 5-30 seconds
- Depends on Base network congestion
- Don't timeout your HTTP client too early
Claiming Frequency
You can claim as often as you want, but consider:
- Gas efficiency: Wait for rewards to accumulate
- Optimal strategy: Check rewards first, claim when worthwhile
- Minimum threshold: Set a minimum value to make gas costs worthwhile
Verification
Always verify claims on Basescan:
https://basescan.org/tx/{TRANSACTION_HASH}You can see:
- Exact amounts transferred
- Gas used
- Block confirmation
- Recipient addresses
Error Handling
Common Errors
Missing Token Address
{
"error": "Missing tokenAddress parameter"
}Solution: Provide tokenAddress in request body
Invalid API Key
{
"error": "Invalid API key"
}Solution: Get your API key from digifi.fun/api-key (opens in a new tab)
LP Not Initialized
{
"success": false,
"error": "LP not initialized",
"message": "Cannot claim rewards - LP not yet initialized for this token"
}Solution: Wait for the token's LP to be fully initialized after deployment
Invalid Contract
{
"error": "Invalid contract",
"details": "Contract does not appear to be a SimpleToken with the expected interface"
}Solution: Ensure the token was deployed through Digifi's V4 factory
Transaction Failed
{
"success": false,
"error": "Failed to claim rewards",
"details": "Revert reason or error details"
}Solution: Check the error details. Common causes:
- Network congestion
- Contract state issues
- Insufficient gas (shouldn't happen, but possible)
Error Handling Example
async function safeClaimRewards(tokenAddress, apiKey) {
try {
const response = await fetch("https://api.digifi.fun/claim", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ tokenAddress, apiKey }),
});
const data = await response.json();
if (!response.ok) {
// Handle HTTP errors
switch (response.status) {
case 400:
console.error("Bad request:", data.error);
break;
case 401:
console.error("Authentication failed:", data.error);
break;
case 500:
console.error("Server error:", data.error);
break;
default:
console.error("Unknown error:", data);
}
throw new Error(data.error || "Claim failed");
}
if (!data.success) {
console.error("Claim unsuccessful:", data.error);
throw new Error(data.error);
}
return data;
} catch (error) {
console.error("Failed to claim rewards:", error.message);
throw error;
}
}Limitations
Rate Limits
- Standard API rate limits apply
- No specific limit on claim frequency
- Consider gas costs when claiming frequently
Network Requirements
- Only Base Mainnet (Chain ID: 8453)
- Token must be deployed via Digifi's V4 factory
- LP must be initialized
Token Requirements
The token contract must:
- Have
get_rewards()function - Be deployed through Digifi's factory
- Have an initialized LP position
Troubleshooting
Q: Why does claiming take so long?
A: The API waits for on-chain confirmation. Base blocks are ~2 seconds, so expect 5-30 seconds depending on confirmation requirements and network load.
Q: Can I claim for someone else's token?
A: No, you need the API key associated with the token deployment. Only the token creator can claim rewards.
Q: What if there are zero rewards?
A: The transaction will still execute successfully, but claimed amounts will be 0. Use /checkRewards first to avoid wasting gas.
Q: Who receives the rewards?
A:
- Token rewards →
feeReceiveraddress (set during deployment) - ETH rewards →
factoryCreatoraddress (master wallet)
Q: Can I customize the recipient addresses?
A: Not via the API. Addresses are determined at deployment time and stored in the contract.
Q: How often should I claim?
A: Wait for rewards to accumulate. Check rewards periodically, and claim when the amount justifies the gas cost.
Next Steps
- Check Rewards - View pending rewards without claiming
- Deploy Token - Create tokens with reward systems
- Error Handling - Handle API errors properly
Questions? Contact us at digifievm999@gmail.com
View transactions: BaseScan (opens in a new tab)