Skip to content

AvianNetwork/avn-api-server

Repository files navigation

🚀 Avian API Server

A modern, secure, and scalable public REST API server for the Avian blockchain network. This API is open for anyone to use without authentication, providing comprehensive blockchain data access. The project has been completely modernized with the latest security practices, performance optimizations, and developer experience improvements.

✨ Features

  • 🌐 Public Access: No API keys or authentication required - open for everyone
  • 🔒 Security First: Input validation, rate limiting, and security headers
  • ⚡ High Performance: Redis caching, connection pooling, and optimized database queries
  • 📊 Real-time Updates: WebSocket support for live blockchain data
  • 🐳 Containerized: Docker and Docker Compose support for easy deployment
  • 📚 Comprehensive API: Full REST API coverage for blockchain operations
  • 🔍 Monitoring: Built-in metrics, logging, and health checks
  • 🌐 Modern Frontend: Updated HTML5 interface with Bootstrap 5

🛠️ Tech Stack

  • Backend: Python 3.12, Flask 3.0, Socket.IO
  • Caching: Redis
  • Security: Flask-Limiter, CORS, Security Headers
  • Frontend: Modern HTML5, Bootstrap 5, Vanilla JavaScript
  • Deployment: Docker, Gunicorn, Nginx

🚀 Quick Start

Prerequisites

  • Python 3.12+
  • Redis (optional, for caching)
  • Avian blockchain node with RPC enabled

1. Clone and Setup

git clone <repository-url>
cd api
cp .env.example .env
# Edit .env with your configuration

2. Install Dependencies

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate

# Install dependencies
pip install -r requirements.txt

3. Configure Environment

Edit .env file with your blockchain node settings (API key not required):

# Blockchain RPC connection (required)
API_RPC_HOST=127.0.0.1
API_RPC_PORT=8767
API_RPC_USER=your-rpc-username
API_RPC_PASSWORD=your-rpc-password

# Optional: Redis for caching
REDIS_URL=redis://localhost:6379/0

# Optional: Custom secret key (auto-generated if not set)
# API_SECRET_KEY=your-custom-secret-key

4. Run the Server

# Development
python app.py

# Production
gunicorn --bind 0.0.0.0:3002 --workers 4 --worker-class eventlet wsgi:app

🐳 Docker Deployment

Development

docker-compose up --build

Production (without Nginx)

# Run API and Redis only (no Nginx reverse proxy)
docker-compose up -d api redis

# Or to explicitly exclude the production profile
docker-compose up --build -d

Production (with optional Nginx)

# Only if you need the built-in Nginx reverse proxy
docker-compose --profile production up -d

📚 API Documentation

The API provides comprehensive endpoints for blockchain interaction:

Core Endpoints

  • GET /info - Blockchain information
  • GET /height/{height} - Block by height
  • GET /block/{hash} - Block by hash
  • GET /transaction/{hash} - Transaction details

Address Endpoints

  • GET /balance/{address} - Address balance
  • GET /history/{address} - Transaction history
  • GET /unspent/{address} - Unspent outputs
  • GET /mempool/{address} - Mempool transactions

Asset Endpoints

  • GET /listassets - List all assets
  • POST /asset - Get asset information
  • POST /ans - Get ANS data

Utility Endpoints

  • GET /fee - Estimate transaction fee
  • POST /broadcast - Broadcast transaction
  • GET /mempool - Mempool information

🔒 Security Features

Input Validation

  • Address format validation
  • Hash format validation
  • Parameter sanitization
  • SQL injection prevention

Rate Limiting

  • Per-endpoint rate limits
  • IP-based tracking
  • Configurable limits

Security Headers

  • CSRF protection
  • XSS protection
  • Content type validation
  • HSTS in production

⚙️ Configuration

Environment Variables

Variable Description Default
API_RPC_HOST Blockchain RPC host 127.0.0.1
API_RPC_PORT Blockchain RPC port 8767
API_RPC_USER Blockchain RPC username Required
API_RPC_PASSWORD Blockchain RPC password Required
API_SECRET_KEY Flask secret key (optional) Auto-generated
API_RATE_LIMIT_PER_MINUTE Rate limit per minute 60
REDIS_URL Redis connection URL Optional

🚀 Deployment

Production Checklist

  • Configure blockchain RPC connection
  • Set up Redis for caching (recommended)
  • Configure your VPC load balancer/reverse proxy to point to port 3002
  • Enable SSL/TLS certificates on your VPC load balancer
  • Configure log rotation
  • Set up monitoring/alerting
  • Configure firewall rules (allow port 3002)
  • Set API_DEBUG=false and API_LOG_LEVEL=INFO in production
  • Optionally set custom API_SECRET_KEY

Built with ❤️ for the Avian blockchain community

Configuration

The API server uses environment variables for configuration. Create a .env file in the root directory:

# Blockchain RPC connection (required)
API_RPC_HOST=127.0.0.1
API_RPC_PORT=8767
API_RPC_USER=your-rpc-username
API_RPC_PASSWORD=your-rpc-password

# Optional: Redis for caching
REDIS_URL=redis://localhost:6379/0

# Optional: Custom settings
API_SECRET_KEY=your-custom-secret-key
API_DEBUG=false
API_LOG_LEVEL=INFO

All requests should be sent to this endpoint: https://api.avn.network

Response have following fields:

result: list or object which contains requested data error: this field contains error message in case something went wrong id: api server identifier which is set in configuration

P.s. keep in mind, that all amounts in this API should be in Satoshis.

Methods


/info

This method returns current info about Avian blockchain.

Params: none

Request: https://api.avn.network/info

Response:

{
    "result": {
        "chain": "main",
        "blocks": 4143315,
        "headers": 4143315,
        "bestblockhash": "00000000029a81d0205dee0866f670cd959fd2018e35a5bc200dfd357dc3675d",
        "difficulty": 31.76004891706626,
        "difficulty_algorithm": "LWMA-3",
        "difficulty_minotaurx": 0.01645496709759841,
        "difficulty_x16rt": 31.76004891706626,
        "mediantime": 1756741507,
        "chainwork": "00000000000000000000000000000000000000000000000045e792c2989ec2cd",
        "dev_fee": 6250000000,
        "miner_reward": 118750000000,
        "reward": 125000000000,
        "supply": 780414500000000000,
        "nethash": 2513791318,
        "nethash_minotaurx": 1262925,
        "nethash_x16rt": 2513791318
    },
    "error": null,
    "id": "avn-api-server"
}

/height/int:height

This method returns block info by given height.

Params: offset: offset of transactions list (default: 0)

Request: https://api.avn.network/height/4143315

Response:

{
    "result": {
        "hash": "00000000029a81d0205dee0866f670cd959fd2018e35a5bc200dfd357dc3675d",
        "confirmations": 1,
        "size": 222,
        "strippedsize": 222,
        "weight": 888,
        "height": 4143315,
        "version": 536870912,
        "versionHex": "20000000",
        "merkleroot": "52e142b559e6ba048e00b7b1ef94fb0ec4f8b2ba84289158b49dd604f94619d3",
        "tx": [
            "52e142b559e6ba048e00b7b1ef94fb0ec4f8b2ba84289158b49dd604f94619d3"
        ],
        "time": 1756741545,
        "mediantime": 1756741507,
        "nonce": 3424328192,
        "bits": "1c080f71",
        "difficulty": 31.76004891706626,
        "chainwork": "00000000000000000000000000000000000000000000000045e792c2989ec2cd",
        "previousblockhash": "0000000003b8100faaf437bb51ad78622eaf138669a4ab7e01e93cf43f10b568",
        "txcount": 1,
        "powtype": "x16rt"
    },
    "error": null,
    "id": "avn-api-server"
}

Request: https://api.avn.network/height/0

Response:

{
    "result": "00000000029a81d0205dee0866f670cd959fd2018e35a5bc200dfd357dc3675d",
    "error": null,
    "id": "avn-api-server"
}

/block/string:hash

This method returns block info by given hash.

Params: offset: offset of transactions list (default: 0)

Request: https://api.avn.network/block/00000000029a81d0205dee0866f670cd959fd2018e35a5bc200dfd357dc3675d

Response:

{
    "result": {
        "hash": "14c03ecf20edc9887fb98bf34b53809f063fc491e73f588961f764fac88ecbae",
        "minedhash": "001cb6047ddf13074c4bce354ed3cf0cdd96a4287aa562b032eb81d03e183da8",
        "confirmations": 3580,
        "size": 403750,
        "strippedsize": 403750,
        "weight": 1615000,
        "height": 0,
        "version": 1,
        "versionHex": "00000001",
        "merkleroot": "3426ccad3017e14a4ab6efddaa44cb31beca67a86c82f63de18705f1b6de88df",
        "tx": [
            "3426ccad3017e14a4ab6efddaa44cb31beca67a86c82f63de18705f1b6de88df"
        ],
        "time": 1570625829,
        "mediantime": 1570625829,
        "nonce": 709,
        "bits": "1f3fffff",
        "difficulty": 2.384149979653205e-07,
        "chainwork": "0000000000000000000000000000000000000000000000000000000000000400",
        "nextblockhash": "3fbdde4f2ccd683e4bae7d8867d1d647b21e5a90f3ae557c57e3f2b625d387d4",
        "txcount": 1
    },
    "error": null,
    "id": "avn-api-server"
}

/header/string:hash

This method returns block header by given hash.

Params: none

Request: https://api.avn.network/header/00000000029a81d0205dee0866f670cd959fd2018e35a5bc200dfd357dc3675d

Response:

{
    "result": {
        "hash": "14c03ecf20edc9887fb98bf34b53809f063fc491e73f588961f764fac88ecbae",
        "confirmations": 3623,
        "height": 0,
        "version": 1,
        "versionHex": "00000001",
        "merkleroot": "3426ccad3017e14a4ab6efddaa44cb31beca67a86c82f63de18705f1b6de88df",
        "time": 1570625829,
        "mediantime": 1570625829,
        "nonce": 709,
        "bits": "1f3fffff",
        "difficulty": 2.384149979653205e-07,
        "chainwork": "0000000000000000000000000000000000000000000000000000000000000400",
        "nextblockhash": "3fbdde4f2ccd683e4bae7d8867d1d647b21e5a90f3ae557c57e3f2b625d387d4",
        "txcount": 1
    },
    "error": null,
    "id": "avn-api-server"
}

/range/int:height

This method returns range of blocks starting from certain height.

Params: offset: number of blocks required (default: 30)

Request: https://api.avn.network/range/4143300

Response:

{
    "result": [
        {
            "hash": "4f99bb6f9640eb340c69a563b0f113c71481343f1e37b8e2f91107c02ba8c6e7",
            "minedhash": "0004110dad177766910aed21bfc511761172b0568d7ca2fdd86184bb3bd895f7",
            "confirmations": 3544,
            "strippedsize": 222,
            "size": 258,
            "weight": 924,
            "height": 100,
            "version": 536870912,
            "versionHex": "20000000",
            "merkleroot": "84cea323eaa44d5aed27f5f8b7a237298626865608ba4d947a95375ae9cb8649",
            "tx": [
                "84cea323eaa44d5aed27f5f8b7a237298626865608ba4d947a95375ae9cb8649"
            ],
            "time": 1570628802,
            "mediantime": 1570628799,
            "nonce": 452985008,
            "bits": "1f23bcba",
            "difficulty": 4.269654764157484e-07,
            "chainwork": "000000000000000000000000000000000000000000000000000000000001a3de",
            "previousblockhash": "a6248bb69a57e414bd109aff5db99ce1271e1fc34daac8fdc720fa714028f741",
            "nextblockhash": "1236eab5de3b26dd798021248101cccb5b8467b2406cd9703d8239e9fe4e7452",
            "txcount": 1,
            "nethash": 35
        },
        ...
    ],
    "error": null,
    "id": "avn-api-server"
}

/balance/string:address

This method returns address balance.

Params: none

Request: https://api.avn.network/balance/RNmGpNQPp88esJPj6nyQYdJY4ZzqFKpTBa

Response:

{
    "result": {
        "balance": 127627708980,
        "received": 127627708980,
        "immature": 0
    },
    "error": null,
    "id": "avn-api-server"
}

/mempool/string:address

This method returns address mempool transactions.

Params: none

Request: https://api.avn.network/mempool/RNmGpNQPp88esJPj6nyQYdJY4ZzqFKpTBa

Response:

{
    "result": {
        "tx": [
            {
                "txid": "2797000448842feed62a000f070615e3468211859d4ac3c34f19c8bd59c3fc69",
                "index": 0,
                "satoshis": 10000,
                "timestamp": 1570703951
            }
        ],
        "txcount": 1
    },
    "error": null,
    "id": "avn-api-server"
}

/unspent/string:address

This method returns address unspent outputs.

Params: amount: amount which you want to spend (default: 0 will return all utxos)

Request: https://api.avn.network/unspent/RNmGpNQPp88esJPj6nyQYdJY4ZzqFKpTBa

Response:

{
    "result": [
        {
            "txid": "3426ccad3017e14a4ab6efddaa44cb31beca67a86c82f63de18705f1b6de88df",
            "index": 5672,
            "script": "76a9147fd7e409fc303e407a933b3392aa197c66348da688ac",
            "value": 127627662980,
            "height": 0
        },
        ...
    ],
    "error": null,
    "id": "avn-api-server"
}

/history/string:address

This method returns list of address transaction hashes.

Params: offset: offset of transactions list (default: 0)

Request: https://api.avn.network/history/RNmGpNQPp88esJPj6nyQYdJY4ZzqFKpTBa

Response:

{
    "result": {
        "tx": [
            "279e770e469ffdfac463ec74f0a052fd546b249328d681cd58609760e9b57501",
            "957fc74933dcfc7da179bd53d01b2a7f8ffda4daa7a39b83656acf52ef772070",
            "cb844f6ee6dceb81a280e45ef65c0e965413bb43abb4285eb4c584aace4ec1c8",
            "f318418db0c56cb2735d1b2c581fa87311109216078efa57a0679fb0a47434d6",
            "d587f628cfb722b1eb590f07bd3b864b5c56b63bd6f4469a4e20024e2b9e2ed4",
            "2797000448842feed62a000f070615e3468211859d4ac3c34f19c8bd59c3fc69",
            "3426ccad3017e14a4ab6efddaa44cb31beca67a86c82f63de18705f1b6de88df"
        ],
        "txcount": 7
    },
    "error": null,
    "id": "avn-api-server"
}

/transaction/string:hash

This method returns info about transaction.

Params: none

Request: https://api.avn.network/transaction/9df87fe9d1efae7cd47c9e89c1560cea53a5a686c0ef5c340b73dcf83238269f

Response:

{
    "result": {
        "txid": "957fc74933dcfc7da179bd53d01b2a7f8ffda4daa7a39b83656acf52ef772070",
        "hash": "957fc74933dcfc7da179bd53d01b2a7f8ffda4daa7a39b83656acf52ef772070",
        "version": 1,
        "size": 226,
        "vsize": 226,
        "weight": 904,
        "locktime": 0,
        "vin": [
            {
                "txid": "cb844f6ee6dceb81a280e45ef65c0e965413bb43abb4285eb4c584aace4ec1c8",
                "vout": 1,
                "scriptSig": {
                    "asm": "3045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb55586522[ALL] 021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117",
                    "hex": "483045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb555865220121021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117"
                },
                "sequence": 4294967293,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 436072406255f648da990ea1fa902cb98c4b6e20 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a914436072406255f648da990ea1fa902cb98c4b6e2088ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "BZvwQt9vUebNsWJanWCJy3CGtqecuBDKU8"
                    ]
                },
                "value": 93000
            }
        ],
        "vout": [
            {
                "value": 1000,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 7fd7e409fc303e407a933b3392aa197c66348da6 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9147fd7e409fc303e407a933b3392aa197c66348da688ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "BfSf3YKJ84P2vhSYLZkTCJvAmDtZs79XBH"
                    ]
                }
            },
            {
                "value": 91000,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 436072406255f648da990ea1fa902cb98c4b6e20 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a914436072406255f648da990ea1fa902cb98c4b6e2088ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "BZvwQt9vUebNsWJanWCJy3CGtqecuBDKU8"
                    ]
                }
            }
        ],
        "hex": "0100000001c8c14eceaa84c5b45e28b4ab43bb1354960e5cf65ee480a281ebdce66e4f84cb010000006b483045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb555865220121021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117fdffffff02e8030000000000001976a9147fd7e409fc303e407a933b3392aa197c66348da688ac78630100000000001976a914436072406255f648da990ea1fa902cb98c4b6e2088ac00000000",
        "blockhash": "8b7ece31deca627b0ddd23eff3f0c580ab84ef8137921400f469bbcd40dc42a5",
        "confirmations": 1234,
        "time": 1570751006,
        "blocktime": 1570751006,
        "height": 2436,
        "amount": 92000
    },
    "error": null,
    "id": "avn-api-server"
}

/decode/string:raw

This method returns decoded info about transaction.

Params: none

Request: https://api.avn.network/decode/0100000001c8c14eceaa84c5b45e28b4ab43bb1354960e5cf65ee480a281ebdce66e4f84cb010000006b483045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb555865220121021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117fdffffff02e8030000000000001976a9147fd7e409fc303e407a933b3392aa197c66348da688ac78630100000000001976a914436072406255f648da990ea1fa902cb98c4b6e2088ac00000000

Response:

{
    "result": {
        "txid": "957fc74933dcfc7da179bd53d01b2a7f8ffda4daa7a39b83656acf52ef772070",
        "hash": "957fc74933dcfc7da179bd53d01b2a7f8ffda4daa7a39b83656acf52ef772070",
        "version": 1,
        "size": 226,
        "vsize": 226,
        "weight": 904,
        "locktime": 0,
        "vin": [
            {
                "txid": "cb844f6ee6dceb81a280e45ef65c0e965413bb43abb4285eb4c584aace4ec1c8",
                "vout": 1,
                "scriptSig": {
                    "asm": "3045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb55586522[ALL] 021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117",
                    "hex": "483045022100bcf51d6111d3f23a23689d1956e010433e4ea65a3680211e5e442e229ccedd59022049e89b4762788d1718ebc5f6c300d2a898f161f22e08a6a8e55b96fb555865220121021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117"
                },
                "sequence": 4294967293
            }
        ],
        "vout": [
            {
                "value": 0.1,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 7fd7e409fc303e407a933b3392aa197c66348da6 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9147fd7e409fc303e407a933b3392aa197c66348da688ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "BfSf3YKJ84P2vhSYLZkTCJvAmDtZs79XBH"
                    ]
                }
            },
            {
                "value": 9.1,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 436072406255f648da990ea1fa902cb98c4b6e20 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a914436072406255f648da990ea1fa902cb98c4b6e2088ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "BZvwQt9vUebNsWJanWCJy3CGtqecuBDKU8"
                    ]
                }
            }
        ]
    },
    "error": null,
    "id": "avn-api-server"
}

/mempool

This method returns info about mempool.

Params: none

Request: https://api.avn.network/mempool

Response:

{
    "result": {
        "size": 0,
        "bytes": 0,
        "usage": 64,
        "maxmempool": 300000000,
        "mempoolminfee": 0.1,
        "minrelaytxfee": 0.1,
        "tx": []
    },
    "error": null,
    "id": "avn-api-server"
}

/supply

This method returns info about current coins supply.

Params: none

Request: https://api.avn.network/supply

Response:

{
    "result": {
        "supply": 444065650592233,
        "height": 3675
    },
    "error": null,
    "id": "avn-api-server"
}

/fee

This method returns recommended transaction fee.

Params: none

Request: https://api.avn.network/fee

Response:

{
    "result": {
        "feerate": 20045,
        "blocks": 6
    },
    "error": null,
    "id": "avn-api-server"
}

/broadcast

This method broadcasts raw signed transaction to Avian network. Keep in mind that you have to use POST request for this method!

Params: raw: raw signed transaction

Request: https://api.avn.network/broadcast raw: 01000000010175b5e960976058cd81d62893246b54fd52a0f074ec63c4fafd9f460e779e27010000006b48304502210092ac0108461dec3d90c31781ccac868ebb876a2e09939793581d20d733369c6002207473120c0150e1777ee700da88b833ecfb1805cd629a18d29509fad0d03a97970121021121f5e63f7537a6c8e8881b0c54c5914cd117e775c3be0486205c45eced9117fdffffff0210270000000000001976a9147fd7e409fc303e407a933b3392aa197c66348da688ac880d0100000000001976a914436072406255f648da990ea1fa902cb98c4b6e2088ac00000000

Response:

{
    "result": "9df87fe9d1efae7cd47c9e89c1560cea53a5a686c0ef5c340b73dcf83238269f",
    "error": null,
    "id": "avn-api-server"
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •