Skip to content

Instantly share code, notes, and snippets.

@blurpesec
Created May 7, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurpesec/98425dac4a3ffcc07040f909f18a2217 to your computer and use it in GitHub Desktop.
Save blurpesec/98425dac4a3ffcc07040f909f18a2217 to your computer and use it in GitHub Desktop.
getAssetIconurl Example
import getUuid from 'uuid-by-string';
import { toChecksumAddress } from 'ethereumjs-util';
const chainId = '1' // chainId of network asset relies on (1 = ethereum)
const daiContractAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // Contract address of token
// This is used to generate a deterministic network-unique asset uuid.
const generateUUIDByIdAndAddress = (chainId, address) =>
address
? getUuid(`${chainId}-${toChecksumAddress(address)}`)
: getUuid(`${chainId}`);
const daiAssetIconUrl = `https://mycryptoapi.com/api/v1/images/${generateUUIDByIdAndAddress(chainId, daiContractAddress)}.png`
const ethAssetIconUrl = `https://mycryptoapi.com/api/v1/images/${generateUUIDByIdAndAddress(chainId)}.png`
// daiAssetIconUrl = 'https://mycryptoapi.com/api/v1/images/e1f698bf-cb85-5405-b563-14774af14bf1.png'
// ethAssetIconUrl = 'https://mycryptoapi.com/api/v1/images/356a192b-7913-504c-9457-4d18c28d46e6.png'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment