{
  "id": "bxHiJI04Rm0lO9HySi7-X",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Query web3 wallet balance, send data to BigQuery & GA4 and Discord whale alert",
  "tags": [
    {
      "id": "DJcYrZuaomqXolEb",
      "name": "bigquery",
      "createdAt": "2026-02-03T12:14:23.761Z",
      "updatedAt": "2026-02-03T12:14:23.761Z"
    },
    {
      "id": "hxhinyNy2Xb3p64A",
      "name": "web3",
      "createdAt": "2026-02-03T12:14:25.662Z",
      "updatedAt": "2026-02-03T12:14:25.662Z"
    },
    {
      "id": "m5iCWoJAMNpsodp3",
      "name": "ga4",
      "createdAt": "2026-01-25T15:28:48.821Z",
      "updatedAt": "2026-01-25T15:28:48.821Z"
    }
  ],
  "nodes": [
    {
      "id": "1d0a4bb5-0e3a-47dc-adb9-f33e6a1bb1b6",
      "name": "Webhook - Receive data from GTM",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1136,
        240
      ],
      "parameters": {
        "path": "wallet_ingest",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f089dcc1-b3c2-48d6-a2b4-adb891792086",
      "name": "HTTP Request - Query wallet balance in Zerion",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -912,
        240
      ],
      "parameters": {
        "url": "=https://api.zerion.io/v1/wallets/{{$json.body.wallet_address}}/portfolio?currency=usd",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        },
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "ba6d173a-6c35-421d-89d7-28bca5f9a9e9",
      "name": "HTTP Request - Send Measurement Protocol Hit Wallet Balance",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -464,
        48
      ],
      "parameters": {
        "url": "https://www.google-analytics.com/mp/collect?measurement_id=G-6ZRWY6SYN7&api_secret=XPOhYOSeTduRKY7R4zPL6g",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"client_id\": \"{{ $json.ga_client_id }}\",\n  \"events\": [\n    {\n      \"name\": \"connect_wallet\", \n      \"params\": {\n        \"wallet_usd_balance\": {{ $json.wallet_usd_balance }},\n        \"engagement_time_msec\": \"100\",\n        \"session_id\": \"{{ $json.ga_session_id }}\" \n      }\n    }\n  ]\n}",
        "sendBody": true,
        "contentType": "=json",
        "specifyBody": "json",
        "bodyParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "1b70d51e-0922-4842-8309-45e3b34618ac",
      "name": "Edit Fields ",
      "type": "n8n-nodes-base.set",
      "position": [
        -688,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "be1eb1bf-8623-4ca8-a2f9-2ef8a4b60643",
              "name": "wallet_usd_balance",
              "type": "string",
              "value": "={{$json.data.attributes.total.positions}}"
            },
            {
              "id": "10a32845-ce83-4361-ba47-1855d2c98217",
              "name": "hashed_wallet_id",
              "type": "string",
              "value": "={{ $('Webhook - Receive data from GTM').item.json.body.hashed_wallet_id }}"
            },
            {
              "id": "688570ca-c158-40ab-a882-3a1b7f70aff7",
              "name": "ga_client_id",
              "type": "string",
              "value": "={{ $('Webhook - Receive data from GTM').item.json.body.ga_client_id }}"
            },
            {
              "id": "aad1a7d8-61b3-4c63-80f5-95da18cccfbc",
              "name": "ga_session_id",
              "type": "string",
              "value": "={{ $('Webhook - Receive data from GTM').item.json.body.ga_session_id }}"
            },
            {
              "id": "e46e8e48-7a95-472c-b6bd-0b6cae472dc1",
              "name": "wallet_id",
              "type": "string",
              "value": "={{ $('Webhook - Receive data from GTM').item.json.body.wallet_address }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e5512096-4a45-458f-86f7-0daeee3c3715",
      "name": "BigQuery - Send wallet address to a table",
      "type": "n8n-nodes-base.googleBigQuery",
      "position": [
        -464,
        240
      ],
      "parameters": {
        "options": {},
        "tableId": {
          "__rl": true,
          "mode": "list",
          "value": "wallet_mapping",
          "cachedResultName": "wallet_mapping"
        },
        "dataMode": "define",
        "fieldsUi": {
          "values": [
            {
              "fieldId": "wallet_address",
              "fieldValue": "={{ $json.wallet_id }}"
            },
            {
              "fieldId": "hashed_wallet_id",
              "fieldValue": "={{ $json.hashed_wallet_id }}"
            },
            {
              "fieldId": "ga_client_id",
              "fieldValue": "={{ $json.ga_client_id }}"
            },
            {
              "fieldId": "ga_session_id",
              "fieldValue": "={{ $json.ga_session_id }}"
            }
          ]
        },
        "datasetId": {
          "__rl": true,
          "mode": "list",
          "value": "wallets",
          "cachedResultName": "wallets"
        },
        "operation": "insert",
        "projectId": {
          "__rl": true,
          "mode": "list",
          "value": "scalo-labs-testing",
          "cachedResultUrl": "https://console.cloud.google.com/bigquery?project=scalo-labs-testing",
          "cachedResultName": "scalo-labs-testing"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "fd749ec1-5489-46b6-9506-485d4967fc11",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1680,
        -336
      ],
      "parameters": {
        "width": 1792,
        "height": 976,
        "content": "## Query web3 wallet USD balance + send data to BigQuery & GA4 through Measurement Protocol \n\n## How it works\n\nThis workflow seamlessly receives wallet details from Google Tag Manager, queries the wallet USD balance in Zerion and passes the wallet balance details to BigQuery and Google Analytics as a custom metric through the Measurement Protocol system.  It also runs a check and if the wallet balance is greater than a set amount, it sends a message to a specific Discord channel with a 'Whale alert; their usd balance and balances by each blockchain'\nVideo walkthrough: https://youtu.be/2_wuTRzRpkg\n\n## Setup steps\n\n1.  **Webhook trigger**: Configure a POST n8n link to ingest the wallet details directly from Google Tag Manager, once the user connects their wallet on the website.\n2.  **Credentials**: Configure credentials for GA4, Zerion and BigQuery.\n3.  **HTTP Request for wallet balance**: Queries wallet balance in Zerion API\n4. **HTTP request**: Send a POST event to GA4 with the wallet balance as a measurement protocol hit to append the details to an already existing session/client id\n5. **BigQuery** : Send wallet address, hashed wallet address, USD balance, session and client id to map GA4 data to BigQuery (using hashed wallet address as a join key)\n6. **Switch** Check if USD balance is higher than a particular amount\n7. **If condition is met, send a message to a Discord channel sharing wallet balance details, wallet id and balance by each chain."
      },
      "typeVersion": 1
    },
    {
      "id": "6e8d44e0-c087-49cf-a7b6-a0a13fec0b9c",
      "name": "Switch - Check if balance>50 to know whale",
      "type": "n8n-nodes-base.switch",
      "position": [
        -464,
        432
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8dfef380-0168-4712-9ec5-1b6e4bb85ac1",
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    },
                    "leftValue": "={{ $json.wallet_usd_balance.toNumber() }}",
                    "rightValue": 50
                  }
                ]
              }
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "87eb6e4a-d09b-43b8-9f9b-7e1e47dfb685",
      "name": "Send a message to admin channel - whale wallet balance details",
      "type": "n8n-nodes-base.discord",
      "position": [
        -240,
        432
      ],
      "parameters": {
        "content": "=\ud83d\udea8 **WHALE ALERT** \ud83d\udea8\nTotal Balance: ${{ $json.wallet_usd_balance.toNumber().toFixed(2) }}\nWallet: {{ $json.wallet_id }}\n\n**Chain Breakdown:**\n{{ Object.entries($node[\"HTTP Request - Query wallet balance in Zerion\"].json.data.attributes.positions_distribution_by_chain).filter(c => c[1] > 0.1).map(c => \"\u2022 \" + c[0].toUpperCase() + \": $\" + c[1].toFixed(2)).join('\\n') }}\n\n[View Portfolio](https://app.zerion.io/{{ $json.wallet_id }}/overview)",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "1477397884948185342",
          "cachedResultUrl": "https://discord.com/channels/1477397884948185342",
          "cachedResultName": "Block Raptor's server"
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "1477397986873970880",
          "cachedResultUrl": "https://discord.com/channels/1477397884948185342/1477397986873970880",
          "cachedResultName": "whale-connected"
        }
      },
      "credentials": {
        "discordBotApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    }
  ],
  "active": true,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "00ae1c62-8b10-4951-bd8c-25e4e4cf269f",
  "connections": {
    "Edit Fields ": {
      "main": [
        [
          {
            "node": "HTTP Request - Send Measurement Protocol Hit Wallet Balance",
            "type": "main",
            "index": 0
          },
          {
            "node": "BigQuery - Send wallet address to a table",
            "type": "main",
            "index": 0
          },
          {
            "node": "Switch - Check if balance>50 to know whale",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - Receive data from GTM": {
      "main": [
        [
          {
            "node": "HTTP Request - Query wallet balance in Zerion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch - Check if balance>50 to know whale": {
      "main": [
        [
          {
            "node": "Send a message to admin channel - whale wallet balance details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Query wallet balance in Zerion": {
      "main": [
        [
          {
            "node": "Edit Fields ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}