Skip to content

Commit

Permalink
Use etherscan API to fetch contract ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Thomas committed Aug 6, 2017
1 parent 972b0a9 commit 5d594f9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions bin/scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,29 @@ fetch_etherscan_contract() {
| awk -v pattern='>(.*)[<\\/pre>|<\\/div>]$' '{ while (match($0, pattern)) { printf("%s\n", substr($0, RSTART + 1, RLENGTH - 7)); $0=substr($0, RSTART + RLENGTH) } }' \
| sed 's/<\/div>$//g')

abi=$(echo "$response" | sed 's/<br>/\n&/g' \
| grep '<pre' \
| grep -i 'contract abi' \
| egrep 'js-copytextarea2|12pc' \
| sed 's/&nbsp;<pre/\n&/g' \
| grep '<pre' \
| awk -v pattern='>(.*)[<\\/pre>|<\\/div>]$' '{ while (match($0, pattern)) { printf("%s\n", substr($0, RSTART + 1, RLENGTH - 7)); $0=substr($0, RSTART + RLENGTH) } }')
echo "${bytecode}" > $CACHE_PATH/${address}/bytecode

if [ "$DEBUG_OUTPUT" == "true" ]; then
echo "DEBUG: Retrieved bytecode ${bytecode} for contract at address: ${address}"
echo "DEBUG: Retrieved abi ${abi} for contract at address: ${address}"
fi

echo "${bytecode}" > $CACHE_PATH/${address}/bytecode
fetch_etherscan_contract_abi $address
}

fetch_etherscan_contract_abi() {
address=$1

if [ "$DEBUG_OUTPUT" == "true" ]; then
echo "Fetching Ethereum contract ABI from etherscan: ${address}"
fi

abi=$(curl --silent https://api.etherscan.io/api?module=contract&action=getabi&address=${address} | python -c "import sys, json; print json.load(sys.stdin)['result']")

if [ ! -z "$abi" ]; then
if [ "$DEBUG_OUTPUT" == "true" ]; then
echo "DEBUG: Retrieved abi ${abi} for contract at address: ${address}"
fi

echo "${abi}" > $CACHE_PATH/${address}/abi
fi
}
Expand Down

0 comments on commit 5d594f9

Please sign in to comment.