Skip to content

Commit 42abdd6

Browse files
Configuration and Environment
1 parent 9bfe6fa commit 42abdd6

1 file changed

Lines changed: 107 additions & 1 deletion

File tree

Blockchain-Python.py

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,4 +2212,110 @@ def automated_portfolio_tracker():
22122212

22132213
print(f"Address {address}: {eth_balance:.4f} ETH")
22142214

2215-
print(f"Total portfolio value: ${total_value:,.2f}")
2215+
print(f"Total portfolio value: ${total_value:,.2f}")
2216+
2217+
2218+
# ═══════════════════════════════════════════════════════════════════════════════
2219+
# 12. CONFIGURATION AND ENVIRONMENT
2220+
# ═══════════════════════════════════════════════════════════════════════════════
2221+
2222+
@dataclass
2223+
class BlockchainConfig:
2224+
"""Configuration for blockchain applications"""
2225+
2226+
# Network settings
2227+
ethereum_rpc_url: str = "https://mainnet.infura.io/v3/YOUR_KEY"
2228+
polygon_rpc_url: str = "https://polygon-rpc.com"
2229+
arbitrum_rpc_url: str = "https://arb1.arbitrum.io/rpc"
2230+
2231+
# API keys
2232+
infura_key: str = ""
2233+
alchemy_key: str = ""
2234+
opensea_api_key: str = ""
2235+
coinmarketcap_key: str = ""
2236+
2237+
# Exchange API credentials
2238+
binance_api_key: str = ""
2239+
binance_secret: str = ""
2240+
coinbase_api_key: str = ""
2241+
coinbase_secret: str = ""
2242+
2243+
# Private keys (use environment variables!)
2244+
private_key: str = ""
2245+
2246+
# Database settings
2247+
database_url: str = "sqlite:///blockchain_data.db"
2248+
2249+
# Monitoring settings
2250+
alert_email: str = ""
2251+
slack_webhook: str = ""
2252+
2253+
@classmethod
2254+
def from_env(cls) -> 'BlockchainConfig':
2255+
"""Load configuration from environment variables"""
2256+
return cls(
2257+
ethereum_rpc_url=os.getenv('ETHEREUM_RPC_URL', cls.ethereum_rpc_url),
2258+
polygon_rpc_url=os.getenv('POLYGON_RPC_URL', cls.polygon_rpc_url),
2259+
arbitrum_rpc_url=os.getenv('ARBITRUM_RPC_URL', cls.arbitrum_rpc_url),
2260+
infura_key=os.getenv('INFURA_KEY', ''),
2261+
alchemy_key=os.getenv('ALCHEMY_KEY', ''),
2262+
opensea_api_key=os.getenv('OPENSEA_API_KEY', ''),
2263+
coinmarketcap_key=os.getenv('COINMARKETCAP_KEY', ''),
2264+
binance_api_key=os.getenv('BINANCE_API_KEY', ''),
2265+
binance_secret=os.getenv('BINANCE_SECRET', ''),
2266+
coinbase_api_key=os.getenv('COINBASE_API_KEY', ''),
2267+
coinbase_secret=os.getenv('COINBASE_SECRET', ''),
2268+
private_key=os.getenv('PRIVATE_KEY', ''),
2269+
database_url=os.getenv('DATABASE_URL', cls.database_url),
2270+
alert_email=os.getenv('ALERT_EMAIL', ''),
2271+
slack_webhook=os.getenv('SLACK_WEBHOOK', '')
2272+
)
2273+
2274+
# Example .env file template
2275+
ENV_TEMPLATE = """
2276+
# Blockchain RPC URLs
2277+
ETHEREUM_RPC_URL=https://mainnet.infura.io/v3/YOUR_INFURA_KEY
2278+
POLYGON_RPC_URL=https://polygon-rpc.com
2279+
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
2280+
2281+
# API Keys
2282+
INFURA_KEY=your_infura_key_here
2283+
ALCHEMY_KEY=your_alchemy_key_here
2284+
OPENSEA_API_KEY=your_opensea_key_here
2285+
COINMARKETCAP_KEY=your_cmc_key_here
2286+
2287+
# Exchange APIs
2288+
BINANCE_API_KEY=your_binance_key_here
2289+
BINANCE_SECRET=your_binance_secret_here
2290+
COINBASE_API_KEY=your_coinbase_key_here
2291+
COINBASE_SECRET=your_coinbase_secret_here
2292+
2293+
# Wallet (NEVER commit real private keys!)
2294+
PRIVATE_KEY=your_private_key_here
2295+
2296+
# Database
2297+
DATABASE_URL=postgresql://user:pass@localhost/blockchain_db
2298+
2299+
# Alerts
2300+
ALERT_EMAIL=your_email@example.com
2301+
SLACK_WEBHOOK=your_slack_webhook_url
2302+
"""
2303+
2304+
def setup_environment():
2305+
"""Set up development environment"""
2306+
env_file = Path('.env')
2307+
2308+
if not env_file.exists():
2309+
print("Creating .env template file...")
2310+
with open('.env', 'w') as f:
2311+
f.write(ENV_TEMPLATE)
2312+
print("Please edit .env file with your API keys and settings")
2313+
else:
2314+
print(".env file already exists")
2315+
2316+
# Create directories
2317+
directories = ['data', 'logs', 'contracts', 'tests']
2318+
for directory in directories:
2319+
Path(directory).mkdir(exist_ok=True)
2320+
2321+
print("Environment setup complete!")

0 commit comments

Comments
 (0)