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
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.)
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 the IProtocolHandler interface:
Operation functions (prefixed with op_) are called dynamically based on the op parameter in the data URI. For example, the collections manager implements:
op_create_collection_and_add_self(...)
op_add_self_to_collection(...)
op_edit_collection(...)
These are not part of the interface - the Ethscriptions contract uses dynamic dispatch to call them.
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
interface IProtocolHandler {
// Called when ethscription is transferred
function onTransfer(
bytes32 ethscriptionId,
address from,
address to
) external;
// Returns the protocol name
function protocolName() external pure returns (string memory);
}