config.json
Overview
The `config.json` file is a configuration file used to define runtime parameters and operational settings for a Polygon (MATIC) blockchain node or related service component. It primarily configures how the system interacts with external data sources (e.g., fiat currency exchange rates), blockchain RPC endpoints, mempool transaction handling, and coin metadata.
This file does **not** contain executable code but serves as a structured JSON-based configuration that other system components consume at startup or runtime to tailor behavior according to the specified parameters.
Detailed Explanation of Configuration Fields
Field Name | Type | Description | Example Value |
|---|---|---|---|
`fiat_rates` | string | Specifies the source/provider of fiat currency exchange rates. | |
`fiat_rates_params` | string (JSON) | JSON string specifying parameters related to the fiat rates API, including URL, coin to fetch rates for, platform info, and polling period in seconds. | |
`fiat_rates_vs_currencies` | string | Comma-separated list of fiat and crypto currency codes against which the base coin exchange rates will be fetched. | `"AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH"` |
`mempoolTxTimeoutHours` | integer | Number of hours after which unconfirmed mempool transactions are considered timed out and may be dropped or re-processed. | `48` |
`queryBackendOnMempoolResync` | boolean | Flag determining if the backend database should be queried when resyncing the mempool. | `false` |
`coin_name` | string | Full name of the cryptocurrency (used for display purposes). | |
`coin_shortcut` | string | Short ticker symbol of the cryptocurrency. | `"MATIC"` |
`coin_label` | string | Label or display name for the coin, often matching `coin_name`. | |
`rpc_url` | string | RPC endpoint URL used to connect with the blockchain node (supports WebSocket in this example). | `"ws://localhost:8546"` |
`rpc_user` | string | Username for RPC authentication (empty if no authentication is required). | `""` |
`rpc_pass` | string | Password for RPC authentication (empty if no authentication is required). | `""` |
`rpc_timeout` | integer | Timeout in seconds for RPC calls to the blockchain node. | `25` |
`parse` | boolean | Flag indicating whether to parse incoming data (e.g., transaction or block data). | `true` |
`message_queue_binding` | string | Binding key or identifier for message queue integration (empty if not used). | `""` |
`subversion` | string | Subversion or client version string (empty if not specified). | `""` |
`address_format` | string | Format specification for blockchain addresses (empty if default is used). | `""` |
`mempool_workers` | integer | Number of worker threads or processes handling mempool transactions. | `8` |
`mempool_sub_workers` | integer | Number of sub-worker threads/processes under each mempool worker. | `2` |
`block_addresses_to_keep` | integer | Number of block addresses to retain in memory/cache for quicker access or history. | `300` |
Usage Example
This file is usually loaded by the blockchain node service or a related component at startup. Here is a pseudocode example of how this configuration might be used in a Node.js service:
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
// Connect to RPC endpoint
const rpcClient = new RpcClient({
url: config.rpc_url,
user: config.rpc_user,
pass: config.rpc_pass,
timeout: config.rpc_timeout,
});
// Setup fiat rates polling
const fiatParams = JSON.parse(config.fiat_rates_params);
const fiatRatesProvider = new FiatRatesProvider(config.fiat_rates, fiatParams, config.fiat_rates_vs_currencies);
// Initialize mempool workers
const mempoolManager = new MempoolManager(config.mempool_workers, config.mempool_sub_workers, config.mempoolTxTimeoutHours);
// Other logic...
Important Implementation Details
Fiat Rates Integration:
Thefiat_rates_paramsfield is a serialized JSON string that must be parsed before use. It contains critical details such as the API URL, coin identifier, platform, and polling interval in seconds (periodSeconds). The system uses these to query fiat exchange rates periodically, updating internal rate caches for currency conversions.Mempool Transaction Handling:
Mempool timeout (
mempoolTxTimeoutHours) defines how long pending transactions remain valid in the mempool before being dropped or flagged for resync.Workers (
mempool_workers) and sub-workers (mempool_sub_workers) allow parallel processing of mempool transactions, improving throughput and responsiveness.The option to query the backend database on mempool resync (
queryBackendOnMempoolResync) helps maintain data consistency but is disabled by default for performance.
RPC Configuration:
The RPC URL supports WebSocket (ws://) connections, facilitating real-time event subscriptions or notifications. Authentication fields (rpc_user,rpc_pass) are optional and left empty here, suggesting either no authentication or environment-based overrides.Parsing Flag:
Theparseboolean toggles whether incoming blockchain data should be parsed immediately or handled in raw form. This can affect performance and data handling strategies.
Interaction With Other System Components
Blockchain Node / RPC Client:
Therpc_url,rpc_user,rpc_pass, andrpc_timeoutfields are consumed by the blockchain RPC client module to establish and maintain communication with the Polygon node.Fiat Rates Module:
The fiat rates configuration parameters are used by the fiat currency rate fetcher module (likely interacting with the CoinGecko API) to obtain live exchange rates for MATIC against a wide range of fiat and crypto currencies.Mempool Manager:
The mempool-related fields configure how the mempool manager handles transactions, including concurrency settings and timeout policies.Message Queue / Event Bus:
Themessage_queue_bindingfield indicates potential integration with a messaging system for event-driven processing or notifications, though it is empty here.UI / Display Layer:
Coin metadata fields likecoin_name,coin_shortcut, andcoin_labelare useful for user interfaces or reporting components that display coin information.
Visual Diagram: Configuration Structure Flowchart
flowchart TD
A[config.json] --> B[Fiat Rates Config]
A --> C[Mempool Config]
A --> D[RPC Config]
A --> E[Coin Metadata]
A --> F[Misc Settings]
B --> B1["fiat_rates"]
B --> B2["fiat_rates_params"]
B --> B3["fiat_rates_vs_currencies"]
C --> C1["mempoolTxTimeoutHours"]
C --> C2["queryBackendOnMempoolResync"]
C --> C3["mempool_workers"]
C --> C4["mempool_sub_workers"]
C --> C5["block_addresses_to_keep"]
D --> D1["rpc_url"]
D --> D2["rpc_user"]
D --> D3["rpc_pass"]
D --> D4["rpc_timeout"]
E --> E1["coin_name"]
E --> E2["coin_shortcut"]
E --> E3["coin_label"]
F --> F1["parse"]
F --> F2["message_queue_binding"]
F --> F3["subversion"]
F --> F4["address_format"]
Summary
The `config.json` file serves as a centralized configuration hub for the Polygon blockchain node or service, defining essential parameters for fiat rate fetching, RPC connectivity, mempool transaction management, and coin metadata. Proper configuration ensures smooth operation, efficient data processing, and accurate currency conversions within the system. It interacts closely with network communication modules, data parsers, and external APIs, enabling a modular and scalable blockchain infrastructure.