Token

getTokenMetadata

Returns metadata (name, symbol, decimals, logo) for a given token contract address (asynchronous).

Options:

//Get metadata for one token
const options = { chain: "bsc", addresses: "0xe...556" };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(options);
​
​
//Get metadata for an array of tokens
const options = { chain: "bsc", addresses: ["0xe...556", "0xe...742"] };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(options);

Example result:

[
{
"address": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
"name": "Kylin Network",
"symbol": "KYL",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png",
"logo_hash": "ee7aa2cdf100649a3521a082116258e862e6971261a39b5cd4e4354fcccbc54d",
"thumbnail": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png",
"block_number": "string",
"validated": "string"
}
]

getTokenMetadataBySymbol

Returns metadata (name, address, decimals, logo) for given symbols (asynchronous).

Options:

//Get metadata for one token
const options = { chain: "bsc", symbols: "LINK" };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadataBySymbol(options);
​
​
//Get metadata for an array of tokens
const options = { chain: "bsc", symbols: ["LINK", "AAVE"] };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadataBySymbol(options);

Example result:

[
{
"address": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
"name": "Kylin Network",
"symbol": "KYL",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png",
"logo_hash": "ee7aa2cdf100649a3521a082116258e862e6971261a39b5cd4e4354fcccbc54d",
"thumbnail": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png",
"block_number": "string",
"validated": "string"
}
]

getTokenAllowance

Returns the amount which the spender is allowed to withdraw from the spender (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • owner_address (required): The address of the token owner

  • spender_address (required): The address of the token spender

  • address(required): The address of the token contract

//Get token allowace on ETH
const options = {
owner_address: "0xe...556",
spender_address: "0xe...556",
address: "0xe...556"
};
const allowance = await Moralis.Web3API.token.getTokenAllowance(options);

Example result:

{
"allowance": "string"
}

getTokenPrice

Returns the price nominated in the native token and usd for a given token contract address (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • exchange_name (optional): The factory name or address of the token exchange. Possible exchanges, for different chains are: ETH mainnet: uniswap-v3, sushiswap, uniswap-v2 BSC mainnet: pancakeswap-v2, pancakeswap-v1 Polygon mainnet: quickswap If no exchange_name is specified, all exchanges are checked (in the order as listed above) until a valid pool has been found. Note that this request can take more time. So specifying the exchange_name will result in faster responses most of the time.

  • address(required): The address of the token contract

//Get token price on PancakeSwap v2 BSC
const options = {
address: "0x7...2",
chain: "bsc",
exchange: "PancakeSwapv2"
};
const price = await Moralis.Web3API.token.getTokenPrice(options);

Example result:

{
"nativePrice": {
"value": "8409770570506626",
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"usdPrice": 19.722370676,
"exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"exchangeName": "Uniswap v3"
}

getERC721Metadata

Returns metadata (name, symbol) for a given token contract address (asynchronous).

Options:

const options = { address: "0x...2", chain: "bsc" };
const price = await Moralis.Web3API.token.getERC721Metadata(options);

Example result:

{
name: "Pancake Bunnies",
symbol: "PB",
token_uri: "ipfs://QmYu9WwPNKNSZQiTCDfRk7aCR472GURavR9M1qosDmqpev/sparkle.json"
}

getAllTokenIds

Returns an object with number of NFTs and an array with NFT metadata (name, symbol) for a given token contract address (asynchronous).

Options:

const options = { address: "0xd...07", chain: "bsc" };
const NFTs = await Moralis.Web3API.token.getAllTokenIds(options);

Example result:

[
{
"token_address": "0xdf7952b35f24acf7fc0487d01c8d5690a60dba07",
"token_id": "414742",
"contract_type": "ERC721",
"token_uri": "https://ipfs.moralis.io:2053/ipfs/QmYsTqbmGA3H5cgouCkh8tswJAQE1AsEko9uBZX9jZ3oTC/twinkle.json",
"metadata": "{\n\t\"name\": \"Twinkle\",\n\t\"description\": \"Three guesses what's put that twinkle in those eyes! (Hint: it's CAKE)\",\n\t\"image\": \"ipfs://QmYD9AtzyQPjSa9jfZcZq88gSaRssdhGmKqQifUDjGFfXm/twinkle.png\",\n\t\"attributes\": {\n\t\t\"bunnyId\": \"7\"\n\t}\n}",
"synced_at": null,
"amount": null,
"name": "Pancake Bunnies",
"symbol": "PB"
}
]

getNFTMetadata

Returns the contract level metadata (name, symbol, base token uri) for the given contract (asynchronous).

Options:

const options = { address: "0xd...07", chain: "bsc" };
const metaData = await Moralis.Web3API.token.getNFTMetadata(options);

Requests for contract addresses not yet indexed will automatically start the indexing process for that NFT collection

Example result:

{
token_address: "0xdf7952b35f24acf7fc0487d01c8d5690a60dba07",
name: "Pancake Bunnies",
symbol: "PB",
abi: null,
contract_type: "ERC721",
supports_token_uri: null,
synced_at: "2021-09-16",
}

getNFTOwners

Returns an object with number of NFT ownsers and an array with NFT metadata (name, symbol) for a given token contract address (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • format (optional): The format of the token id. Available values : decimal, hex. Default value : decimal.

  • offset (optional): offset.

  • limit(optional): limit.

  • order (optional): The field(s) to order on and if it should be ordered in ascending or descending order.

  • address(required): Address of the contract

const options = { address: "0xd...07", chain: "bsc" };
const nftOwners = await Moralis.Web3API.token.getNFTOwners(options);

The field(s) to order on and if it should be ordered in ascending or descending order. Specified by: fieldName1.order, fieldName2.order.

//Example 1: "name". Example for name: "name.ASC" or "name.DESC"
const options = { address: "0xd...07", order: "name.ASC" };
const nftOwners = await Moralis.Web3API.token.getNFTOwners(options);
​
//Example 2: "Name and Symbol"
const options = { address: "0xd...07", order: "name.ASC,symbol.DESC" };
const nftOwners = await Moralis.Web3API.token.getNFTOwners(options);

Make sure to include a sort parm on a column like block_number_minted for consistent pagination results

Requests for contract addresses not yet indexed will automatically start the indexing process for that NFT collection

Example result:

[
{
"token_address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"token_id": "15",
"contract_type": "ERC721",
"owner_of": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"block_number": "88256",
"block_number_minted": "88256",
"token_uri": "string",
"metadata": "string",
"synced_at": "string",
"amount": "1",
"name": "CryptoKitties",
"symbol": "RARI"
}
]

getContractNFTTransfers

Returns an object with number of NFT transfers and an array with NFT transfers for a given token contract address (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • format (optional): The format of the token id. Available values : decimal, hex. Default value is decimal.

  • offset (optional): offset.

  • limit(optional): limit.

  • order (optional): The field(s) to order on and if it should be ordered in ascending or descending order.

  • address(required): Address of the contract

const options = { address: "0xd...07", chain: "bsc" };
const nftTransfers = await Moralis.Web3API.token.getContractNFTTransfers(options);

The field(s) to order on and if it should be ordered in ascending or descending order. Specified by: fieldName1.order, fieldName2.order.

//Exmaple 1 "block_number": "block_number.ASC", "block_number.DESC",
const options = { address: "0xd...07", order: "name.ASC" };
const nftTransfers = await Moralis.Web3API.token.getContractNFTTransfers(options);
​
//Example 2 "block_number and contract_type": "block_number.ASC,contract_type.DESC"
const options = {
address: "0xd...07",
order: "block_number.ASC, contract_type.DESC"
}
const nftTransfers = await Moralis.Web3API.token.getContractNFTTransfers(options);

Example result:

[
{
"token_address": "0xdf7952b35f24acf7fc0487d01c8d5690a60dba07",
"token_id": "191123",
"from_address": "0x0000000000000000000000000000000000000000",
"to_address": "0xccbc6f1df01bad0f477fe085760571572d115eed",
"amount": "1",
"contract_type": "ERC721",
"block_number": "6827111",
"block_timestamp": "2021-04-23T22:25:35.000Z",
"block_hash": "0x79b8618df3d5b62ee4f230386284ea78037bc61f36418488db71564d2aca583c",
"transaction_hash": "0x9dedbb0fa63eba77634564ef6682826ccfdd1cb58be6e7b2f44cdf0aada07733",
"transaction_type": "Single",
"transaction_index": 129,
"log_index": 415
}
]

getTokenIdMetadata

Returns data, including fully resolved metadata for the given token id of the given contract address (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • format (optional): The format of the token id. Available values : decimal, hex. Default value is decimal.

  • address(required): Address of the contract

  • token_id (required): The id of the token

const options = { address: "0xd...07", token_id: "1", chain: "bsc" };
const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(options);

Example result:

{
"token_address": "0xdf7952b35f24acf7fc0487d01c8d5690a60dba07",
"token_id": "222",
"contract_type": "ERC721",
"token_uri": "ipfs://QmYu9WwPNKNSZQiTCDfRk7aCR472GURavR9M1qosDmqpev/sparkle.json",
"metadata": "{\n \"name\": \"Sparkle\",\n \"description\": \"It’s sparkling syrup, pancakes, and even lottery tickets! This bunny really loves it.\",\n \"image\": \"ipfs://QmXdHqg3nywpNJWDevJQPtkz93vpfoHcZWQovFz2nmtPf5/sparkle.png\",\n \"attributes\": {\n \"bunnyId\": \"4\"\n }\n}",
"synced_at": "2021-08-19T10:49:00.324Z",
"amount": "1",
"name": "Pancake Bunnies",
"symbol": "PB"
}

getTokenIdOwners

Returns an object with number of NFT transfers and an array with all owners of NFT items within a given contract collection (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • format (optional): The format of the token id. Available values : decimal, hex. Default value is decimal

  • offset (optional): offset.

  • limit(optional): limit.

  • order (optional): The field(s) to order on and if it should be ordered in ascending or descending order.

  • address(required): Address of the contract.

  • token_id(requierd): The id of the token.

const options = { address: "0xd...07", token_id: "1", chain: "bsc" };
const tokenIdOwners= await Moralis.Web3API.token.getTokenIdOwners(options);

The field(s) to order on and if it should be ordered in ascending or descending order. Specified by: fieldName1.order, fieldName2.order.

//Example 1: "name", "name.ASC", "name.DESC"
const options = { address: "0xd...07", order: "name.DESC", token_id: "1" };
const nftTransfers = await Moralis.Web3API.token.getTokenIdOwners(options);
​
//Example 2: "Block and Contract Type", "block_number.ASC, contract_type.DESC"
const options = {
address: "0xd...07",
order: "block_number.ASC, contract_type.DESC",
token_id: "1"
}
const nftTransfers = await Moralis.Web3API.token.getTokenIdOwners(options);

Example result:

[
{
"token_address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"token_id": "15",
"contract_type": "ERC721",
"owner_of": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"block_number": "88256",
"block_number_minted": "88256",
"token_uri": "string",
"metadata": "string",
"synced_at": "string",
"amount": "1",
"name": "CryptoKitties",
"symbol": "RARI"
}
]

getWalletTokenIdTransfers

Returns an object with number of NFT transfers and an array with all transfers of NFT by token id (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • format (optional): The format of the token id. Available values : decimal, hex. Default value is decimal

  • offset (optional): offset.

  • limit(optional): limit.

  • order (optional): The field(s) to order on and if it should be ordered in ascending or descending order.

  • address(required): Address of the contract.

  • token_id(requierd): The id of the token.

const options = { address: "0xd...07", token_id: "1", chain: "bsc" };
const transfers = await Moralis.Web3API.token.getWalletTokenIdTransfers(options);

The field(s) to order on and if it should be ordered in ascending or descending order. Specified by: fieldName1.order, fieldName2.order.

//Example 1: "name", "block_number.ASC", "block_number.DESC"
const options = { address: "0xd...07", order: "block_number.DESC", token_id: "1" };
const transfers = await Moralis.Web3API.token.getContractNFTTransfers(options);
​
//Example 2: "Block and Contract Type", "block_number.ASC, contract_type.DESC"
const options = {
address: "0xd...07",
order: "block_number.ASC, contract_type.DESC",
token_id: "1"
}
const transfers = await Moralis.Web3API.token.getWalletTokenIdTransfers(options);

Example result:

[
{
"token_address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"token_id": "15",
"from_address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"to_address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"amount": "1",
"contract_type": "ERC721",
"block_number": "88256",
"block_timestamp": "2021-06-04T16:00:15",
"block_hash": "string",
"transaction_hash": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"transaction_type": "string",
"transaction_index": "string",
"log_index": 0
}
]