Skip to main content

Token Endpoints

info

Bungee Auto supports trading any token with sufficient liquidity, regardless of whether it appears in the token list responses.

This page covers how to use the token-related endpoints in the Bungee API.

The tokens returned by the /tokens/list endpoint represent commonly used tokens, but this is not a comprehensive list of all tradable tokens. If you want to trade a specific token that doesn't appear in the list, you can:

  1. Use the /tokens/search endpoint to verify if Bungee recognizes it as a valid token
  2. Proceed with creating a quote using that token address if it has liquidity

Token list endpoint example usage​

The /tokens/list endpoint retrieves a list of available tokens, with optional parameters to customize the response.

API Reference: Token List Endpoint

async function getTokenList(userAddress, chainIds = [1], isTrending = true) {
const url = `https://public-backend.bungee.exchange/tokens/list`;
const params = {
userAddress,
chainIds: chainIds.join(","),
list: isTrending ? "trending" : "full",
};

const queryParams = new URLSearchParams(params);
const response = await fetch(`${url}?${queryParams}`);
const data = await response.json();

return data;
}

Token search endpoint example usage​

The /tokens/search endpoint allows you to search for tokens by address, name, or symbol. Use this endpoint to verify if a specific token can be traded, even if it doesn't appear in the token list.

API Reference: Token Search Endpoint

async function searchToken(query, userAddress) {
const url = `https://public-backend.bungee.exchange/tokens/search`;
const params = {
q: query,
userAddress,
};

const queryParams = new URLSearchParams(params);
const response = await fetch(`${url}?${queryParams}`);
const data = await response.json();

return data;
}

Complete Integration Example​

import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);
console.log("Account address:", account.address);

const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange";

// Search for a token (by address, symbol, or name)
async function tokenSearch(query, userAddress) {
try {
const url = `${BUNGEE_API_BASE_URL}/tokens/search`;
const params = {
q: query,
userAddress,
};

const queryParams = new URLSearchParams(params);
const response = await fetch(`${url}?${queryParams}`);
const data = await response.json();
const serverReqId = response.headers.get("server-req-id");

if (!data.success) {
throw new Error(
`Search error: ${data.statusCode}: ${data.message}. server-req-id: ${serverReqId}`
);
}

return {
result: data.result,
serverReqId,
};
} catch (error) {
console.error("Failed to search for token:", error);
throw error;
}
}

// Get token list (trending or complete)
async function tokenList({
userAddress = "",
chainIds = [],
isTrending = null,
} = {}) {
try {
const url = `${BUNGEE_API_BASE_URL}/tokens/list`;
const params = {};

// Only add parameters if they have values
if (userAddress) {
params.userAddress = userAddress;
}

if (chainIds && chainIds.length > 0) {
params.chainIds = chainIds.join(",");
}

// Only add list parameter if isTrending is explicitly specified
if (isTrending !== null) {
params.list = isTrending ? "trending" : "complete";
}

const queryParams = new URLSearchParams(params);
const response = await fetch(`${url}?${queryParams}`);
const data = await response.json();
const serverReqId = response.headers.get("server-req-id");

if (!data.success) {
throw new Error(
`List error: ${data.statusCode}: ${data.message}. server-req-id: ${serverReqId}`
);
}

return {
result: data.result,
serverReqId,
};
} catch (error) {
console.error("Failed to get token list:", error);
throw error;
}
}

// Usage examples
(async () => {
try {
let searchResponse;
// Search for USDC
searchResponse = await tokenSearch("USDC", account.address);
console.log(
"Search results:",
JSON.stringify(searchResponse.result, null, 2)
);

// Search for a token address
searchResponse = await tokenSearch(
"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
account.address
);
console.log(
"Search results:",
JSON.stringify(searchResponse.result, null, 2)
);

// Search for a partial token name
searchResponse = await tokenSearch("Bridged USD Coin", account.address);
console.log(
"Search results:",
JSON.stringify(searchResponse.result, null, 2)
);

// Search for a inexisting token
searchResponse = await tokenSearch("0x123...abc", account.address);
if (Object.keys(searchResponse.result.tokens).length === 0) {
console.log(
"The tokens object is empty, but you can still try to trade this token if it has liquidity"
);
}

let trendingResponse;
// Get trending tokens on Ethereum and Arbitrum
trendingResponse = await tokenList({
userAddress: account.address,
chainIds: [1, 42161],
isTrending: true,
});
console.log(
"Trending tokens:",
JSON.stringify(trendingResponse.result, null, 2)
);

// Get complete token list for Optimism with account balances
trendingResponse = await tokenList({
userAddress: account.address,
chainIds: [10],
isTrending: false,
});
console.log(
"Complete token list:",
JSON.stringify(trendingResponse.result, null, 2)
);

// Get complete token list with account balances
trendingResponse = await tokenList({ userAddress: account.address });
console.log(
"Complete token list:",
JSON.stringify(trendingResponse.result, null, 2)
);

// Get trending token list for Optimism
trendingResponse = await tokenList({ chainIds: [10] });
console.log(
"Trending token list for Optimism:",
JSON.stringify(trendingResponse.result, null, 2)
);

// Get complete token list
trendingResponse = await tokenList({ isTrending: false });
console.log(
"Complete token list:",
JSON.stringify(trendingResponse.result, null, 2)
);

// Get trending token list for all chains
trendingResponse = await tokenList();
console.log(
"Default token list:",
JSON.stringify(trendingResponse.result, null, 2)
);
} catch (error) {
console.error("Error:", error.message);
}
})();

This integration provides you with the tools to search for tokens and retrieve token lists from the Bungee API, with optional parameters to customize the responses based on your needs.