Skip to content

Comments

Refactor: Centralize duplicated configuration across query scripts#24

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/refactor-duplicated-code-again
Draft

Refactor: Centralize duplicated configuration across query scripts#24
Copilot wants to merge 5 commits intomainfrom
copilot/refactor-duplicated-code-again

Conversation

Copy link

Copilot AI commented Feb 3, 2026

Four scripts (query-token-balance.{js,py,sh} and fetch-example.js) each hardcoded identical configuration values: API base URL, default address, chain ID, pagination, module/action, and address validation pattern.

Changes

  • Centralized config: Extended etherscan-config.json with address_validation_pattern, made it single source of truth for all scripts
  • Error handling: Added descriptive errors for missing/malformed config in all implementations
  • Performance: Shell script parses JSON once (previously 8x in python3 fallback), Python compiles regex at module level (previously per-call)

Example

Before (duplicated in each script):

const baseUrl = 'https://api.etherscan.io/v2/api';
const defaultAddress = '0x983e3660c0bE01991785F80f266A84B911ab59b0';
const chainId = 1;

After (all scripts):

const config = JSON.parse(fs.readFileSync('etherscan-config.json', 'utf8'));
const baseUrl = config.etherscan_api.base_url;
const defaultAddress = config.etherscan_api.example_address;

Configuration changes now require updating one file instead of four.

Stats: 5 files changed (+125/-38), zero duplication remaining

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.etherscan.io
    • Triggering command: /usr/local/bin/node node fetch-example.js (dns block)
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)
    • Triggering command: /usr/local/bin/node node -e require('./fetch-example.js') (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Find and refactor duplicated code.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 3, 2026 17:42
…config file

Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
…times

Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
… scripts

Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor: Centralize duplicated configuration across query scripts Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants