Last active
October 29, 2019 09:23
-
-
Save nordicdyno/0f829172257e4361803f4d0db823aa9b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Illustrates my confusion with how to properly read events via Ethersan API | |
# | |
# Script code depends on bash and httpie util (https://httpie.org/) | |
# | |
# Based on https://etherscan.io/apis#accounts Get a list of "ERC20 - Token Transfer Events" by Address | |
#!/bin/bash | |
# https://etherscan.io/apis#accounts Get a list of "ERC20 - Token Transfer Events" by Address | |
API=https://api-ropsten.etherscan.io | |
PAGE=1 | |
OFFSET=10 | |
get_events_address () { | |
FROM=${BLOCK} | |
TO=${BLOCK} | |
echo "get_events_address: CONTRACT=${CONTRACT} -> ${FROM}:${TO}" | |
http --print=Hb "${API}/api?module=account&action=tokentx&address=${CONTRACT}&page=${PAGE}&offset=${OFFSET}&sort=asc&startblock=${FROM}&endblock=${TO}" | |
} | |
get_events_contractaddress () { | |
FROM=${BLOCK} | |
TO=${BLOCK} | |
echo "get_events_contractaddress: CONTRACT=${CONTRACT} -> ${FROM}:${TO}" | |
http --print=Hb "${API}/api?module=account&action=tokentx&contractaddress=${CONTRACT}&page=${PAGE}&offset=${OFFSET}&sort=asc&startblock=${FROM}&endblock=${TO}" | |
} | |
get_logs () { | |
FROM=${BLOCK} | |
TO=${BLOCK} | |
echo "get_logs: CONTRACT=${CONTRACT} -> ${FROM}:${TO}" | |
http --print=Hb "${API}/api?module=logs&action=getLogs&address=${CONTRACT}&fromBlock=${FROM}&toBlock=${TO}" | |
} | |
echo "CASE #1: https://ropsten.etherscan.io/tx/0xa7fc6671038ce1650fb23db087d28f15642acb889834ebdf76be5b0815937ca2" | |
CONTRACT=0x4da6422d45e8b1535f9dd4ae0971ffd56ab10470 | |
BLOCK=6496137 | |
get_events_address | |
get_events_contractaddress | |
get_logs | |
echo "CASE #2: https://ropsten.etherscan.io/tx/0x9c4a76590d89617ec5e6380cc3c03b3b8a092d3b6d0edf6814ae1003af8b88d6" | |
CONTRACT=0x8949e85cfa93de23ffa751e7c97ec31207e801f3 | |
BLOCK=6642512 | |
get_events_address | |
get_events_contractaddress | |
get_logs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment