Simple nodeJS script to connect to Etherscan (using a free API key) to pull incoming transactions, mined blocks and Consensus Layer withdrawal rewards, correlate with the closing day USD price of ETH (from Coingecko's API, using a free DEMO API key), and create a report (CSV) for tax purposes.
Now including optional Google Sheets connectivity!
This script assumes all incoming transactions are Execution Layer proposal rewards and purposefully excludes Uniswap Routers from any incoming internal transaction data.
- run
npm install
- Create a
.env
file and add:
ADDRESS=0X_ETHEREUM_ADDRESS
ETHERSCANAPIKEY=YOUR_ETHERSCAN_API_KEY
COINGECKOAPIKEY=YOUR_COINGECKO_API_KEY
SPREADSHEETID=GOOGLE_SHEETS_SPREADSHEET_ID # optional
SPREADSHEETNAME=GOOGLE_SHEETS_SPREADSHEET_NAME # optional
node getRewards
It is also possible to pass a startDate
and endDate
at the command line to limit the range of the output data. Dates must be formed like mm-dd-yyyy
. Omitting the endDate
will output from startDate
until now
. Omitting both outputs everything.
For Consensus Layer withdrawal rewards, a startBlock
and endBlock
may be specified.
Use the command node getRewards --help
for detailed usage instructions.
If progress seems to stop, it's because the code is backing off the APIs for a moment as the free and demo tiers have rate limits. Don't panic.
Examples:
# get everything - note, you may need to run this multiple times if there are more than 10,000 transactions or withdrawals
node getRewards
# get all EL rewards from 4/13/2023 - 4/15/2023 and all CL withdrawals in blocks 17034893 through 17034895
node getRewards --startDate 04-13-2023 --endDate 04-15-2023 --startBlock 17034893 --endBlock 17034895
# get all EL ever for an address and all CL withdrawals in blocks 17034893 through 17034895
node getRewards -b 17034893 -c 17034895
This tool was created with a focus of not relying on a centralized database or complex setup. That said, it works with both Etherscan and CoinGecko (centralized databases). One has to make a leap of faith that both of these are good actors in the space.
Etherscan's APIs are used to pull in transaction data, withdrawals (aka CL rewards) and "internal" transaction data for EL block rewards, and convert a given block ID to a timestamp.
- Accept multiple addresses
- Specify fiat currency (from available Coingecko currencies)
- User-specified output file
- Add sum-by-date output option
- Documentation on optional Google Sheets connector