https://github.com/metamask/etherscan-link
A library for generating Etherscan links
https://github.com/metamask/etherscan-link
Last synced: 7 months ago
JSON representation
A library for generating Etherscan links
- Host: GitHub
- URL: https://github.com/metamask/etherscan-link
- Owner: MetaMask
- License: isc
- Created: 2017-10-14T02:38:17.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-28T16:14:32.000Z (10 months ago)
- Last Synced: 2025-06-01T22:12:33.250Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 997 KB
- Stars: 43
- Watchers: 34
- Forks: 44
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Etherscan Link Generator
## Installation
`npm install '@metamask/etherscan-link' -S`
## Usage
```javascript
const etherscanLink = require('@metamask/etherscan-link')
const networkId = '1'
const chainId = '0x1'
const account = '0xFDEa65C8e26263F6d9A1B5de9555D2931A33b825'
const accountLink = etherscanLink.createAccountLink(account, networkId)
const accountLinkForChain = etherscanLink.createAccountLinkForChain(account, chainId)
const hash = '0xa7540793de6b6ca7d3c948a8cc0a163bf107f5535a69353162ea9dec7ee7beca'
const txLink = etherscanLink.createExplorerLink(hash, networkId)
const txtLinkForChain = etherscanLink.createExplorerLinkForChain(hash, chainId)
const token = '0xdac17f958d2ee523a2206206994597c13d831ec7'
const tokenTrackerLink = etherscanLink.createTokenTrackerLink(token, networkId)
// You can also track token balances by account
const accountTokenTrackerLink = etherscanLink.createTokenTrackerLink(token, networkId, account)
const accountTokenTrackerLinkForChain = etherscanLink.createTokenTrackerLinkForChain(token, chainId, account)
// Create urls for interacting with custom networks
const customNetworkUrl = 'https://customnetwork.com/'
const customTokenTrackerLink = etherscanLink.createCustomTokenTrackerLink(token, customNetworkUrl)
const customAccountLink = etherscanLink.createCustomAccountLink(account, customNetworkUrl)
const customExplorerLink = etherscanLink.createCustomExplorerLink(hash, customNetworkUrl)
// Generate custom or native block explorer link based on rcpPrefs
const blockExplorerLink = etherscanLink.getBlockExplorerLink(transaction, rcpPrefs)
// Generate account link for custom or native network
const getAccountLink = etherscanLink.getAccountLink(address, chainId, rpcPrefs, networkId)
// Generate token tracker link for custom or native network
const tokenTrackerLink = etherscanLink.getTokenTrackerLink(tokenAddress, chainId, networkId, holderAddress, rpcPrefs)
```
## Running tests
```bash
yarn test
```