A comprehensive TypeScript library for managing token lists with built-in validation and utilities. Built on top of the Uniswap token list standard.
- π Token lookup by chain ID, address, or symbol
- β¨ Type-safe token validation using Zod schemas
- π Type-safe utilities with full TypeScript support
- π Comprehensive token list management tools
npx create-tokenlist project-name
npm run list:validate
After running the npx command to create your tokenlist project, you'll need to customize it to fit your specific requirements:
-
Change the project name: Update the
name
field in thepackage.json
file to reflect your project's name. -
Customize the token list: Modify the token list in your project to include the tokens relevant to your use case.
-
Set up npm publishing: To publish your bundled version on npm:
- Ensure you have an npm account and are logged in (
npm login
). - Update the
version
field inpackage.json
when making changes. - Run
npm publish
to publish your package. - Or create a repository, and set up a github action
- Ensure you have an npm account and are logged in (
-
Configure CI/CD (optional): Set up a CI/CD pipeline to automate the build, test, and publish process (e.g semantic-release)
Remember to thoroughly test your customized tokenlist before publishing to ensure it meets your specific needs and maintains the integrity of the original library.
The package includes a powerful CLI tool for managing your token list. You can use it to add/remove tokens and manage tags interactively.
npm run cli
The CLI provides the following options:
-
Add a token
- Interactively add a new token to the list
- Required fields:
- Chain ID: search for a network name
- Token address (0x-prefixed Ethereum address)
- Token name (prefilled given a correct address)
- Token symbol (prefilled given a correct address)
- Decimals (0-18) (prefilled given a correct address)
- Optional fields:
- Logo URI
- Tags (select from existing tags using checkbox interface)
-
Remove a token
- Search for tokens by symbol
- Select the specific token to remove from search results
- Automatically updates all references
-
Add a tag
- Create a new tag with:
- Tag identifier (1-10 alphanumeric characters and underscores)
- Tag name (1-20 characters)
- Tag description (1-200 characters)
- Validates input according to schema rules
- Prevents duplicate tag identifiers
- Create a new tag with:
-
Remove tags
- Multi-select interface to choose tags to remove
- Automatically removes selected tags from:
- The main tags registry
- Any tokens that were using those tags
- Provides feedback on the operation
# Start the CLI
npm run cli
# Choose "Add a token" and follow the prompts:
> Enter chain ID: 1
> Enter token address: 0x...
> Enter token name: My Token
> Enter token symbol: MTK
> Enter decimals: 18
> Enter logo URI (optional): https://...
> Select tags (if any exist): [x] stablecoin [ ] defi
# Choose "Add a tag" and follow the prompts:
> Enter tag identifier: defi
> Enter tag name: DeFi Token
> Enter tag description: Tokens used in decentralized finance applications
import { isToken, isListedToken } from '@yourorg/yourlist';
// Validate if an object matches the TokenInfo interface
isToken(tokenObject);
// Check if a token is listed in the tokenlist
isListedToken(tokenObject);
import {
getTokenByChainAndAddress,
getTokenByChainAndSymbol,
getChainTokenList
} from '@yourorg/yourlist';
// Get token by chain ID and address
const token = getTokenByChainAndAddress(1, '0x...');
// Get token by chain ID and symbol
const usdcToken = getTokenByChainAndSymbol(1, 'USDC');
// Get all tokens for a specific chain
const ethereumTokens = getChainTokenList(1);
// Get tokens with specific tags
const currencyTokens = getChainTokenList(1, ['currency']);
For functional programming enthusiasts, curried versions of the lookup functions are available:
import {
getTokenByChainAndAddressCurried,
getTokenByChainAndSymbolCurried
} from '@yourorg/yourlist';
const getEthereumToken = getTokenByChainAndAddressCurried(1);
const token = getEthereumToken('0x...');
const getEthereumTokenBySymbol = getTokenByChainAndSymbolCurried(1);
const usdcToken = getEthereumTokenBySymbol('USDC');
import { isAddressEqual, isTokenEqual } from '@yourorg/yourlist';
// Compare Ethereum addresses case-insensitively
isAddressEqual(address1, address2);
// Compare tokens based on chainId and address
isTokenEqual(tokenA, tokenB);
- Node.js >= 18
- npm >= 9
Tokens follow the Uniswap Token List standard:
interface TokenInfo {
chainId: number;
address: string;
name: string;
symbol: string;
decimals: number;
logoURI?: string;
tags?: string[];
extensions?: Record<string, any>;
}
chainId
: Must be a positive integeraddress
: Must be a valid Ethereum address (0x-prefixed, 40 hex characters)name
: 1-60 characters, must contain non-whitespace characterssymbol
: 1-20 characters, no whitespacedecimals
: Integer between 0 and 255logoURI
: Optional, must be a valid URL if providedtags
: Optional, maximum 10 tags
# Clone the repository
git clone https://github.com/tokdaniel/tokenlist.git
cd tokenlist
# Install dependencies
npm install
# Run tests
npm test
# Run linter
npm run lint
# Format code
npm run format
npm run lint
- Run linter checksnpm run format
- Format code using Biomenpm run test
- Run test suitenpm run coverage
- Generate test coverage reportnpm run list:validate
- Validate token listnpm run list:build
- Build token listnpm run list:bundle
- Bundle package for distribution
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
We follow the Conventional Commits specification:
feat:
- New featuresfix:
- Bug fixesdocs:
- Documentation changesstyle:
- Code style changes (formatting, etc.)refactor:
- Code refactoringtest:
- Adding or modifying testschore:
- Maintenance tasks
This project is licensed under the MIT License - see the LICENSE file for details.