import json, urllib.request, time
U = 'https://rpc.mainnet.chain.robinhood.com'; UA = 'Mozilla/5.0 (Macintosh) Chrome/128'
def rpc(m, p, tries=7):
    for i in range(tries):
        try:
            r = json.loads(urllib.request.urlopen(urllib.request.Request(U, json.dumps(dict(jsonrpc='2.0', id=1, method=m, params=p)).encode(), {'Content-Type': 'application/json', 'User-Agent': UA}), timeout=40).read())
            if 'error' in r:
                msg = str(r['error'].get('message', ''))
                if 'exceeds limit' in msg or 'timed out' in msg or 'narrow' in msg: return r
                if i == tries - 1: return r
                time.sleep(2 + 2 * i); continue
            return r['result']
        except Exception as e:
            if i == tries - 1: return {'error': str(e)}
            time.sleep((8 + 6 * i) if '429' in str(e) else (1 + 2 * i))
TR = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
INIT = '0xdd466e674ea557f56295e2d0218a125ea4b4f0f6f3307b95f85e6110838d6438'
PM = '0x8366a39cc670b4001a1121b8f6a443a643e40951'
