Skip to content

getTokens

The getTokens function retrieves a list of tokens on Base by searching for the name, symbol, or address of a token.

The utility uses the Coinbase Developer Platform APIs to retrieve the token's data. To use the API, make sure to have an API_KEY and set this before using getTokens.

Usage

Search by symbol

code
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getTokens } from '@coinbase/onchainkit/token'; 
 
setOnchainKitConfig({ apiKey: 'YOUR_API_KEY' });
 
const tokens = await getTokens({ limit: '1', search: 'degen' }); 

Search by name

code
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getTokens } from '@coinbase/onchainkit/token'; 
 
setOnchainKitConfig({ apiKey: 'YOUR_API_KEY' });
 
const tokens = await getTokens({ limit: '1', search: 'Wrapped Ether' }); 

Search by address

code
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getTokens } from '@coinbase/onchainkit/token'; 
 
setOnchainKitConfig({ apiKey: 'YOUR_API_KEY' });
 
const tokens = await getTokens({
  limit: '1',
  search: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
}); 

Returns

Promise<GetTokensResponse>

Parameters

GetTokensOptions