@cryptodevops/n8n-nodes-blockchain-explorer
Version:
n8n node for accessing multiple blockchain networks (Ethereum, BSC, Polygon, Fantom, Avalanche, Arbitrum, Optimism, etc.) with comprehensive analytics and data retrieval capabilities
182 lines (181 loc) • 6.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockchainExplorerApi = void 0;
class BlockchainExplorerApi {
constructor() {
this.name = 'blockchainExplorerApi';
this.displayName = 'Blockchain Explorer API';
this.documentationUrl = 'https://docs.etherscan.io/';
this.properties = [
{
displayName: 'Blockchain Network',
name: 'network',
type: 'options',
options: [
{
name: 'Ethereum (Etherscan)',
value: 'ethereum',
},
{
name: 'Binance Smart Chain (BscScan)',
value: 'bsc',
},
{
name: 'Polygon (PolygonScan)',
value: 'polygon',
},
{
name: 'Fantom (FtmScan)',
value: 'fantom',
},
{
name: 'Avalanche (Snowtrace)',
value: 'avalanche',
},
{
name: 'Arbitrum (Arbiscan)',
value: 'arbitrum',
},
{
name: 'Optimism (Optimistic Etherscan)',
value: 'optimism',
},
{
name: 'Cronos (Cronoscan)',
value: 'cronos',
},
{
name: 'Moonbeam (Moonscan)',
value: 'moonbeam',
},
{
name: 'Celo (Celoscan)',
value: 'celo',
},
],
default: 'ethereum',
description: 'Select the blockchain network to use',
},
{
displayName: 'Environment',
name: 'environment',
type: 'options',
options: [
{
name: 'Mainnet',
value: 'mainnet',
},
{
name: 'Testnet',
value: 'testnet',
},
],
default: 'mainnet',
description: 'Select mainnet or testnet environment',
},
{
displayName: 'API Key',
name: 'apiKey',
type: 'string',
typeOptions: { password: true },
default: '',
placeholder: 'YourApiKeyToken',
description: 'Your API key for the selected blockchain explorer',
required: true,
},
{
displayName: 'Custom Base URL',
name: 'customBaseUrl',
type: 'string',
default: '',
placeholder: 'https://api.custom-explorer.com/api',
description: 'Optional: Use a custom API endpoint URL (overrides network selection)',
},
];
this.authenticate = {
type: 'generic',
properties: {
qs: {
apikey: '={{$credentials.apiKey}}',
},
},
};
this.test = {
request: {
baseURL: '={{$credentials.customBaseUrl}}',
method: 'GET',
qs: {
module: 'stats',
action: 'ethsupply',
apikey: '={{$credentials.apiKey}}',
},
},
};
}
// Helper method to get base URL based on network and environment
static getBaseUrl(network, environment) {
var _a;
const urls = {
ethereum: {
mainnet: 'https://api.etherscan.io/api',
testnet: 'https://api-sepolia.etherscan.io/api',
},
bsc: {
mainnet: 'https://api.bscscan.com/api',
testnet: 'https://api-testnet.bscscan.com/api',
},
polygon: {
mainnet: 'https://api.polygonscan.com/api',
testnet: 'https://api-testnet.polygonscan.com/api',
},
fantom: {
mainnet: 'https://api.ftmscan.com/api',
testnet: 'https://api-testnet.ftmscan.com/api',
},
avalanche: {
mainnet: 'https://api.snowtrace.io/api',
testnet: 'https://api-testnet.snowtrace.io/api',
},
arbitrum: {
mainnet: 'https://api.arbiscan.io/api',
testnet: 'https://api-goerli.arbiscan.io/api',
},
optimism: {
mainnet: 'https://api-optimistic.etherscan.io/api',
testnet: 'https://api-goerli-optimistic.etherscan.io/api',
},
cronos: {
mainnet: 'https://api.cronoscan.com/api',
testnet: 'https://api-testnet.cronoscan.com/api',
},
moonbeam: {
mainnet: 'https://api-moonbeam.moonscan.io/api',
testnet: 'https://api-moonbase.moonscan.io/api',
},
celo: {
mainnet: 'https://api.celoscan.io/api',
testnet: 'https://api-alfajores.celoscan.io/api',
},
};
return ((_a = urls[network]) === null || _a === void 0 ? void 0 : _a[environment]) || urls['ethereum']['mainnet'];
}
// Compatibility method to convert Etherscan credentials to BlockchainExplorer format
static convertFromEtherscanApi(etherscanCredentials) {
let network = 'ethereum';
let environment = 'mainnet';
const baseUrl = etherscanCredentials.baseUrl;
if (baseUrl.includes('goerli')) {
environment = 'testnet';
}
else if (baseUrl.includes('sepolia')) {
environment = 'testnet';
}
return {
network,
environment,
apiKey: etherscanCredentials.apiKey,
customBaseUrl: baseUrl, // Use exact URL to ensure compatibility
};
}
}
exports.BlockchainExplorerApi = BlockchainExplorerApi;