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

# Onchain execution engine

> Understand how the EVM execution engine deploys agreement definitions and enforces valid inputs, issuers, states, transitions, and history.

export const OnchainProtocolDiagram = () => <div className="shodai-diagram-frame not-prose my-6 overflow-hidden rounded-lg border shadow-sm">
    <svg className="shodai-architecture-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1320 560" role="img" aria-labelledby="onchain-protocol-diagram-title onchain-protocol-diagram-desc">
            <title id="onchain-protocol-diagram-title">Onchain execution engine flow</title>
            <desc id="onchain-protocol-diagram-desc">A diagram showing JSON agreement templates, the Agreements SDK, Agreement Factory, Agreement Engine instance, input verifiers, and actions.</desc>
            <defs>
              <marker id="onchain-protocol-arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
                <polygon points="0 0, 10 3.5, 0 7" fill="var(--shodai-diagram-accent)" />
              </marker>
              <pattern id="onchain-protocol-grid" width="28" height="28" patternUnits="userSpaceOnUse">
                <path d="M 28 0 L 0 0 0 28" fill="none" stroke="var(--shodai-diagram-grid)" strokeWidth="0.5" />
                <circle cx="1" cy="1" r="1" fill="var(--shodai-diagram-line)" />
              </pattern>
            </defs>
    
            <rect width="100%" height="100%" fill="var(--shodai-diagram-bg)" />
    
            <rect width="100%" height="100%" fill="url(#onchain-protocol-grid)" />
    
            {}
            <line x1="148" y1="280" x2="225" y2="280" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
            <path d="M 390 280 L 425 280 Q 455 280 455 250 L 455 165 Q 455 125 495 125 L 505 125" fill="none" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
            <line x1="620" y1="125" x2="725" y2="125" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
            <rect x="641" y="82" width="70" height="34" rx="6" fill="var(--shodai-diagram-bg)" opacity="1" />
            <text x="676" y="96" fill="var(--shodai-diagram-muted)" fontSize="11" textAnchor="middle">EIP-1167</text>
            <text x="676" y="111" fill="var(--shodai-diagram-muted)" fontSize="11" textAnchor="middle">Clone</text>
    
            <line x1="390" y1="280" x2="725" y2="280" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
            <path d="M 390 280 L 565 280 Q 585 280 585 315 L 585 350 Q 585 378 625 378 L 725 378" fill="none" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
    
            <line x1="1030" y1="185" x2="1150" y2="185" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
            <path d="M 1030 255 L 1075 255 Q 1100 255 1100 292 Q 1100 322 1130 322 L 1150 322" fill="none" stroke="var(--shodai-diagram-connector)" strokeWidth="2.2" markerEnd="url(#onchain-protocol-arrowhead)" />
    
            {}
            <rect x="30" y="238" width="118" height="84" rx="8" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="30" y="238" width="118" height="84" rx="8" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="2" />
            <text x="89" y="273" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">JSON Agreement</text>
            <text x="89" y="293" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">Template</text>
    
            {}
            <rect x="225" y="238" width="165" height="84" rx="8" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="225" y="238" width="165" height="84" rx="8" fill="var(--shodai-diagram-surface-alt)" stroke="var(--shodai-diagram-connector)" strokeWidth="2" />
            <text x="307" y="286" fill="var(--shodai-diagram-ink)" fontSize="14" fontWeight="600" textAnchor="middle">Agreements SDK</text>
    
            {}
            <rect x="500" y="82" width="125" height="86" rx="8" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="500" y="82" width="125" height="86" rx="8" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="2" />
            <text x="562" y="121" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">Agreement</text>
            <text x="562" y="140" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">Factory</text>
    
            {}
            <rect x="725" y="65" width="305" height="398" rx="10" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="725" y="65" width="305" height="398" rx="10" fill="var(--shodai-diagram-tint-soft)" stroke="var(--shodai-diagram-accent)" strokeWidth="2.2" />
            <rect x="725" y="65" width="305" height="84" rx="10" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="2" />
            <text x="877" y="117" fill="var(--shodai-diagram-ink)" fontSize="15" fontWeight="700" textAnchor="middle">Agreement Engine Instance</text>
    
            {}
            <rect x="755" y="181" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="811" y="207" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">inputs</text>
    
            <rect x="888" y="181" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="944" y="207" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">verifiers</text>
    
            <rect x="755" y="252" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="811" y="278" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">transitions</text>
    
            <rect x="888" y="252" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="944" y="278" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">actions</text>
    
            <rect x="755" y="323" width="245" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="877" y="349" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">initialize</text>
    
            <rect x="755" y="394" width="245" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="877" y="420" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">submitInput</text>
    
            {}
            <rect x="1150" y="150" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1150" y="150" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1162" y="163" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1162" y="163" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1174" y="176" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1174" y="176" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1186" y="189" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1186" y="189" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-stronger)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="1242" y="215" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">IInputVerifier</text>
    
            {}
            <rect x="1150" y="292" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1150" y="292" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1162" y="305" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1162" y="305" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1174" y="318" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1174" y="318" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <rect x="1186" y="331" width="112" height="42" rx="4" fill="var(--shodai-diagram-bg)" stroke="var(--shodai-diagram-bg)" strokeWidth="4" />
            <rect x="1186" y="331" width="112" height="42" rx="4" fill="var(--shodai-diagram-tint-stronger)" stroke="var(--shodai-diagram-accent)" strokeWidth="1.8" />
            <text x="1242" y="357" fill="var(--shodai-diagram-ink)" fontSize="13" fontWeight="600" textAnchor="middle">IAction</text>
    
            {}
            <text x="35" y="500" fill="var(--shodai-diagram-ink)" fontSize="11" fontWeight="700">Legend</text>
            <rect x="100" y="492" width="16" height="10" rx="2" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1" />
            <text x="123" y="500" fill="var(--shodai-diagram-muted)" fontSize="10">agreement data</text>
            <rect x="235" y="492" width="16" height="10" rx="2" fill="var(--shodai-diagram-surface-alt)" stroke="var(--shodai-diagram-connector)" strokeWidth="1" />
            <text x="258" y="500" fill="var(--shodai-diagram-muted)" fontSize="10">SDK/client</text>
            <rect x="345" y="492" width="16" height="10" rx="2" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1" />
            <text x="368" y="500" fill="var(--shodai-diagram-muted)" fontSize="10">onchain contracts</text>
            <rect x="495" y="492" width="16" height="10" rx="2" fill="var(--shodai-diagram-tint)" stroke="var(--shodai-diagram-accent)" strokeWidth="1" />
            <text x="518" y="500" fill="var(--shodai-diagram-muted)" fontSize="10">verifier modules</text>
            <rect x="640" y="492" width="16" height="10" rx="2" fill="var(--shodai-diagram-tint-strong)" stroke="var(--shodai-diagram-accent)" strokeWidth="1" />
            <text x="663" y="500" fill="var(--shodai-diagram-muted)" fontSize="10">engine state/functions</text>
          </svg>
  </div>;

For the complete documentation index, see [llms.txt](https://docs.shodai.network/llms.txt).

The onchain execution engine is the first concrete runtime for Agreements Protocol. It is implemented in [CNSLabs/agreements-protocol-evm](https://github.com/CNSLabs/agreements-protocol-evm), including Solidity contracts and the lower-level `@cns-labs/agreements-protocol-evm` SDK.

The engine interprets agreement definitions produced from the [agreement data standard](/system-architecture/data-standard) and gives them a verifiable onchain execution surface.

The current onchain implementation is EVM-based, and each API environment can expose more than one agreement deployment chain. The `testnet` API environment uses the testnet chains: Linea Sepolia, Ethereum Sepolia, and Base Sepolia. The `production` API environment uses the production chains: Linea Mainnet and Base Mainnet.

## Execution model

Each deployed agreement definition becomes an isolated onchain execution instance. The `AgreementFactory` deploys `AgreementEngine` instances, and each instance stores the agreement-specific inputs, verifiers, transitions, initialization values, and optional actions.

Agreements are deployed through an `AgreementFactory`. Each deployed agreement has an associated engine that tracks its state, validates submitted inputs, and applies the authored transition rules.

The agreement's deployed behavior is derived from the agreement definition and associated deployment data. Once deployed, the core agreement definition is fixed, which makes the agreement reliable as a shared operational source of truth.

For signing details, typed data, and current factory addresses, see the [EIP-712 Signing Reference](/reference/eip-712-signing).

<OnchainProtocolDiagram />

## What the engine enforces

The engine enforces the agreement lifecycle:

1. A participant submits an input.
2. The engine validates and verifies the submitted payload.
3. The engine checks whether the input is allowed from the current state.
4. The engine updates state when the transition is valid.
5. Optional actions run as part of the configured transition.
6. The result is emitted through onchain state and events.

This gives each agreement deterministic execution: the same agreement definition and same valid inputs lead to the same state transition and result.

## Agreement instances and execution history

A deployed agreement instance produces a sequence of events, state transitions, submitted inputs, and final outcomes. That history becomes the shared source of truth for the agreement.

Participants do not need to reconcile independent application databases to understand what happened. They can read the agreement instance, inspect input history, and verify the state that follows from accepted inputs.

## Direct engine usage

Use the direct onchain path when your integration already works with wallets, RPC clients, and contract-level execution.

The onchain repository contains:

| Area          | Purpose                                                                                                                                                     |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `contracts/`  | Solidity contracts, tests, deployment scripts, and deployment artifacts.                                                                                    |
| `sdk/`        | TypeScript SDK package for `AgreementFactory`, `AgreementEngine`, ABIs, deployments, and payload helpers. Published as `@cns-labs/agreements-protocol-evm`. |
| `agreements/` | Sample agreement artifacts used for execution-engine tests and examples.                                                                                    |

For current factory and implementation addresses, see [Contracts](/system-architecture/contracts).

For most application integrations, start with the [API client](/sdks/typescript-client) instead. It uses the onchain SDK where needed but gives you higher-level validation, signing, deployment, state, and input-history methods. See [Agreements API](/system-architecture/putting-it-together).
