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?

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 May 31 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 May 31 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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