Created
May 7, 2020 20:22
-
-
Save blurpesec/98425dac4a3ffcc07040f909f18a2217 to your computer and use it in GitHub Desktop.
getAssetIconurl Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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