# 🌐 Web3 Restful Gateway
> A multi-chain Web3 gateway service that provides unified RESTful APIs for blockchain interaction.
[](https://www.python.org/downloads/)
[](https://fastapi.tiangolo.com)
[](https://web3py.readthedocs.io/)
[](https://opensource.org/licenses/MIT)
## 🚀 Features
- 🔗 **Multi-Chain Support**: Seamlessly interact with multiple EVM-compatible blockchains
- 🔄 **Real-time Data**: Live blockchain data through Infura and Etherscan V2 API
- 🛡️ **Battle-tested Security**: Basic auth + rate limiting
- 🎯 **High Performance**: Redis caching for frequently accessed data
- 📊 **Gas Optimization**: Smart gas estimation and transaction cost prediction
## 🛠️ Tech Stack
- **FastAPI**: High-performance async web framework
- **Web3.py**: Ethereum interaction library
- **Etherscan V2**: Multi-chain data queries
- **Redis**: Query result caching
- **Pydantic**: Data validation and settings management
## 🔧 Quick Start
### Step1: Install the package
```bash
pip install web3gateway
```
### Step2: Create a config file and edit it with your credentials
```bash
touch config.json
```
```json
{
"auth_username": "test_user",
"auth_password": "test_password",
"infura_project_id": "your infura project id",
"etherscan_api_key": "your etherscan api key",
"redis_url": "redis://localhost:6379",
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
"redis_password": "",
"rate_limit_calls": 5,
"rate_limit_period": 1,
"cache_expiration": 10
}
```
### Step3: Make sure you have redis-server installed and running correctly
```bash
redis-server
```
### Step4: Start the server
```bash
web3gateway -c config.json
```
### Step5: Test the server
```bash
curl -X GET "http://localhost:8000/ping"
```
## 📦 Development Installation
```bash
# Clone the repo
git clone https://github.com/daboooooo/web3gateway.git
# Create virtual environment and install dependencies
cd web3gateway
./setup.sh -i
source .env/bin/activate
# Set up configuration
cp config.json.example config.json
# Edit config.json with your credentials
# Start the server
web3gateway
# Test the server
curl -X GET "http://localhost:8000/ping"
```
## 🔥 Core APIs
### Transaction Operations
```http
POST /transaction/assemble
POST /transaction/send
POST /transaction/get_receipt
```
### Account Operations
```http
POST /account/balance
POST /account/token_balance
POST /account/txlist
```
### System Operations
```http
GET /ping
```
## 🎮 API Examples
### Get Account Balance
```bash
curl -X POST "http://localhost:8000/account/balance" \
-H "Content-Type: application/json" \
-u "test_user:test_password" \
-d '{
"chain_id": 1,
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}'
```
Response:
```json
{
"timestamp": 1677654321000,
"data": {
"balance": "1234567890000000000"
}
}
```
### Get Token Balance
```bash
curl -X POST "http://localhost:8000/account/token_balance" \
-H "Content-Type: application/json" \
-u "test_user:test_password" \
-d '{
"chain_id": 1,
"contractaddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}'
```
Response:
```json
{
"timestamp": 1677654321000,
"data": {
"contract address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"token balance": "150000000"
}
}
```
### Assemble Transaction
```bash
curl -X POST "http://localhost:8000/transaction/assemble" \
-H "Content-Type: application/json" \
-u "test_user:test_password" \
-d '{
"chain_id": 1,
"tx_params": {
"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"to": "0x1234567890123456789012345678901234567890",
"value": "1000000000000000000"
},
"gas_level": "normal"
}'
```
Response:
```json
{
"timestamp": 1677654321000,
"data": {
"chainId": 1,
"nonce": 5,
"gasPrice": "20000000000",
"gas": 21000,
"to": "0x1234567890123456789012345678901234567890",
"value": 1000000000000000000,
"data": "0x",
"maxPriorityFeePerGas":492407668,"maxFeePerGas":1632172748
}
}
```
You can then sign and send the transaction using the `send` API.
### Get Transaction List
```bash
curl -X POST "http://localhost:8000/account/txlist" \
-H "Content-Type: application/json" \
-u "test_user:test_password" \
-d '{
"chain_id": 1,
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}'
```
Response:
```json
{
"timestamp": 1677654321000,
"data": {
"last transactions": [
{
"blockNumber": "17584321",
"timeStamp": "1677654000",
"hash": "0xabcd...",
"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"to": "0x1234...",
"value": "1000000000000000000",
"gas": "21000",
"gasPrice": "20000000000"
}
]
}
}
```
## 🔌 Supported Networks
- Ethereum Mainnet (ChainID: 1)
- Binance Smart Chain (ChainID: 56)
- Polygon (ChainID: 137)
- Arbitrum (ChainID: 42161)
- Optimism (ChainID: 10)
- And more...
## ⚡️ Performance
- Response Time: < 100ms (cached)
- Throughput: 1000+ TPS
- Cache Hit Ratio: ~80%
## 🔒 Security Features
- Basic Authentication
- Rate Limiting
- Input Validation
- Error Handling
- Response Sanitization
## 🤝 Contributing
PRs are welcome! Check out our [contribution guidelines](CONTRIBUTING.md).
## 📜 License
MIT License - fork, modify and use as you wish.
## ⚠️ Disclaimer
This is a production-ready gateway but use at your own risk. Always verify transactions before signing.
Raw data
{
"_id": null,
"home_page": null,
"name": "web3gateway",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "web3, blockchain, ethereum, gateway, restful, api",
"author": null,
"author_email": "daboooooo <horsen666@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/1c/5b/9ae5309936740477a5f7f11840f4eeed18b9e118f9eeb218d6eccd2243fc/web3gateway-0.1.3.tar.gz",
"platform": null,
"description": "# \ud83c\udf10 Web3 Restful Gateway\n\n> A multi-chain Web3 gateway service that provides unified RESTful APIs for blockchain interaction.\n\n[](https://www.python.org/downloads/)\n[](https://fastapi.tiangolo.com)\n[](https://web3py.readthedocs.io/)\n[](https://opensource.org/licenses/MIT)\n\n## \ud83d\ude80 Features\n\n- \ud83d\udd17 **Multi-Chain Support**: Seamlessly interact with multiple EVM-compatible blockchains\n- \ud83d\udd04 **Real-time Data**: Live blockchain data through Infura and Etherscan V2 API\n- \ud83d\udee1\ufe0f **Battle-tested Security**: Basic auth + rate limiting\n- \ud83c\udfaf **High Performance**: Redis caching for frequently accessed data\n- \ud83d\udcca **Gas Optimization**: Smart gas estimation and transaction cost prediction\n\n## \ud83d\udee0\ufe0f Tech Stack\n\n- **FastAPI**: High-performance async web framework\n- **Web3.py**: Ethereum interaction library\n- **Etherscan V2**: Multi-chain data queries\n- **Redis**: Query result caching\n- **Pydantic**: Data validation and settings management\n\n## \ud83d\udd27 Quick Start\n\n### Step1: Install the package\n\n```bash\npip install web3gateway\n```\n\n### Step2: Create a config file and edit it with your credentials\n\n```bash\ntouch config.json\n```\n\n```json\n{\n \"auth_username\": \"test_user\",\n \"auth_password\": \"test_password\",\n \"infura_project_id\": \"your infura project id\",\n \"etherscan_api_key\": \"your etherscan api key\",\n \"redis_url\": \"redis://localhost:6379\",\n \"redis_host\": \"localhost\",\n \"redis_port\": 6379,\n \"redis_db\": 0,\n \"redis_password\": \"\",\n \"rate_limit_calls\": 5,\n \"rate_limit_period\": 1,\n \"cache_expiration\": 10\n}\n```\n\n### Step3: Make sure you have redis-server installed and running correctly\n\n```bash\nredis-server\n```\n\n### Step4: Start the server\n\n```bash\nweb3gateway -c config.json\n```\n\n### Step5: Test the server\n\n```bash\ncurl -X GET \"http://localhost:8000/ping\"\n```\n\n## \ud83d\udce6 Development Installation\n\n```bash\n# Clone the repo\ngit clone https://github.com/daboooooo/web3gateway.git\n\n# Create virtual environment and install dependencies\ncd web3gateway\n./setup.sh -i\nsource .env/bin/activate\n\n# Set up configuration\ncp config.json.example config.json\n# Edit config.json with your credentials\n\n# Start the server\nweb3gateway\n\n# Test the server\ncurl -X GET \"http://localhost:8000/ping\"\n```\n\n## \ud83d\udd25 Core APIs\n\n### Transaction Operations\n\n```http\nPOST /transaction/assemble\nPOST /transaction/send\nPOST /transaction/get_receipt\n```\n\n### Account Operations\n\n```http\nPOST /account/balance\nPOST /account/token_balance\nPOST /account/txlist\n```\n\n### System Operations\n\n```http\nGET /ping\n```\n\n## \ud83c\udfae API Examples\n\n### Get Account Balance\n\n```bash\ncurl -X POST \"http://localhost:8000/account/balance\" \\\n -H \"Content-Type: application/json\" \\\n -u \"test_user:test_password\" \\\n -d '{\n \"chain_id\": 1,\n \"address\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\"\n }'\n```\n\nResponse:\n\n```json\n{\n \"timestamp\": 1677654321000,\n \"data\": {\n \"balance\": \"1234567890000000000\"\n }\n}\n```\n\n### Get Token Balance\n\n```bash\ncurl -X POST \"http://localhost:8000/account/token_balance\" \\\n -H \"Content-Type: application/json\" \\\n -u \"test_user:test_password\" \\\n -d '{\n \"chain_id\": 1,\n \"contractaddress\": \"0xdac17f958d2ee523a2206206994597c13d831ec7\",\n \"address\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\"\n }'\n```\n\nResponse:\n\n```json\n{\n \"timestamp\": 1677654321000,\n \"data\": {\n \"contract address\": \"0xdac17f958d2ee523a2206206994597c13d831ec7\",\n \"address\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\",\n \"token balance\": \"150000000\"\n }\n}\n```\n\n### Assemble Transaction\n\n```bash\ncurl -X POST \"http://localhost:8000/transaction/assemble\" \\\n -H \"Content-Type: application/json\" \\\n -u \"test_user:test_password\" \\\n -d '{\n \"chain_id\": 1,\n \"tx_params\": {\n \"from\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\",\n \"to\": \"0x1234567890123456789012345678901234567890\",\n \"value\": \"1000000000000000000\"\n },\n \"gas_level\": \"normal\"\n }'\n```\n\nResponse:\n\n```json\n{\n \"timestamp\": 1677654321000,\n \"data\": {\n \"chainId\": 1,\n \"nonce\": 5,\n \"gasPrice\": \"20000000000\",\n \"gas\": 21000,\n \"to\": \"0x1234567890123456789012345678901234567890\",\n \"value\": 1000000000000000000,\n \"data\": \"0x\",\n \"maxPriorityFeePerGas\":492407668,\"maxFeePerGas\":1632172748\n }\n}\n```\n\nYou can then sign and send the transaction using the `send` API.\n\n### Get Transaction List\n\n```bash\ncurl -X POST \"http://localhost:8000/account/txlist\" \\\n -H \"Content-Type: application/json\" \\\n -u \"test_user:test_password\" \\\n -d '{\n \"chain_id\": 1,\n \"address\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\"\n }'\n```\n\nResponse:\n\n```json\n{\n \"timestamp\": 1677654321000,\n \"data\": {\n \"last transactions\": [\n {\n \"blockNumber\": \"17584321\",\n \"timeStamp\": \"1677654000\",\n \"hash\": \"0xabcd...\",\n \"from\": \"0x742d35Cc6634C0532925a3b844Bc454e4438f44e\",\n \"to\": \"0x1234...\",\n \"value\": \"1000000000000000000\",\n \"gas\": \"21000\",\n \"gasPrice\": \"20000000000\"\n }\n ]\n }\n}\n```\n\n## \ud83d\udd0c Supported Networks\n\n- Ethereum Mainnet (ChainID: 1)\n- Binance Smart Chain (ChainID: 56)\n- Polygon (ChainID: 137)\n- Arbitrum (ChainID: 42161)\n- Optimism (ChainID: 10)\n- And more...\n\n## \u26a1\ufe0f Performance\n\n- Response Time: < 100ms (cached)\n- Throughput: 1000+ TPS\n- Cache Hit Ratio: ~80%\n\n## \ud83d\udd12 Security Features\n\n- Basic Authentication\n- Rate Limiting\n- Input Validation\n- Error Handling\n- Response Sanitization\n\n## \ud83e\udd1d Contributing\n\nPRs are welcome! Check out our [contribution guidelines](CONTRIBUTING.md).\n\n## \ud83d\udcdc License\n\nMIT License - fork, modify and use as you wish.\n\n## \u26a0\ufe0f Disclaimer\n\nThis is a production-ready gateway but use at your own risk. Always verify transactions before signing.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Web3Gateway - A Restful Web3 Gateway Service",
"version": "0.1.3",
"project_urls": {
"Bug Tracker": "https://github.com/daboooooo/web3gateway/issues",
"Documentation": "https://github.com/daboooooo/web3gateway",
"Homepage": "https://github.com/daboooooo/web3gateway"
},
"split_keywords": [
"web3",
" blockchain",
" ethereum",
" gateway",
" restful",
" api"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e84e35f6bdb0c88573c4cd7e48396e436d73f2d40d5bc46da19634144fd78bf6",
"md5": "b18f523843888feb35b2974a44a896ce",
"sha256": "4df5e67f8f6c1646faf706856c7e8110c36880e52cd6f2920df98ba448c20866"
},
"downloads": -1,
"filename": "web3gateway-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b18f523843888feb35b2974a44a896ce",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 33500,
"upload_time": "2025-02-16T05:12:05",
"upload_time_iso_8601": "2025-02-16T05:12:05.026937Z",
"url": "https://files.pythonhosted.org/packages/e8/4e/35f6bdb0c88573c4cd7e48396e436d73f2d40d5bc46da19634144fd78bf6/web3gateway-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1c5b9ae5309936740477a5f7f11840f4eeed18b9e118f9eeb218d6eccd2243fc",
"md5": "bf9ce66249cbaef83a9ad73ac70c13d6",
"sha256": "2229b787616328e984c7215885c0f60e18bc65574f2f1e50edb5130c26a63f6b"
},
"downloads": -1,
"filename": "web3gateway-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "bf9ce66249cbaef83a9ad73ac70c13d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 31382,
"upload_time": "2025-02-16T05:12:07",
"upload_time_iso_8601": "2025-02-16T05:12:07.508552Z",
"url": "https://files.pythonhosted.org/packages/1c/5b/9ae5309936740477a5f7f11840f4eeed18b9e118f9eeb218d6eccd2243fc/web3gateway-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-16 05:12:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "daboooooo",
"github_project": "web3gateway",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "python-dotenv",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "ccxt",
"specs": [
[
"==",
"4.4.43"
]
]
},
{
"name": "web3",
"specs": [
[
"==",
"7.5.0"
]
]
},
{
"name": "redis",
"specs": [
[
"==",
"5.2.1"
]
]
},
{
"name": "types-redis",
"specs": []
},
{
"name": "cryptography",
"specs": [
[
"==",
"42.0.8"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"44.0.0"
]
]
},
{
"name": "aiohttp",
"specs": [
[
"==",
"3.10.11"
]
]
},
{
"name": "SQLAlchemy",
"specs": [
[
"==",
"2.0.36"
]
]
},
{
"name": "python-telegram-bot",
"specs": [
[
"==",
"21.9"
]
]
},
{
"name": "httpx",
"specs": [
[
">=",
"0.24.1"
]
]
},
{
"name": "humanize",
"specs": [
[
"==",
"4.11.0"
]
]
},
{
"name": "cachetools",
"specs": [
[
"==",
"5.5.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.32.3"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.3.0"
]
]
},
{
"name": "jsonschema",
"specs": [
[
"==",
"4.23.0"
]
]
},
{
"name": "rich",
"specs": [
[
"==",
"13.9.4"
]
]
},
{
"name": "pyarrow",
"specs": [
[
"==",
"18.1.0"
]
]
},
{
"name": "fastapi",
"specs": [
[
"==",
"0.115.6"
]
]
},
{
"name": "pydantic",
"specs": [
[
"==",
"2.10.4"
]
]
},
{
"name": "uvicorn",
"specs": [
[
"==",
"0.34.0"
]
]
},
{
"name": "pyjwt",
"specs": [
[
"==",
"2.10.1"
]
]
},
{
"name": "aiofiles",
"specs": [
[
"==",
"24.1.0"
]
]
},
{
"name": "psutil",
"specs": [
[
"==",
"6.1.1"
]
]
}
],
"lcname": "web3gateway"
}