0

I use web3 library to interact with Ethereum Network and I want to get token info with his contract address such as tokenName, tokenSymbol, tokenDecimal, tokenLogoURL etc. I can get almost any data except for the token logo URL.

Here is the code to get name, symbol, decimal:

export async function useGetTokenInfo(chainId: IChainId, tokenAddress: string) {
  const web3: Web3 = new Web3(providers[chainId]);
  const tokenInst = new web3.eth.Contract(tokenABI, tokenAddress);

  const tokenDecimal = await tokenInst.methods.decimals().call();
  const tokenName = await tokenInst.methods.name().call();
  const tokenSymbol = await tokenInst.methods.symbol().call();
}

But I have no any idea to get token Logo as url. Is there any api to get any Ethereum token(For example ERC20, ERC 721 tokens) logo url?

2 Answers 2

0

The token logo URL isn't part of the ERC-20 or ERC-721 specifications (here and here). Some tokens may have included it in their contracts, but most of them won't have.

An alternative would be to use the Coingecko API. For example:

https://api.coingecko.com/api/v3/coins/ethereum

Returns a JSON object including the following logo fields:

"image": {
    "thumb": "https://assets.coingecko.com/coins/images/279/thumb/ethereum.png?1595348880",
    "small": "https://assets.coingecko.com/coins/images/279/small/ethereum.png?1595348880",
    "large": "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880"
  },

You'll need to replace the ethereum query string with the name of the token you're querying. (Which can be found from the list in https://api.coingecko.com/api/v3/coins/list.)

This only works for coins and tokens listed on Coingecko. For anything else, you'll have to find another source.

2
  • Thank you for your quick reply. To clarify again, this api work for tokens and coins both? or just for coins?
    – ClusterH
    Commented May 31, 2021 at 17:45
  • And another alternative solution is that use follow url: https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/${address}/logo.png But it looks does not work for the binance smart chain tokens even though change ethereum with smartchain on the url
    – ClusterH
    Commented May 31, 2021 at 17:48
0

Logos are not part of the ERC20 specification. A few tokens have included a logo on the contract, but this method would be unreliable.

You'll need to use a 3rd party api service. I would recommend using the Codex Api (just rebranded from Defined). They seem to have more logos than anywhere else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.