UNPKG

@lido-sdk/helpers

Version:

This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li

42 lines (39 loc) 1.69 kB
import invariant from 'tiny-invariant'; import { CHAINS } from '@lido-sdk/constants'; var ETHERSCAN_ENTITIES; (function (ETHERSCAN_ENTITIES) { ETHERSCAN_ENTITIES["Tx"] = "tx"; ETHERSCAN_ENTITIES["Token"] = "token"; ETHERSCAN_ENTITIES["Address"] = "address"; })(ETHERSCAN_ENTITIES || (ETHERSCAN_ENTITIES = {})); const ETHERSCAN_PREFIX_BY_NETWORK = { [CHAINS.Mainnet]: '', [CHAINS.Ropsten]: 'ropsten.', [CHAINS.Rinkeby]: 'rinkeby.', [CHAINS.Goerli]: 'goerli.', [CHAINS.Kovan]: 'kovan.', [CHAINS.Holesky]: 'holesky.', [CHAINS.Sepolia]: 'sepolia.', [CHAINS.Hoodi]: 'hoodi.', }; const getEtherscanPrefix = (chainId) => { const prefix = ETHERSCAN_PREFIX_BY_NETWORK[chainId]; invariant(prefix != null, 'Chain is not supported'); return prefix; }; const getEtherscanLink = (chainId, hash, entity) => { const prefix = getEtherscanPrefix(chainId); invariant(hash && typeof hash === 'string', 'Hash should be a string'); invariant(entity && typeof entity === 'string', 'Entity should be a string'); return `https://${prefix}etherscan.io/${entity}/${hash}`; }; const getEtherscanTxLink = (chainId, hash) => { return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.Tx); }; const getEtherscanTokenLink = (chainId, hash) => { return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.Token); }; const getEtherscanAddressLink = (chainId, hash) => { return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.Address); }; export { ETHERSCAN_ENTITIES, ETHERSCAN_PREFIX_BY_NETWORK, getEtherscanAddressLink, getEtherscanLink, getEtherscanPrefix, getEtherscanTokenLink, getEtherscanTxLink };