Created
December 12, 2022 22:21
-
-
Save sbarratt/06506f8b00f62b941740651ba90584a6 to your computer and use it in GitHub Desktop.
RPC Multiplexer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
from flask_restful import Resource, Api | |
import requests | |
app = Flask(__name__) | |
api = Api(app) | |
default_rpc = "https://rpc.builder0x69.io/" | |
rpcs = [ | |
"https://rpc.builder0x69.io/", | |
"https://rpc.flashbots.net", | |
"https://api.edennetwork.io/v1/beta", | |
"https://rpc.beaverbuild.org/", | |
"https://virginia.rpc.blxrbdn.com/", | |
] | |
class RpcMultiplexer(Resource): | |
def post(self): | |
request_json = request.get_json() | |
if "method" in request_json and request_json["method"] == "eth_sendRawTransaction": | |
resp = {} | |
for x in rpcs: | |
resp = requests.post(x, json=request.get_json()).json() | |
return resp | |
else: | |
return requests.post(default_rpc, json=request.get_json()).json() | |
api.add_resource(RpcMultiplexer, '/') | |
if __name__ == '__main__': | |
app.run(port=6001, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment