Created
May 15, 2024 06:25
-
-
Save cassc/4ba4df83079a9216ba2f6ddb7f910e1e to your computer and use it in GitHub Desktop.
Use cast run to get traces as json
This file contains 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
# ❯ CAST_BIN=[optional-cast-binary-full-path] python cast-json-example.py | |
import subprocess | |
import json | |
import os | |
import tempfile | |
cast_bin = os.environ.get('CAST_BIN', 'cast') | |
def cast_run(rpc_url, txhash): | |
with tempfile.NamedTemporaryFile(delete=True) as tmpfile: | |
output = tmpfile.name | |
result = subprocess.run([cast_bin, 'run', '-r', rpc_url, txhash, '--output', output ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True, check=True) | |
result.check_returncode() | |
return json.load(open(output)) | |
if __name__ == "__main__": | |
data = cast_run('https://rpc.ankr.com/arbitrum', '0x979ad9b7f5331ea8034305a83b5cd50aea88adec395fff8298dd90eb1b87667f') | |
print("Parsed JSON data:") | |
print(json.dumps(data, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment