# Add e-signatures and clickwrap to Fastify

> Add e-signatures and clickwrap to a Fastify app with the esigncomply package: built-in JSON parsing and a schema on the confirm route. Run on Fastify 5.

Source: https://esigncomply.com/fastify

Stack · Fastify

To add e-signatures and clickwrap to Fastify, install `fastify` and the `esigncomply` package. One route creates the session with the secret key, the browser SDK attaches to your own checkbox and button, and a second route with a JSON schema confirms the record before your app grants anything. Esign Comply seals each acceptance as an independent record anyone can verify.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/fastify)

`npm install fastify @fastify/static esigncomply`

[Fastify quickstart](https://esigncomply.com/docs/quickstart/fastify)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run in Fastify before publishing

**Session route**

server.js (excerpt)

```js
// Step 4: create the session with the secret key. The browser gets the client token only.
app.post("/api/ceremony", async (request, reply) => {
  const { data: session, error } = await esc.sessions.create(
    {
      profile: process.env.ESIGNCOMPLY_PROFILE_ID,
      signer,
      documents: [
        { document: DOCUMENTS.terms, version: "current" },
        { document: DOCUMENTS.privacy, version: "current" },
      ],
      // The page that runs the ceremony: the origin the browser reports, plus its path.
      context: { url: `${request.headers.origin ?? `${request.protocol}://${request.host}`}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return reply.code(502).send({ error: error.code });
  pinned.set(signer.external_id, session.documents.map((d) => d.version_id));
  return { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents };
```

**Schema and confirm route**

server.js (excerpt)

```js
// Step 6: confirm the record with the secret key before the account exists.
// Fastify parses the JSON body itself, and the schema refuses a body without a record ID.
const confirmBody = { type: "object", required: ["recordId"], properties: { recordId: { type: "string" } } };

app.post("/api/signup/confirm", { schema: { body: confirmBody } }, async (request, reply) => {
  const { data: record, error } = await esc.records.get(request.body.recordId);
  const expected = [...(pinned.get(signer.external_id) ?? [])].sort();
  const confirmed =
    !error &&
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === signer.external_id &&
    JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify(expected);
  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused");
  if (!confirmed) return reply.code(409).send({ confirmed: false });
  // Only now create the account, and store record.id and record.receipt with it.
  return { confirmed: true, recordId: record.id };
```

**Signup page**

server.js (excerpt)

```js
// The signup page.
app.register(fastifyStatic, { root: join(import.meta.dirname, "public") });
app.get("/signup", (request, reply) => reply.sendFile("signup.html"));
```

Integrate with Fastify

## How do you integrate Esign Comply with Fastify?

Fastify does two parts of the integration for you. It parses the JSON body, so the confirm route reads `request.body.recordId` with no plugin, and a JSON schema on that route refuses a malformed body before the handler runs. An async handler returns the payload, and `reply.code(409).send(...)` refuses.

Fastify natively supports the application/json and text/plain content types.

Source: [Fastify documentation, Content-Type Parser](https://fastify.dev/docs/latest/Reference/ContentTypeParser/), read on November 24, 2026.

[Fastify quickstart](https://esigncomply.com/docs/quickstart/fastify) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Fastify

- **Session route** · `server.js`
- **Schema and confirm route** · `server.js`
- **Signup page** · `server.js`

Run on 2026-11-26 with Fastify 5.12.8 and @fastify/static 10.1.12 on Node.js 24.22.1, esigncomply 1.0.4, the browser SDK script build and the conformance check from esigncomply 1.0.4 (--timeout 60), against the API in test mode.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Fastify app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Fastify, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap in Fastify

```
Add Esign Comply clickwrap to my Fastify app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/fastify.md (the steps and the tested code for Fastify)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Fastify facts
- Packages (the only ones that exist): esigncomply (server, Node.js 20.19 or later, an ES module) and @esigncomply/browser. Without a bundler, load the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is in ESIGNCOMPLY_API_KEY, in a .env file loaded with: node --env-file=.env server.js. Never print it.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- Fastify parses JSON bodies itself. Put a JSON schema on the confirm route so a body without recordId is refused before the handler runs. A request with Content-Type application/json and an empty body is answered 400 by Fastify: the page must send no content type when it sends no body.
- Fastify listens on 127.0.0.1 unless listen() gets a host.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Server: app.post("/api/ceremony") creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in server-owned state, and returns only clientToken, apiUrl and documents.
4. Server: app.get("/legal/:slug") renders the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Server: app.post("/api/signup/confirm") reads the record with esc.records.get and requires: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the server-owned state. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures in Fastify?

These are specific to Fastify. Each one was seen while the quickstart's code was run, or is in Fastify's own documentation.

- **A JSON content type with an empty body is refused with 400**

  In a test on Fastify 5.12.8, a `POST` to `/api/ceremony` with `Content-Type: application/json` and no body was answered `400` with `FST_ERR_CTP_EMPTY_JSON_BODY` before the handler ran. The same `POST` with no content type, which is what the signup page sends, was answered `200`.

- **Fastify listens on 127.0.0.1 unless you pass a host**

  `app.listen({ port })` bound to `127.0.0.1` in the test, and a request through the machine's own network address was refused. With `host: "0.0.0.0"` the same request succeeded. Pass the host in a container, or nothing outside it reaches the server.

- **The schema answers before the record check**

  A body without `recordId` never reaches the handler: the schema answered `400` with `FST_ERR_VALIDATION` in the test. A body with a made-up record ID passed the schema, reached the API, and was refused with `409`. Both are refusals, with two different status codes.

## Where are the Fastify quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Fastify quickstart](https://esigncomply.com/docs/quickstart/fastify)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature in Fastify?

The same record on every stack and platform. Your Fastify code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures in Fastify

### Is there an Esign Comply SDK for Fastify?

Yes. Fastify runs on Node.js, so it uses the `esigncomply` server package directly, with the browser SDK for the page. There is no Fastify plugin to register for it: the integration is three routes of your own and `@fastify/static` for the page.

### Where do I create the session in Fastify?

In a route handler, for example `app.post("/api/ceremony")`, with `esc.sessions.create` and the secret key. The async handler returns only the client token, the API URL and the pinned documents, and Fastify sends them as JSON.

### Does Fastify need a body parser for the confirm route?

No. Fastify parses `application/json` bodies itself, so `request.body` is an object with no plugin added. The quickstart was run on Fastify 5.12.8, and its confirm route read the record ID straight from `request.body`.

### What does the JSON schema on the confirm route add?

It refuses a malformed request before the handler and before any API call. In the test run, a body without `recordId` was answered `400` by the schema, and a made-up record ID reached the handler and was refused with `409`.

### Why can nothing outside my machine reach the Fastify server?

Because Fastify listens on `127.0.0.1` unless `listen` gets a host. In a test, a request through the machine's network address was refused, and it succeeded once the server listened with `host: "0.0.0.0"`.

### Other stacks

- [Express](https://esigncomply.com/express)
- [Hono](https://esigncomply.com/hono)
- [Node.js](https://esigncomply.com/nodejs)

### Platforms used with Fastify

- [AWS Lambda](https://esigncomply.com/aws-lambda)
- [Netlify](https://esigncomply.com/netlify)
- [Vercel](https://esigncomply.com/vercel)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Add three routes to your Fastify app. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/fastify)

Free plan: 10 live signatures a month and a full test mode. No card required.

Fastify is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Fastify is from Fastify's documentation or from a test run, as marked, on November 24, 2026. `/fastify.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
