Token API Quickstart
A new developer’s guide to using the Token API and getting token information. Query Token data using alchemy-web3 (recommended) or fetch.
New CU Costs
Build and scale apps with lower CU costs on key APIs
With the Token API, you can retrieve token balances, metadata, and more.
Alchemy currently supports the following Token API Endpoints:
alchemy_getTokenAllowance
: Returns the amount which the sender is allowed to withdraw from the owner.alchemy_getTokenBalances
: Returns ERC20 token balances for all tokens the given address has ever transacted in with. Optionally accepts a list of contracts.alchemy_getTokenMetadata
: Returns metadata (name, symbol, decimals, logo) for a given token contract address.
Interested in token prices? Check out the Prices API.
Unless otherwise specified, Alchemy methods will return decoded values in their responses (e.g., for token decimals, 18 will be returned instead of “0x12”) to save you the extra step of decoding the value yourself ✅
How to Query the Token API
Alchemy SDK (Recommended)
Install the alchemy-sdk
module to easily interact with Alchemy APIs. We highly recommend the alchemy-sdk
for WebSocket support, retries, and more.
Check the Github repo here: https://github.com/alchemyplatform/alchemy-sdk-js
Installation
Run the following command to install alchemy-sdk
with npm
or yarn
Usage
And then paste the following code snippet into the file:
From your command line, you can execute the script with:
You should see output like this:
Node Fetch
node-fetch
is a lightweight, common module for making HTTP requests.
See the documentation for more info: https://www.npmjs.com/package/node-fetch
Installation
Run the following command to install node-fetch
with npm
or yarn
Usage
token-api-javascript-scripts/fetch-script.js at main · alchemyplatform/token-api-javascript-scripts
and then paste the following code snippet into the file to explore the getNFTs
method:=
From your command line, you can execute the script with:
Your output should look like the following:
API Reference
For more details on the available Token API methods, check out the docs: