description |
---|
The Token API allows you to easily get token information, minimizing the number of necessary requests. |
{% hint style="info" %} Unless otherwise specified, Alchemy methods will return decoded values in their responses (e.g., for token decimals, 18 will be returned instead of "0x12"). We plan to eventually normalize all methods in our enhanced API to return decoded values. {% endhint %}
Returns the amount which the spender is allowed to withdraw from the owner.
Object
- An object with the following fields:contract
:DATA
, 20 Bytes - The address of the token contract.owner
:DATA
, 20 Bytes - The address of the token owner.spender
:DATA
, 20 Bytes - The address of the token spender.
String
- The allowance amount.
Request
{% tabs %} {% tab title="Curl" %}
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"alchemy_getTokenAllowance","params":[{"contract":"0xE41d2489571d322189246DaFA5ebDe1F4699F498", "owner":"0xe8095A54C83b069316521835408736269bfb389C", "spender":"0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db"}],"id": 1}'
{% endtab %}
{% tab title="Postman" %}
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"alchemy_getTokenAllowance",
"params":[{"contract":"0xE41d2489571d322189246DaFA5ebDe1F4699F498", "owner":"0xe8095A54C83b069316521835408736269bfb389C", "spender":"0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db"}],
"id":83
}
{% endtab %} {% endtabs %}
Result
{
"jsonrpc": "2.0",
"id": 83,
"result": "10963536149943846000",
}
Returns token balances for a specific address given a list of contracts.
{% hint style="warning" %}
This method returns hex encoded values in the tokenBalance
fields.
{% endhint %}
DATA
, 20 Bytes - The address for which token balances will be checked- One of:
Array
- A list of contract addresses- The
String
"DEFAULT_TOKENS" - denotes a query for the top 100 tokens by 24 hour volume
Object
- An object with the following fields:
address
:DATA
, 20 Bytes - The address for which token balances were checkedtokenBalances
:Array
- returns an array of token balance objects. Each object contains:contractAddress
tokenBalance
error
- One of
tokenBalance
orerror
will be null.
Request
{% tabs %} {% tab title="Curl" %}
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"alchemy_getTokenBalances","params": ["0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be", ["0x607f4c5bb672230e8672085532f7e901544a7375", "0x618e75ac90b12c6049ba3b27f5d5f8651b0037f6", "0x63b992e6246d88f07fc35a056d2c365e6d441a3d", "0x6467882316dc6e206feef05fba6deaa69277f155", "0x647f274b3a7248d6cf51b35f08e7e7fd6edfb271"]],"id":"42"}'
{% endtab %}
{% tab title="Postman" %}
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"alchemy_getTokenBalances",
"params":["0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be", ["0x607f4c5bb672230e8672085532f7e901544a7375", "0x618e75ac90b12c6049ba3b27f5d5f8651b0037f6", "0x63b992e6246d88f07fc35a056d2c365e6d441a3d", "0x6467882316dc6e206feef05fba6deaa69277f155", "0x647f274b3a7248d6cf51b35f08e7e7fd6edfb271"]],
"id":42
}
{% endtab %} {% endtabs %}
Result
{
"jsonrpc":"2.0",
"id":42,
"result": {
"address": "0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be"},
"tokenBalances": [{"contractAddress": "0x607f4c5bb672230e8672085532f7e901544a7375", "tokenBalance": "0x00000000000000000000000000000000000000000000000000044d06e87e858e", "error": null}, {"contractAddress": "0x618e75ac90b12c6049ba3b27f5d5f8651b0037f6", "tokenBalance": "0x0000000000000000000000000000000000000000000000000000000000000000", "error": null}, {"contractAddress": "0x63b992e6246d88f07fc35a056d2c365e6d441a3d", "tokenBalance": "0x0000000000000000000000000000000000000000000000000000000000000000", "error": null}, {"contractAddress": "0x6467882316dc6e206feef05fba6deaa69277f155", "tokenBalance": "0x0000000000000000000000000000000000000000000000000000000000000000", "error": null}, {"contractAddress": "0x647f274b3a7248d6cf51b35f08e7e7fd6edfb271", "tokenBalance": "0x0000000000000000000000000000000000000000000000000000000000000000", "error": null}]
}
Returns metadata (name, symbol, decimals, logo) for a given token contract address.
name
,symbol
anddecimals
are optional methods in the ERC-20 token standard. Therefore, not all contracts will respond correctly to calls requesting this information. While the incorrectness or absence ofname
and symbol
can be an inconvenience, having the correct decimals
is absolutely crucial in displaying token balances or converting user inputs accurately when communicating with the contract.
Alchemy maintains a regularly updated database of contract metadata, with values gathered and intelligently merged from the contracts themselves along with several other sources. Alchemy is therefore able to provide clean, accurate, up-to-date metadata for contracts that may be missing any of these methods or have changed their name or symbol since contract publication.
As a bonus, token logo images are available for many of the popular tokens.
DATA
, 20 Bytes - The address of the token contract.
Object
- An object with the following fields:
name
:String
- The token's name.null
if not defined in the contract and not available from other sources.symbol
:String
- The token's symbol.null
if not defined in the contract and not available from other sources.decimals
:Number
- The number of decimals of the token.null
if not defined in the contract and not available from other sources.logo
:String
- URL of the token's logo image.null
if not available.
Request
{% tabs %} {% tab title="Curl" %}
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"alchemy_getTokenMetadata","params": ["0x1985365e9f78359a9B6AD760e32412f4a445E862"], "id": 1}'
{% endtab %}
{% tab title="Postman" %}
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"alchemy_getTokenMetadata",
"params":["0x1985365e9f78359a9B6AD760e32412f4a445E862"],
"id":1
}
{% endtab %} {% endtabs %}
Result
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"logo": "https://static.alchemyapi.io/images/assets/1104.png",
"symbol": "REP",
"decimals": 18,
"name": "Augur"
}
}