Skip to content

Instantly share code, notes, and snippets.

@0xlxy
Last active April 26, 2023 23:32
Show Gist options
  • Save 0xlxy/2cfd874b1a56c793df714ad7967d2797 to your computer and use it in GitHub Desktop.
Save 0xlxy/2cfd874b1a56c793df714ad7967d2797 to your computer and use it in GitHub Desktop.
Script for Pirate Nation's total gas fee spent on Arbitrum Nova
import requests
# API endpoint for retrieving transaction information
api_url = "https://api-nova.arbiscan.io/api"
# Address of the smart contract
contract_address = "0x3b4cdb27641bc76214a0cb6cae3560a468d9ad4a"
# Start and end blocks to search for transactions
start_block = 0
end_block = 9999999
# API key (optional)
api_key = "DH6G7DPYQWIDH8GIS4R94SY3RVY18NHJ9K"
# Query parameters
query_params = {
"module": "account",
"action": "txlist",
"address": contract_address,
"startblock": start_block,
"endblock": end_block,
"sort": "asc",
"apikey": api_key
}
# Send the query to the API
response = requests.get(api_url, params=query_params)
# Calculate the total gas fees spent on transactions
total_gas_fees = 0
transactions = response.json()["result"]
for transaction in transactions:
gas_price = int(transaction["gasPrice"], 16)
gas_used = int(transaction["gasUsed"], 16)
total_gas_fees += gas_price * gas_used
# Convert total gas fees from wei to ethers
wei_per_eth = 1000000000000000000 # Wei per ETH
total_gas_fees_ether = total_gas_fees / wei_per_eth
print("Total transactions: ", len(transactions))
print("Total gas fees spent on transactions: ", total_gas_fees_ether, "ETH")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment