Smart Contracts

Complete API reference for ERC-1066-x402 smart contracts: IntentExecutor, BaseIntentValidator, PolicyRegistry, and StatusCodes library.

Overview

ERC-1066-x402 consists of four main smart contract components that work together to validate and execute intents.

IntentExecutor

Executes validated intents through a pluggable validator

BaseIntentValidator

Abstract base implementing common validation checks

PolicyRegistry

Stores versioned policies referenced by intents

StatusCodes

Library of standardized status code constants

IntentExecutor

Executes intents through a pluggable validator and forwards calls on success.

Functions

execute

external payable nonReentrant

Execute an intent if the validator returns a success status

Parameters:
  • intent - The intent to execute (IntentTypes.Intent calldata)
Returns:
  • returnData - Return data from the target call (bytes memory)
Reverts:
  • ExecutionDenied - If validation fails
  • ExecutionFailed - If target call fails

setValidator

external

Set a new validator (should be protected by governance/ownership in production)

Parameters:
  • _validator - New validator address (IIntentValidator)
IntentExecutor.sol
contract IntentExecutor is ReentrancyGuard {
    IIntentValidator public validator;

    function execute(IntentTypes.Intent calldata intent)
        external payable nonReentrant
        returns (bytes memory returnData)
    {
        bytes32 intentHash = keccak256(abi.encode(intent));
        bytes1 status = validator.canExecute(intent);

        if (!StatusCodes.isSuccess(status)) {
            revert ExecutionDenied(status);
        }

        (bool ok, bytes memory ret) = intent.target.call{value: intent.value}(intent.data);
        if (!ok) {
            revert ExecutionFailed(StatusCodes.STATUS_EXECUTION_FAILED, ret);
        }

        emit IntentExecuted(intentHash, status, msg.sender, ret);
        return ret;
    }
}

BaseIntentValidator

Abstract base contract implementing common checks for intent validation: time windows, policy checks, and funds verification.

Functions

canExecute

public view virtual

Validates an intent by checking time windows, policy, and funds

Parameters:
  • intent - The intent to validate (IntentTypes.Intent calldata)
Returns:
  • status - Status code (bytes1)
Validation Checks:
  • • Time window (validAfter, validBefore)
  • • Policy checks (targets, selectors, chains, value caps)
  • • Funds verification

PolicyRegistry

Stores versioned policies referenced by intents. Policies are immutable per policyId.

Functions

setPolicy

external onlyOwner

Set a new policy; policies are immutable per policyId

Parameters:
  • policyId - Unique identifier (bytes32)
  • policy - Policy data (IntentTypes.Policy calldata)
Reverts:
  • PolicyAlreadyExists - If policyId already exists

getPolicy

external view

Get a policy by id

Parameters:
  • policyId - Policy identifier (bytes32)
Returns:
  • policy - Policy data (IntentTypes.Policy memory)

StatusCodes Library

Library of standardized status code constants and helper functions.

Common Status Codes

STATUS_SUCCESS0x01
STATUS_DISALLOWED0x10
STATUS_ALLOWED0x11
STATUS_TOO_EARLY0x20
STATUS_TOO_LATE0x21
STATUS_INSUFFICIENT_FUNDS0x54