A high-performance REST API built with FastAPI for managing Tron wallets and transactions.
- β‘ FastAPI - High performance async framework
- π Secure API key authentication
- πΌ Create new Tron wallets
- π° Check wallet balances
- π Get transaction details
- πΈ Send TRX transactions
- π Auto-generated interactive API documentation
- π³ Docker support
- β Input validation with Pydantic
- Python 3.8 or 3.9 β
tronapipinseth-account==0.4.0, which fails to import on Python 3.10 and newer (from collections import Mappingwas removed in 3.10) - pip
- Clone the repository:
git clone https://github.com/RayanErfan/Tron-Wallet-API.git
cd Tron-Wallet-API- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your configurationCreate a .env file with the following variables:
API_KEY=your_secure_api_key_here
TRON_FULL_NODE=https://api.trongrid.io
TRON_SOLIDITY_NODE=https://api.trongrid.io
TRON_EVENT_SERVER=https://api.trongrid.io
CHANNEL=YourChannel
OWNER=YourName
PORT=8000
RELOAD=False# Development mode with auto-reload
uvicorn app:app --reload --host 0.0.0.0 --port 8000
# Production mode
uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4Or simply:
python app.pyThe server will start on http://0.0.0.0:8000 by default.
FastAPI automatically generates interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
You can test all endpoints directly from the browser!
All endpoints require API key authentication via the X-API-Key header:
X-API-Key: your_api_keyCreates a new Tron wallet.
Endpoint: POST /wallet/create
cURL Example:
curl -X POST "http://localhost:8000/wallet/create" \
-H "X-API-Key: your_api_key"Response:
{
"ok": true,
"channel": "YourChannel",
"owner": "YourName",
"data": {
"private_key": "...",
"public_key": "...",
"address_base58": "TRx...",
"address_hex": "41...",
"is_valid": true
}
}Get the balance of a Tron wallet.
Endpoint: GET /wallet/balance
Query Parameters:
address(string, required): The Tron wallet address
cURL Example:
curl -X GET "http://localhost:8000/wallet/balance?address=TRx..." \
-H "X-API-Key: your_api_key"Python Example:
import requests
response = requests.get(
"http://localhost:8000/wallet/balance",
params={"address": "TRx..."},
headers={"X-API-Key": "your_api_key"}
)
print(response.json())Response:
{
"ok": true,
"channel": "YourChannel",
"owner": "YourName",
"data": {
"address": "TRx...",
"balance_sun": 1000000,
"balance_trx": 1.0
}
}Retrieve transaction details by ID.
Endpoint: GET /transaction/get
Query Parameters:
tx_id(string, required): The transaction ID
cURL Example:
curl -X GET "http://localhost:8000/transaction/get?tx_id=..." \
-H "X-API-Key: your_api_key"Send TRX from one address to another.
Endpoint: POST /transaction/send
Request Body:
{
"private_key": "...",
"from_address": "TRx...",
"to_address": "TRx...",
"amount": 1000000
}cURL Example:
curl -X POST "http://localhost:8000/transaction/send" \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"private_key": "...",
"from_address": "TRx...",
"to_address": "TRx...",
"amount": 1000000
}'Python Example:
import requests
response = requests.post(
"http://localhost:8000/transaction/send",
headers={"X-API-Key": "your_api_key"},
json={
"private_key": "...",
"from_address": "TRx...",
"to_address": "TRx...",
"amount": 1000000 # in SUN
}
)
print(response.json())Build and run with Docker:
docker build -t Tron-Wallet-API .
docker run -p 8000:8000 --env-file .env Tron-Wallet-APIβ
Automatic validation - Pydantic models ensure data integrity
β
Auto-generated docs - Interactive API documentation out of the box
β
Type hints - Better IDE support and fewer bugs
β
Async support - High performance for I/O operations
β
Modern Python - Uses Python 3.6+ features
β
Production ready - Built on Starlette and Uvicorn
- Never commit your
.envfile - Contains sensitive API keys - Use strong API keys - Generate random, complex keys (32+ characters)
- Use HTTPS in production - Never send private keys over HTTP
- Private keys are sensitive - Never log or expose them
- Rate limiting - Consider adding rate limiting for production
- CORS - Configure CORS properly for your use case
import secrets
api_key = secrets.token_urlsafe(32)
print(api_key)Run in development mode with auto-reload:
export RELOAD=True
python app.pyOr:
uvicorn app:app --reloadAccess the interactive API documentation at /docs to test all endpoints visually.
Tron-Wallet-API/
βββ app.py # Main FastAPI application
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ .env # Your configuration (not in git)
βββ .gitignore # Git ignore rules
βββ Dockerfile # Docker container config
βββ README.md # This file
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details
This software is provided as-is. Use at your own risk. Always test thoroughly with testnet before using mainnet. Never expose private keys or API keys.
- Issues: https://github.com/RayanErfan/Tron-Wallet-API/issues
- Discussions: https://github.com/RayanErfan/Tron-Wallet-API/discussions
- FastAPI Docs: https://fastapi.tiangolo.com