Skip to content

Instantly share code, notes, and snippets.

@sh4dowb
Last active Dec 8, 2022
Embed
What would you like to do?
run a fucking ethereum VERY LIGHT client that uses cloudflare rpc
"""
do you have an app that fucking supports geth only?
and after new cryptobros got high and decided you should have at least 1 TB SSD and 10 fucking free days to synchronize to run a "fast" node, you can't be fucking bothered?
well I did, and there you fucking go. this fucking shit gets all stupid motherfucking data from cloudflare and handles account creation and sending etc
fuck you web 3.0
run geth with snap and dont run no consensus or what in the flying fuck that is
note that you probably need to add more methods to the cloudflare array for block and tx fetching etc.
I also added gas price fetching because the app was fucking dumb and sending 0x0
"""
import http.server
import requests
import json
class Proxy(http.server.BaseHTTPRequestHandler):
def do_POST(self):
data = self.rfile.read(int(self.headers['Content-Length'])).decode('utf-8')
decodedData = json.loads(data)
newheaders = {}
for k, v in self.headers.items():
if k.lower() in ['host', 'content-length', 'content-encoding']:
continue
newheaders[k] = v
if decodedData['method'] in ['eth_getBalance','eth_gasPrice','eth_call','eth_getBlockByNumber','eth_getTransactionReceipt','eth_blockNumber','eth_getTransactionByHash']:
r = requests.post('https://cloudflare-eth.com/', data=data, headers=newheaders)
elif decodedData['method'] in ['personal_sendTransaction']:
data = json.dumps({"jsonrpc":"2.0","id":2,"method":"eth_getTransactionCount","params":[decodedData['params'][0]['from'], "pending"]})
print(data)
r = requests.post('https://cloudflare-eth.com/', data=data, headers=newheaders)
print(r.json())
nonce = r.json()['result']
data = json.dumps({"jsonrpc":"2.0","id":2,"method":"eth_gasPrice","params":[]})
print(data)
r = requests.post('https://cloudflare-eth.com/', data=data, headers=newheaders)
gasprice = r.json()['result']
print(r.json())
params1 = {"from":decodedData['params'][0]['from'],"to":decodedData['params'][0]['to'],"value":decodedData['params'][0]['value'],"gas":decodedData['params'][0]['gas'],"gasPrice":gasprice,"nonce":nonce}
if "data" in decodedData['params'][0]:
params1["data"] = decodedData['params'][0]['data']
data = json.dumps({"jsonrpc":"2.0","id":2,"method":"personal_signTransaction","params":[params1,decodedData['params'][1]]})
print(params1)
r = requests.post('http://127.0.0.1:8545', data=data, headers=newheaders)
print(r.json())
data = json.dumps({"jsonrpc":"2.0","id":decodedData['id'],"method":"eth_sendRawTransaction","params":[r.json()['result']['raw']]})
print(data)
r = requests.post('https://cloudflare-eth.com/', data=data, headers=newheaders)
print(r.json())
else:
r = requests.post('http://127.0.0.1:8545' + self.path, data=data, headers=newheaders)
self.send_response(r.status_code)
print("FINALRESP", r.headers, r.content)
self.send_header("Content-Type", "application/json")
self.send_header('Content-Length', len(r.content))
self.end_headers()
self.wfile.write(r.content)
httpd = http.server.HTTPServer(('127.0.0.1', 8546), Proxy)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment