Charging Fees with Bungee
Bungee allows integrators to charge fees on swaps and transfers, providing a revenue stream for your application. This guide explains how to implement fee charging in both Bungee Auto and Bungee Manual integrations.
If you plan to implement fee charging, please request a dedicated API key first.
Fee Mechanics
API Reference: Quote
When integrating Bungee, you can specify two key parameters to collect fees:
feeTakerAddress
: The address that will receive the collected feesfeeBps
: The percentage of the transfer amount to charge as a fee (in basis points - 1 basis point = 0.01%)
These parameters ensure that a portion of each swap is directed to your specified feeTaker address. The input token amount will be reduced by the fee amount before the swap is executed.
Implementation
You can add fee parameters to both Bungee Auto and Manual integrations when requesting a quote:
/**
* This example demonstrates how to implement fee charging in a Bungee integration
*/
// Configuration
const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange";
/**
* Get a quote with fee parameters
* @param {Object} params - The parameters for the quote request
* @returns {Promise<Object>} The quote response
*/
async function getQuoteWithFees() {
// Set up the parameters for the quote request
const quoteParams = {
userAddress: "0xYourUsersAddress",
originChainId: "1", // Ethereum
destinationChainId: "10", // Optimism
inputToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
outputToken: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607", // USDC on Optimism
inputAmount: "1000000", // 1 USDC (6 decimals)
receiverAddress: "0xYourUsersAddress",
feeTakerAddress: "0xYourFeeCollectionAddress", // Address to receive fees
feeBps: "50", // 0.5% fee (50 basis points)
};
// For Manual mode, add this parameter
// quoteParams.enableManual = "true";
// Build the URL with query parameters
const url = `${BUNGEE_API_BASE_URL}/api/v1/bungee/quote`;
const queryParams = new URLSearchParams(quoteParams);
const fullUrl = `${url}?${queryParams}`;
// Make the request
const response = await fetch(fullUrl, { method: "GET" });
const data = await response.json();
const serverReqId = response.headers.get("server-req-id");
if (!data.success) {
throw new Error(
`Quote error: ${data.statusCode}: ${data.message}. server-req-id: ${serverReqId}`
);
}
return data.result;
}
Where to Claim Fees
For Bungee Manual, no need to claim as fees are delivered directly to the feeTakerAddress
provided.
For Bungee Auto, fees are sent to the FeeCollector
contract where anyone can trigger the claim fees for a specified token address and feeTakerAddress
pair.
Since it may be difficult to track all the different token addresses that go into the FeeCollector
address on a specific chain, we've developed a utility script that tracks balances across all networks. For per‑chain FeeCollector
addresses, see the Contract Addresses page. The FeeCollector
exposes a claim(address token, address feeTaker)
method to withdraw accrued fees.
You may access a ready to run version of the script on this public repository.
The script performs the following operations:
- Fetches fee collector balances: Uses
getFeeCollectorBalancesIndividually()
to get token lists from fee collectors across all networks - Checks target address: Uses
getTokenBalancesForNetwork()
to check the same tokens for the provided address - Shows results: Displays only tokens with balances > 0
For customization and advanced options, see the README in the tokens-in-fee-collector repository. If you need project‑specific behavior, fork the repo and document the changes you adopt here.
Example Output
Getting token balances for address: 0x0e15a0774307e422a0Dd3001030aB1501D320E63
Fetching fee collector balances to get token lists...
Error for hyperEvm: { error: { message: 'Unsupported network: hyperevm-mainnet' } }
Error for katana: { error: { message: 'Unsupported network: katana-mainnet' } }
Checking token balances for the provided address...
arbitrum: Found 48 tokens
0x0c880f6761f1af8d9aa9c466984b80dab9a8c9e8: 146253312486944439
0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60: 1306666346595927049
0x2416092f143378750bb29b79ed961ab195cceea5: 87400068846065
base: Found 73 tokens
0x0484e9fdcccf9d62fad6d4cd7ba085e2efc531a1: 1000000000000000000
0x04d5ddf5f3a8939889f11e97f8c4bb48317f1938: 11903498846250567868
- avalanche: No tokens found
- berachain: No tokens found
- blast: No tokens found
bsc: Found 34 tokens
0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82: 334496873785373422
0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3: 1388223867624191913
hyperEvm: Error - {"error":{"message":"Unsupported network: hyperevm-mainnet"}}