> ## Documentation Index
> Fetch the complete documentation index at: https://docs.groundtech.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate gtoken webhooks

> Receive notifications when contracts become ready, fees change or customer access is updated.

Use gtoken webhooks to receive updates about your contracts, fees and customer
access. Ground sends signed HTTP requests to your application when these operations change status.

## Before you start

You need an API key and a public HTTPS callback URL. Ground rejects callback URLs
with credentials, private or loopback hosts, or nonstandard ports.

The examples use sandbox. Register a separate endpoint with your production API
key at `https://production.groundtech.co` for production events.

Registrations created through v3 receive v3 payloads and are managed through v3. Existing v2 registrations retain v2 payloads and are managed through v2.

## 1. Register your endpoint

Choose the events your application needs:

### Event types

| Event | When it is sent | Operation statuses |
| - | - | - |
| `gvault.status_changed` | Contract setup finishes or fails | `ready`, `failed` |
| `gvault.fees.status_changed` | A fee update needs approval, is submitted or finishes | `awaiting_approval`, `submitted`, `confirmed`, `failed` |
| `gvault.allowlist.status_changed` | A customer access change finishes | `confirmed`, `failed` |

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
export BASE_URL="https://sandbox.groundtech.co"
export GROUND_API_KEY="<your-api-key>"
curl --fail-with-body -X POST "$BASE_URL/v3/gvaults/webhooks" \
  -H "Authorization: Bearer $GROUND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://ops.acme.com/webhooks/ground-gvaults",
    "events": [
      "gvault.status_changed",
      "gvault.fees.status_changed",
      "gvault.allowlist.status_changed"
    ],
    "description": "Sandbox gVault events"
  }'
```

The response includes your registration ID and signing secret:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "6b6a0502-9d38-4f94-83fe-06706adbdc51",
  "url": "https://ops.acme.com/webhooks/ground-gvaults",
  "events": [
    "gvault.status_changed",
    "gvault.fees.status_changed",
    "gvault.allowlist.status_changed"
  ],
  "secret": "4cfd6f64a0b5f9d6fd82f953db57f1c0f530f76513f93d41b495a321d797a6c0",
  "createdAt": "2026-11-13T17:32:08.000Z"
}
```

Store `id` to manage the registration. Store `secret` securely on your server as
`GROUND_WEBHOOK_SECRET`. The example secret is illustrative; use the value from
your response. Ground returns the secret only when the registration is created.
If creation times out, list registrations before retrying. If the secret was
lost, delete the registration and create it again.

## 2. Receive and verify events

Each request includes these headers:

| Header | Use |
| - | - |
| `Ground-Event-Id` | Identify the event and deduplicate retries |
| `Ground-Event-Type` | Identify the event type |
| `Ground-Signature` | Verify the signature and delivery timestamp |

Verify the signature against the raw request body before parsing JSON. Ground
signs `timestamp + "." + rawBody` with HMAC-SHA256 using your registration secret.

The Express example below accepts a `saveEvent` function from your application.
It must save the event durably for background processing, deduplicate by
`event.id` and resolve only after that work is committed. For an event already
saved, it should resolve without adding duplicate work.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const crypto = require('node:crypto');
const express = require('express');

function verifyGroundSignature(rawBody, header, secret) {
  if (typeof header !== 'string') throw new Error('Missing signature');
  const parts = Object.fromEntries(
    header.split(',').map((part) => part.trim().split('=')),
  );
  if (!/^\d+$/.test(parts.t || '') || !/^[0-9a-f]{64}$/.test(parts.v1 || '')) {
    throw new Error('Invalid signature header');
  }
  const timestamp = Number(parts.t);
  if (!Number.isSafeInteger(timestamp) ||
      Math.abs(Math.floor(Date.now() / 1000) - timestamp) > 300) {
    throw new Error('Signature timestamp outside tolerance');
  }
  const expected = crypto.createHmac('sha256', secret)
    .update(`${parts.t}.`)
    .update(rawBody)
    .digest();
  const actual = Buffer.from(parts.v1, 'hex');
  if (!crypto.timingSafeEqual(expected, actual)) throw new Error('Invalid signature');
}

function createWebhookApp({ saveEvent }) {
  const secret = process.env.GROUND_WEBHOOK_SECRET;
  if (!secret) throw new Error('Set GROUND_WEBHOOK_SECRET');
  const app = express();

  app.post('/webhooks/ground-gvaults', express.raw({ type: 'application/json' }), async (req, res) => {
    let event;
    try {
      verifyGroundSignature(req.body, req.get('Ground-Signature'), secret);
      event = JSON.parse(req.body.toString('utf8'));
      if (!event || typeof event.id !== 'string' || typeof event.type !== 'string' ||
          event.id !== req.get('Ground-Event-Id') || event.type !== req.get('Ground-Event-Type')) {
        throw new Error('Invalid event');
      }
    } catch (_) {
      return res.sendStatus(400);
    }

    try {
      await saveEvent(event);
    } catch (_) {
      return res.sendStatus(503);
    }
    return res.sendStatus(200);
  });

  return app;
}

module.exports = { createWebhookApp };
```

Start the returned Express app in your server. Keep this route's raw-body parser
ahead of any JSON middleware. Return `2xx` after saving the event, then process
it in the background. If saving fails, return `503` so Ground can retry.

## 3. Handle events

Deliveries use `{ id, type, createdAt, data }`. Retries keep the same event ID.
Events can arrive more than once or out of order. Deduplicate them by ID and read
the current resource before updating your application's state, so a delayed event
cannot overwrite newer settings.

| Event | Follow-up action |
| - | - |
| `gvault.status_changed` with `ready` | Refresh `GET /v3/gvaults` and select the matching `id` |
| `gvault.status_changed` with `failed` | Record `data.error` and contact Ground; the contract is not available as a ready gVault |
| `gvault.fees.status_changed` | Read `GET /v3/gvaults/{gVaultId}` for current fees and update status |
| `gvault.allowlist.status_changed` | Read `GET /v3/gvaults/{gVaultId}/allowlist/{address}` for the customer's current access |

Use `gVaultId` and `address` from `data` in these requests. An access event's
`allowed` field identifies the requested permission; check `status` and the
access endpoint before treating the change as effective.

### Contract readiness

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "73a8e0c9-c20d-4b10-b9a4-0f0ff6b5cb9c",
  "type": "gvault.status_changed",
  "createdAt": "2026-11-13T17:35:39.000Z",
  "data": {
    "gVaultId": "8f4c52d7-62ab-4db9-a964-92f481f6b851",
    "status": "ready",
    "contractAddress": "0x1111111111111111111111111111111111111111"
  }
}
```

### Customer fee updates

For `awaiting_approval`, use `activityId` with your registered signing key through
the [approval API](https://docs.groundtech.co/v3/docs/portfolio-wallets/transaction-approvals.md#approving-an-activity).

Customer fee events include the requested `feeRecipientAddress`,
`managementFeePct` and `performanceFeePct`. Settings take effect when the update
is `confirmed`; read gVault detail for the current values.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "83a8e0c9-c20d-4b10-b9a4-0f0ff6b5cb9c",
  "type": "gvault.fees.status_changed",
  "createdAt": "2026-11-13T17:40:39.000Z",
  "data": {
    "gVaultId": "8f4c52d7-62ab-4db9-a964-92f481f6b851",
    "status": "awaiting_approval",
    "activityId": "01a1c873-a53b-7c26-8922-752334ca46d1",
    "feeRecipientAddress": "0x3333333333333333333333333333333333333333",
    "performanceFeePct": 15,
    "managementFeePct": 0.2
  }
}
```

### Ground fee updates

Ground fee updates use the same event type, with `groundManagementFeePct`
identifying the requested annual rate:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "93a8e0c9-c20d-4b10-b9a4-0f0ff6b5cb9c",
  "type": "gvault.fees.status_changed",
  "createdAt": "2026-11-13T17:45:39.000Z",
  "data": {
    "gVaultId": "8f4c52d7-62ab-4db9-a964-92f481f6b851",
    "status": "confirmed",
    "groundManagementFeePct": 0.1,
    "transactionHash": "0xabababababababababababababababababababababababababababababababab"
  }
}
```

### Customer access

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "a3a8e0c9-c20d-4b10-b9a4-0f0ff6b5cb9c",
  "type": "gvault.allowlist.status_changed",
  "createdAt": "2026-11-13T17:50:39.000Z",
  "data": {
    "gVaultId": "8f4c52d7-62ab-4db9-a964-92f481f6b851",
    "address": "0x5555555555555555555555555555555555555555",
    "allowed": true,
    "status": "confirmed",
    "transactionHash": "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
  }
}
```

## 4. Troubleshoot deliveries

List delivery history for your registration:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
export WEBHOOK_ID="<registration-id>"
curl --fail-with-body "$BASE_URL/v3/gvaults/webhooks/$WEBHOOK_ID/events" \
  -H "Authorization: Bearer $GROUND_API_KEY"
```

Use `GET /v3/gvaults/webhooks/events` to list deliveries across your organization.
Both endpoints return `data` and `nextCursor`; pass `cursor` to read another page.
Inspect `attemptCount`, `deliveredAt` and `lastError` when delivery fails.

### Delivery statuses

| Status | Meaning |
| - | - |
| `pending` | Delivery is waiting or scheduled for a retry |
| `completed` | Your endpoint returned `2xx` |
| `failed` | Delivery stopped; inspect `lastError` |

Delivery status describes the HTTP request. The operation status is inside the
delivered `data` object, or `payload` in delivery history. For example, delivery
can be `completed` while a fee update reports `failed`.

Ground retries network errors, HTTP `5xx`, and HTTP `408`, `425` and `429` responses
with increasing delays until the attempt limit is reached. Other HTTP errors
stop delivery. Check your endpoint and read the resource's current state if
delivery fails; do not rely on receiving every event.

## Manage your registration

Use [list registrations](https://docs.groundtech.co/v3/api-reference/list-gtoken-webhooks.md) or
[get a registration](https://docs.groundtech.co/v3/api-reference/get-gtoken-webhook.md) to inspect your setup.
To stop deliveries, delete the registration:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --fail-with-body -X DELETE "$BASE_URL/v3/gvaults/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $GROUND_API_KEY"
```

Keep your saved event IDs to recognize duplicate deliveries already in flight.
See the [webhook API reference](https://docs.groundtech.co/v3/api-reference/create-gtoken-webhook.md) for registration fields.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.