Environment Variables
Network configuration is managed through theTRON_NETWORK environment variable in your .env file:
~/workspace/source/.env.example:8-9
Network Endpoints
Nile Testnet (Recommended for Development)
- Free test TRX from faucets
- Identical to mainnet functionality
- No real money at risk
- Perfect for development and testing
- Block time: ~3 seconds
Mainnet (Production Only)
- Real TRX cryptocurrency
- Production-ready transactions
- Requires real funds
- Same block time and confirmation rules
Network Comparison
| Feature | Nile Testnet | Mainnet |
|---|---|---|
| Endpoint | https://nile.trongrid.io | https://api.trongrid.io |
| Currency | Test TRX (no value) | Real TRX |
| Block Time | ~3 seconds | ~3 seconds |
| Confirmations | 21 blocks | 21 blocks |
| Faucet | Available | Not available |
| Use Case | Development, testing | Production |
| Cost | Free | Real money |
Configuration by Environment
Use different configurations for each environment:Using TronWeb with Network Config
The backend initializes TronWeb using the environment variable:~/workspace/source/src/services/tron.service.js:1-10
~/workspace/source/src/services/transactionListener.js:4-14
Network-Specific Considerations
Testnet (Nile)
Advantages:- Safe for experimentation
- Free test TRX available
- Identical API to mainnet
- Full transaction history
- Test data may be reset periodically
- Not for production use
- Test TRX has no real value
- Create a wallet using the backend API
- Visit Nile Faucet
- Enter your testnet address
- Receive 10,000 test TRX
Mainnet (Production)
Advantages:- Real cryptocurrency transactions
- Production-ready
- Full network security
- Real TRX for transactions
- Proper security measures
- Comprehensive testing completed
- Error handling and monitoring
Switching Networks
To switch between networks, update your.env file:
Address Compatibility
TRON addresses are compatible across networks:Best Practices
Use Environment-Specific Configuration Files
Use Environment-Specific Configuration Files
Maintain separate
.env files for each environment:.env.development(Nile testnet).env.staging(Nile testnet).env.production(Mainnet)
dotenv-cli to load the correct file:Never Commit .env Files
Never Commit .env Files
Add Commit only
.env to .gitignore:.gitignore
.env.example with safe placeholder values.Validate Network on Startup
Validate Network on Startup
Add validation to ensure correct network configuration:
Test Thoroughly on Testnet
Test Thoroughly on Testnet
Before mainnet deployment:
- Test all transaction types
- Verify refund processing
- Test error handling
- Validate transaction listener
- Check Socket.io notifications
Monitoring Network Health
Check network status programmatically:Additional Resources
TRON Documentation
Official TRON developer documentation
Nile Testnet Explorer
View testnet transactions and blocks
Mainnet Explorer
View mainnet transactions and blocks
TronGrid API
API documentation and rate limits
Next Steps
TRON Setup
Configure TronWeb and create wallets
Transaction Listener
Monitor blockchain transactions