Build your own crypto tax calculator with Google Sheets

GoldRush TeamUpdated 14 min read

Build a crypto tax calculator in Google Sheets: an Apps Script menu imports a wallet's token transfers from the GoldRush API, and formulas work out FIFO gains.

To build a crypto tax calculator in Google Sheets, you need two parts: a script that pulls every transfer of a token in and out of your wallet, with the token's price on the day of each transfer, into a sheet, and formulas that match each sale to the units it used up and work out the gain. This guide builds both. A Google Apps Script menu imports one token's transfers from the GoldRush Foundational API, with your API key kept in Script Properties rather than in a cell, and twelve formula columns compute FIFO cost basis, gains, and how much of each gain is long-term or short-term.

The sheet is a starting point, not tax advice: have a tax professional review the figures before you file.

What the Google Sheets tax calculator builds

One spreadsheet with two tabs:

  • Settings: the chain, wallet and token contract to import, in cells B1, B2 and B3.
  • Transfers: one row per transfer, oldest first, filled in by a GoldRush → Import token transfers menu item. Columns A to F are the data (date, IN or OUT, amount in tokens, USD price that day, gas paid in USD, transaction hash). Columns G to R are formulas that work out FIFO cost basis and gains for every OUT row.

The sheet does the arithmetic for one token at a time. It uses FIFO (first in, first out): each sale uses up the oldest units still held. FIFO is what the IRS applies when you don't identify which units you sold (IRS virtual currency FAQ, A41; checked 20 November 2026). For other methods (LIFO, HIFO, specific identification, average cost) and how they change the result, see how to calculate crypto cost basis and capital gains.

What you need for the Google Sheets tax calculator

  • A GoldRush API key. The free trial includes one; you'll paste it into the script in Step 1.
  • Nothing to install. The code is Apps Script, which runs in Google's own JavaScript runtime, not in Node.js 18 or a terminal on your machine.
  • A new Google Sheet. Rename the first tab Settings and fill in:
Row Column A (label) Column B (value)
1 Chain The chain name, such as eth-mainnet or base-mainnet
2 Wallet Your address, or an ENS name such as vitalik.eth
3 Token contract The ERC-20 token's contract address, such as SHIB's 0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE

The importer reads ERC-20 token transfers (transfers_v2). For each transaction that moved the token, it returns the transfer's direction in transfer_type (IN or OUT), the raw amount in delta with the token's contract_decimals, quote_rate (the token's price in your quote currency on the day of the transfer), and the transaction's gas cost in gas_quote.

Step 1: Add the script and store your API key

Open Extensions → Apps Script, replace the contents of Code.gs with the code blocks from steps 1, 2 and 3, and save. The first block adds the menu and keeps the key out of the sheet:

const API = "https://api.covalenthq.com/v1"; // Adds the GoldRush menu when the spreadsheet opens.function onOpen() {  SpreadsheetApp.getUi()    .createMenu("GoldRush")    .addItem("Set API key", "setApiKey")    .addItem("Import token transfers", "importTransfers")    .addToUi();} // Saves the key in Script Properties: never in a cell, so it isn't shared or copied with the sheet's data.function setApiKey() {  const ui = SpreadsheetApp.getUi();  const answer = ui.prompt(    "GoldRush API key",    "Paste your key. It is stored in Script Properties.",    ui.ButtonSet.OK_CANCEL  );  if (answer.getSelectedButton() !== ui.Button.OK) return;  PropertiesService.getScriptProperties().setProperty("GOLDRUSH_API_KEY", answer.getResponseText().trim());} function apiKey() {  const key = PropertiesService.getScriptProperties().getProperty("GOLDRUSH_API_KEY");  if (!key) throw new Error("No API key: run GoldRush → Set API key first.");  return key;}

Reload the spreadsheet, choose GoldRush → Set API key, and approve the permissions Apps Script asks for (it needs to call an external service and edit this spreadsheet). You can also add or change the key under Project Settings → Script properties with the name GOLDRUSH_API_KEY.

Script Properties belong to the script, so anyone who can edit the script can read them. People you share the sheet with as viewers or commenters can't. If editors shouldn't see your key, keep the sheet to yourself.

Step 2: Import a token's transfers

The second block pages through transfers_v2 for the wallet and token in Settings, keeps the fields cost basis needs, and writes them to the Transfers tab, oldest first:

const HEADERS = ["Date", "Type", "Amount", "Price (USD)", "Fee (USD)", "Tx hash"];const MAX_ROWS = 4999; // the formulas in step 3 cover rows 2 to 5000 // A raw integer amount as a token amount: ("1234500", 6) → 1.2345. String maths keeps every digit until the end.function toUnits(raw, decimals) {  const s = String(raw).padStart(decimals + 1, "0");  return Number(s.slice(0, s.length - decimals) + "." + s.slice(s.length - decimals));} // Every transfer of one ERC-20 token in or out of a wallet, oldest first:// [date, "IN" or "OUT", amount, USD price that day, gas the wallet paid in USD, tx hash].function fetchTransfers(chain, wallet, token) {  const headers = { Authorization: "Bearer " + apiKey() };  const rows = [];  for (let page = 0; ; page++) {    const url =      API +      "/" +      chain +      "/address/" +      encodeURIComponent(wallet) +      "/transfers_v2/" +      "?contract-address=" +      token +      "&quote-currency=USD&page-size=100&page-number=" +      page;    const res = UrlFetchApp.fetch(url, { headers: headers, muteHttpExceptions: true });    if (res.getResponseCode() !== 200) throw new Error(res.getResponseCode() + " " + res.getContentText());    const data = JSON.parse(res.getContentText()).data;    for (const tx of data.items) {      if (!tx.successful) continue;      // Gas is the wallet's cost only when it sent the transaction; count it once.      let fee = tx.from_address === data.address ? tx.gas_quote || 0 : 0;      for (const t of tx.transfers) {        if (t.contract_address !== token.toLowerCase()) continue;        // No price that day: text, not a blank (a blank counts as $0), so the gains show #VALUE! until you type it.        const price = t.quote_rate == null ? "no price" : t.quote_rate;        rows.push([          new Date(t.block_signed_at),          t.transfer_type,          toUnits(t.delta, t.contract_decimals),          price,          fee,          t.tx_hash,        ]);        fee = 0;      }    }    if (!data.pagination || !data.pagination.has_more) break;  }  return rows.sort((a, b) => a[0] - b[0]);} function importTransfers() {  const ss = SpreadsheetApp.getActive();  const settings = ss.getSheetByName("Settings").getRange("B1:B3").getValues();  const [chain, wallet, token] = settings.map((r) => String(r[0]).trim());  const rows = fetchTransfers(chain, wallet, token);  if (rows.length > MAX_ROWS) throw new Error(rows.length + " transfers: split the import by block range.");   const sheet = ss.getSheetByName("Transfers") || ss.insertSheet("Transfers");  sheet.getRange("A2:R").clearContent();  sheet.getRange(1, 1, 1, HEADERS.length).setValues([HEADERS]);  if (rows.length) sheet.getRange(2, 1, rows.length, HEADERS.length).setValues(rows);  writeFifoColumns(sheet, rows.length);  ss.toast(rows.length + " transfers imported");}
  • data.address is the wallet's resolved address, so an ENS name works in B2, and the gas check compares like with like.
  • Each run replaces the Transfers tab, so re-importing after new activity is safe.
  • If a transfer comes back without a quote_rate, its price cell says no price and the cost basis and gain of every sale show #VALUE! until you type in the day's price. (A blank cell would count as $0 and give wrong gains without any error.) Historical token prices returns it.
  • For more than 4,999 transfers, add &starting-block= and &ending-block= to the URL and import in ranges.

This is what fetchTransfers reads from each page: a transfers_v2 response for USDT on eth-mainnet, recorded on 3 November 2026 and trimmed to one transaction and the fields the code reads. It becomes one OUT row: 80,000,000 USDT at $1.011, with a fee of $19.89, because the wallet sent the transaction (from_address equals data.address):

{  "data": {    "address": "0x77edef23fbd05921c26fe29fcc3a65e14d2ac3eb",    "chain_name": "eth-mainnet",    "items": [      {        "block_signed_at": "2026-10-29T21:06:47.000Z",        "tx_hash": "0x279d12e9a7f594eeaf0eb83fe649f7f2cdf82ced156a82f85014dc56369b36d8",        "successful": true,        "from_address": "0x77edef23fbd05921c26fe29fcc3a65e14d2ac3eb",        "gas_quote": 19.88923567251063,        "transfers": [          {            "block_signed_at": "2026-10-29T21:06:47.000Z",            "tx_hash": "0x279d12e9a7f594eeaf0eb83fe649f7f2cdf82ced156a82f85014dc56369b36d8",            "contract_decimals": 6,            "contract_ticker_symbol": "USDT",            "contract_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",            "transfer_type": "OUT",            "delta": "80000000000000",            "quote_rate": 1.011037826538086          }        ]      }    ],    "pagination": { "has_more": false, "page_number": 0, "page_size": 100, "total_count": null }  },  "error": false,  "error_message": null,  "error_code": null}

Step 3: Add the FIFO gains columns

FIFO in a spreadsheet is usually done with a helper sheet of lots or a long lookup formula. There's a shorter way. Line every unit ever bought up in order: the first lot is units 0 to 100, the next 100 to 150, and so on. FIFO means a sale uses up the next units in that line. So if 120 units were sold before a sale of 50, that sale used units 120 to 170, and its cost basis is the cost of the first 170 units minus the cost of the first 120.

The cost of the first n units is one SUMPRODUCT: for each lot, the part of it that lies below n, times its unit cost. The part of a lot from start to end that lies below n is (ABS(n-start) - ABS(n-end) + qty) / 2, which is 0 when n is below the lot, qty above it, and n-start inside it. The third block writes that and the other columns into every row:

const FIFO_HEADERS = [  "Lot qty",  "Lot start",  "Lot end",  "Unit cost",  "Sold before",  "Held after",  "Proceeds",  "Cost basis",  "Gain",  "Long-term units",  "Long-term gain",  "Short-term gain",]; // The cost of the first n units ever acquired, in acquisition order.const fifoCost = (n) => `SUMPRODUCT((ABS(${n}-$H$2:$H$5000)-ABS(${n}-$I$2:$I$5000)+$G$2:$G$5000)/2,$J$2:$J$5000)`; // Columns G to R for row r.function fifoFormulas(r) {  const out = (f) => `=IF(B${r}="OUT",${f},"")`; // only on sales  const longUnits = `SUMIFS($G$2:$G$5000,$A$2:$A$5000,"<"&EDATE(INT(A${r}),-12))-K${r}`;  return [    `=IF(B${r}="IN",C${r},0)`, // G lot qty    `=SUM(G$1:G${r - 1})`, // H lot start: units acquired before this row    `=H${r}+G${r}`, // I lot end    `=IF(B${r}="IN",D${r}+E${r}/C${r},0)`, // J unit cost, gas included    `=SUMIFS(C$1:C${r - 1},B$1:B${r - 1},"OUT")`, // K units sold before this row    `=I${r}-K${r}-IF(B${r}="OUT",C${r},0)`, // L units held after this row    out(`C${r}*D${r}-E${r}`), // M proceeds, gas deducted    out(`${fifoCost(`(K${r}+C${r})`)}-${fifoCost(`K${r}`)}`), // N cost basis    out(`M${r}-N${r}`), // O gain    out(`MEDIAN(0,C${r},${longUnits})`), // P units from lots held more than a year    out(`M${r}*P${r}/C${r}-(${fifoCost(`(K${r}+P${r})`)}-${fifoCost(`K${r}`)})`), // Q long-term gain    out(`O${r}-Q${r}`), // R short-term gain  ];} function writeFifoColumns(sheet, count) {  sheet.getRange(1, 7, 1, FIFO_HEADERS.length).setValues([FIFO_HEADERS]);  if (!count) return;  const formulas = [];  for (let r = 2; r < count + 2; r++) formulas.push(fifoFormulas(r));  sheet.getRange(2, 7, count, FIFO_HEADERS.length).setFormulas(formulas);  sheet.getRange("A2:A").setNumberFormat("yyyy-mm-dd hh:mm");}

Row 2 of the result, if you want to read or type the formulas yourself (fifo(n) stands for the SUMPRODUCT above):

Column Header Formula in row 2 What it is
G Lot qty =IF(B2="IN",C2,0) Units this row added; 0 for a sale
H Lot start =SUM(G$1:G1) Units acquired before this row
I Lot end =H2+G2 Units acquired up to this row
J Unit cost =IF(B2="IN",D2+E2/C2,0) Price plus gas per unit
K Sold before =SUMIFS(C$1:C1,B$1:B1,"OUT") Units sold before this row
L Held after =I2-K2-IF(B2="OUT",C2,0) Running balance; negative means a missing transfer
M Proceeds C2*D2-E2 Amount times that day's price, less gas
N Cost basis fifo(K2+C2)-fifo(K2) The cost of the units this sale used up
O Gain M2-N2 Gain, or loss if negative
P Long-term units MEDIAN(0,C2,SUMIFS(G,A,"<"&EDATE(INT(A2),-12))-K2) Units of this sale from lots held more than a year
Q Long-term gain M2*P2/C2-(fifo(K2+P2)-fifo(K2)) The gain on those units
R Short-term gain O2-Q2 The rest

M to R are wrapped in IF(B2="OUT", …, ""), so they show only on sales. Columns P and Q follow the same idea: lots acquired more than a year before the sale fill the start of the line, and the sale's long-term units are the part of it that falls in that stretch. The IRS FAQ counts units held more than one year as long-term (A6); a lot bought on 1 February 2025 turns long-term on 2 February 2026.

Check the result. The last row's Held after should equal the wallet's current balance of the token. Token balances returns it. A difference, or a negative Held after anywhere, means a transfer is missing, often one from another wallet you own.

Step 4: Total your gains

In any empty cell, for example on the Settings tab:

Total Formula
Long-term gain =SUM(Transfers!Q2:Q5000)
Short-term gain =SUM(Transfers!R2:R5000)
For one year =SUMIFS(Transfers!R2:R5000,Transfers!A2:A5000,">="&DATE(2026,1,1),Transfers!A2:A5000,"<"&DATE(2027,1,1))

For a short worked check: buy 100 units at $1.00 with $2 of gas, buy 50 at $2.00, then sell 120 at $3.00 with $1.50 of gas thirteen months after the first buy and eight months after the second. The sheet shows proceeds of $358.50, a cost basis of $142.00 (100 units at $1.02, 20 at $2.00) and a gain of $216.50, of which $196.75 is long-term (the first 100 units) and $19.75 short-term.

To cover several tokens, make a copy of the spreadsheet per token, or add a Token column and import into one tab per token. The formulas work on one token's history at a time.

Using a custom function instead

Apps Script can also expose the import as a custom function, so =GOLDRUSH_TRANSFERS(Settings!B1, Settings!B2, Settings!B3) in a cell spills the transfers into the sheet. Custom functions may use URL Fetch and Script Properties, so it works with the same key:

/** * Every transfer of one ERC-20 token in or out of a wallet, oldest first. * @customfunction */function GOLDRUSH_TRANSFERS(chain, wallet, token) {  return [HEADERS].concat(fetchTransfers(chain, wallet, token));}

The menu is the better default. A custom function must return within 30 seconds, it recalculates (and calls the API again) whenever its arguments change or the script is edited, and the FIFO formulas still need writing next to it. Use the custom function for a quick look at a small wallet; use the menu for the tax sheet.

Handle errors from the GoldRush API in Apps Script

When a request fails, the API answers with a non-200 status and the same envelope as a success, with data set to null. The docs show this body for a chain name it doesn't recognize, with HTTP status 501:

{  "data": null,  "error": true,  "error_message": "Chain nosuchchain-mainnet not supported.",  "error_code": 501}

fetchTransfers throws the status and that body, so Apps Script shows 501 {"data":null,"error":true,…} and the import stops before it touches the sheet. error_code always equals the HTTP status, and error_message says what went wrong:

  • 501: the chain name in B1 is misspelled or not supported. Fix the cell; retrying the same request returns the same answer.
  • 401: the key is missing or wrong. Run GoldRush → Set API key again.
  • 429 or a 5xx: you hit the rate limit or the backend was busy. Wait a few seconds and import again.

Failed requests cost no credits. The error handling page lists every code and what to do about it.

Limits of a FIFO tax spreadsheet

The formulas trust every row. Before you rely on the totals, check what each row really was:

  • Transfers between your own wallets. An OUT to a wallet you own is not a sale (IRS FAQ A38), and an IN from one is not a purchase. Delete those rows, or import each wallet and merge them into one history first.
  • Income. Airdrops, staking rewards and payments are often income when received, at their fair market value then (A13 for crypto received for services). The sheet treats every IN as a purchase at that day's price, which gives the right basis but doesn't report the income.
  • Swaps and native tokens. A swap's OUT row is priced at the sold token's daily price, and ETH or other native coins never appear because the import reads ERC-20 transfers only. The cost basis guide's limits section explains both and where to get native-token rows (transaction history).
  • Prices at the minute. quote_rate is a daily price. If you need the price at the time of a trade, you need another source.

Products that do this across many wallets, chains and clients build on the same data; the crypto tax and accounting page covers the GoldRush endpoints they use.

Credit cost of a token import

Each import re-reads the token's whole history at 0.05 per item for ERC-20 token transfers, one item per transaction, so a 1,000-transaction token costs 50 credits every time you press Import. Filling a missing price costs 1 per call, and a balance check costs 1 per call. If you re-import often, the pricing calculator shows what a month adds up to.

Frequently asked questions

Can I calculate crypto taxes in Google Sheets?

Yes, for the arithmetic. Import each token's transfers with the date, amount and that day's price, then match every sale to the units it used up with a cost basis method such as FIFO. The formulas in this guide do that and split each gain into long-term and short-term. Classifying transfers and applying your tax rules is still up to you.

How do I pull wallet transactions into Google Sheets?

Use Google Apps Script: UrlFetchApp.fetch calls an API such as GoldRush's ERC-20 token transfers endpoint, and setValues writes the rows into a sheet. Run it from a custom menu so it can ask for permissions and isn't limited to 30 seconds like a custom function.

Where should I store an API key in Google Sheets?

In Script Properties (Apps Script, Project Settings, Script properties), read with PropertiesService.getScriptProperties(). A key in a cell is copied with the sheet, visible to anyone it's shared with and easy to leak in a screenshot. Script Properties are readable by the script's editors only.

How do you do FIFO in Google Sheets?

Line up every unit bought in order and number them. A sale uses the next units in the line, so its cost basis is the cost of the first units through the end of the sale minus the cost of the units sold before it. Each of those costs is one SUMPRODUCT over the lots, as in step 3.

Is this tax advice?

No. It shows how to build a spreadsheet that does FIFO arithmetic on your transfers. Whether those figures are what you owe depends on where you live; a tax professional or your tax authority can tell you.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.