@orbiter-finance/explore-link
v0.0.12
Published
JavaScript library for Orbiter Finance Explore Link
Readme
ExploreLinkProvider
The ExploreLinkProvider class is designed to provide convenient links for blockchain explorers. This class can fetch and manage blockchain configuration data (either locally or remotely via API) and generate links for accounts, tokens, and transactions across different blockchain networks. It supports both mainnet and testnet environments.
Features
- Load Blockchain Configurations: Load chain configurations either from local JSON files or remotely via the Orbiter API.
- Explorer Link Generation: Generate explorer links for accounts, tokens, and transactions based on chain configuration.
- Dynamic Configuration Management: Add or update blockchain configurations dynamically at runtime.
Installation
To install and use this package, run:
npm installUsage
1. Import the Module
import ExploreLinkProvider, { Endpoint } from './ExploreLinkProvider';2. Initialize the Provider
You can initialize the ExploreLinkProvider by passing the appropriate endpoint for either mainnet or testnet:
const exploreProvider = new ExploreLinkProvider(Endpoint.mainnet);3. Generate Explorer Links
Once initialized, you can generate explorer links for accounts, tokens, and transactions by providing the respective blockchain chainId and values:
Get Account Link
const accountLink = await exploreProvider.getAccountLink('1', '0x123...abc');
console.log(accountLink); // Returns the explorer URL for the accountGet Token Link
const tokenLink = await exploreProvider.getTokenLink('1', '0x456...def');
console.log(tokenLink); // Returns the explorer URL for the tokenGet Transaction Link
const txLink = await exploreProvider.getTransactionLink('1', '0x789...ghi');
console.log(txLink); // Returns the explorer URL for the transaction4. Add or Update Blockchain Configuration
You can dynamically add a new chain configuration or update an existing one:
const newChainConfig: ChainConfig = {
chainId: '100',
name: 'NewChain',
explorers: [
{
url: 'https://newchain.explorer.io',
name: 'NewChain Explorer',
standard: 'EIP3091',
},
],
};
await exploreProvider.addBlockchain('100', newChainConfig);Configuration
The ExploreLinkProvider uses two primary sources for blockchain configurations:
- Local JSON Files: Predefined configurations for mainnet and testnet chains.
chains.json: Mainnet chain configurationstestnet.json: Testnet chain configurations
ExplorerFactory
ExploreLinkProvider uses an ExplorerFactory to create explorer objects based on the chain configuration. These explorers provide methods to generate the appropriate links for accounts, tokens, and transactions.
Example ExplorerFactory Usage
import { ExplorerFactory } from './explorer.factory';
const config = {
url: 'https://etherscan.io',
name: 'Etherscan',
standard: 'EIP3091',
};
const explorer = ExplorerFactory.createExplorer(config);
const accountLink = explorer.getAccountLink('0x123...abc');
console.log(accountLink); // Generates the Etherscan account URLError Handling
If no explorers are available for a given chain, the ExploreLinkProvider will throw an error:
try {
const accountLink = await exploreProvider.getAccountLink('999', '0x123...abc');
} catch (error) {
console.error(error.message); // "No explorers available for chain: 999"
}API Endpoints
The ExploreLinkProvider supports two API endpoints, represented by the Endpoint enum:
Endpoint.mainnet: Mainnet chainsEndpoint.testnet: Testnet chains
ChainConfig Interface
A ChainConfig represents the configuration for a blockchain network, including its explorers:
export interface ChainConfig {
chainId: string;
name: string;
explorers: {
url: string;
name: string;
standard: string;
}[];
}Development
Clone the repository:
git clone https://github.com/your-repo/explore-link-provider.git
cd explore-link-providerInstall dependencies:
npm installRun tests:
npm testLicense
This project is licensed under the MIT License.
