# Gas · Google Sheets (internal)

Run the ETH deposit/withdrawal explorer **inside Google Sheets**.  
Address goes in **cell A1**.

## One-time setup (2 minutes)

1. Open [Google Sheets](https://sheets.google.com) → **Blank** spreadsheet.
2. **Extensions → Apps Script**.
3. Delete any stub code. Create two files:
   - `Code.gs` — paste contents of `Code.gs` from this folder  
   - `appsscript.json` — **View → Show manifest file**, paste `appsscript.json`  
     (enables `UrlFetchApp` + Sheets scopes)
4. **Save** (disk icon). Name project e.g. `BFM Gas`.
5. Close the Apps Script tab. Reload the Sheet.
6. You should see a **Gas** menu.  
   First run: **Gas → 1. Setup Control sheet layout**  
   Allow permissions when prompted (needs access to *this* spreadsheet + external URL fetch).

## Every use

| Cell | What |
|------|------|
| **A1** | Ethereum address `0x…` (**required**) |
| A2 | From date (inclusive, optional) |
| A3 | To date (inclusive, optional) |
| A4 | After date (exclusive, optional) |
| A5 | Before date (exclusive, optional) |
| A6 | Kinds: `eth,token,internal` (default) |
| A7 | `blockscout` or `etherscan` |
| A8 | Optional Etherscan API key |
| A9 | Optional API URL override |
| A11 | Status (written by script) |

Then: **Gas → 2. Fetch deposits & withdrawals (A1)**

### Output sheets
- **Flows** — all deposits (IN) / withdrawals (OUT)  
- **ByCounterparty** — unique peers  
- **ByToken** — unique tokens  
- **ByPair** — unique peer × token  

## Notes
- Uses public API: `https://bitcoin-fund-manager.com/apps2/gas/api.php`  
  (Blockscout-backed; same as the web app.)
- Mainnet only. Read-only. No private keys.
- Large wallets may take 30–90s (explorer pagination + rate limits).
- If fetch fails: confirm the sheet can call external URLs (Apps Script → Project settings → Google Cloud project with URL Fetch allowed; consumer accounts usually work by default after OAuth).

## Copy into a shared team sheet
1. Set up once as above.  
2. **File → Make a copy** for each user, **or**  
3. Deploy as **Library** (advanced) and bind from other spreadsheets.

## Local files
```
apps2/gas/sheets/
  Code.gs           ← paste into Apps Script
  appsscript.json   ← manifest (scopes)
  SETUP.md          ← this file
```
