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.
How It Works
Registration - A handler contract registers with the main Ethscriptions contract
Creation - User creates an ethscription with protocol parameters in the Data URI
Routing - The Ethscriptions contract detects the protocol and calls the handler
Execution - The handler performs custom logic (mint tokens, add to collection, etc.)
User β L1 Transaction β Derivation Node β Ethscriptions Contract β Protocol HandlerBuilt-in Protocols
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:
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 nameop- Operation nameAdditional 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
ProtocolHandlerFailedbut don't revert the ethscription creation
Last updated