Protocol Handlers

Extend ethscriptions with pluggable protocol handlers

Protocol handlers allow developers to extend ethscription functionality with custom on-chain logic. When an ethscription includes protocol parameters, the Ethscriptions contract routes the call to a registered handler.

Protocol handlers are an AppChain-only feature. They require smart contract execution on the L2.

How It Works

  1. Registration - A handler contract registers with the main Ethscriptions contract

  2. Creation - User creates an ethscription with protocol parameters in the Data URI

  3. Routing - The Ethscriptions contract detects the protocol and calls the handler

  4. Execution - The handler performs custom logic (mint tokens, add to collection, etc.)

User β†’ L1 Transaction β†’ Derivation Node β†’ Ethscriptions Contract β†’ Protocol Handler

Built-in Protocols

Protocol
Purpose
Documentation

erc-721-ethscriptions-collection

Curated NFT collections with merkle enforcement

erc-20-fixed-denomination

Fungible tokens with fixed-denomination notes

Protocol Data URI Format

Protocols are invoked by adding parameters to the Data URI. Two encoding styles are supported:

Header-Based (for binary content)

Best for images and other binary data where the content itself is the payload:

Parameter
Description

p=<protocol>

Protocol handler name (lowercase)

op=<operation>

Operation to invoke on the handler

d=<base64>

Base64-encoded JSON parameters

rule=esip6

(Optional) Allow duplicate content URIs

JSON Body (for text-based operations)

Best for operations where the parameters ARE the content:

The JSON body contains:

  • p - Protocol handler name

  • op - Operation name

  • Additional operation-specific fields

Example: Creating a Collection Item

Header-based format for adding an image to a collection:

Where the base64-decoded d parameter contains:

Example: Deploying a Token

JSON body format for deploying a fixed-denomination token:

Protocol Handler Contract Interface

Handlers implement operation functions prefixed with op_:

The exact function signature depends on the operation. For example, the collections manager has:

  • op_create_collection_and_add_self(...)

  • op_add_self_to_collection(...)

  • op_edit_collection(...)

Events

The Ethscriptions contract emits events for protocol operations:

Registration

Protocols are registered at genesis or through governance. The main contract maintains a mapping:

When an ethscription with protocol params is created, the contract looks up the handler and calls the appropriate op_* function.

Security Considerations

  • Protocol handlers run within the Ethscriptions contract's context

  • Handlers cannot modify ethscription ownership directly

  • All state changes are atomic with the ethscription creation

  • Failed handler calls emit ProtocolHandlerFailed but don't revert the ethscription creation

Last updated