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 nonReentrantExecute an intent if the validator returns a success status
intent- The intent to execute (IntentTypes.Intent calldata)
returnData- Return data from the target call (bytes memory)
ExecutionDenied- If validation failsExecutionFailed- If target call fails
setValidator
externalSet a new validator (should be protected by governance/ownership in production)
_validator- New validator address (IIntentValidator)
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 virtualValidates an intent by checking time windows, policy, and funds
intent- The intent to validate (IntentTypes.Intent calldata)
status- Status code (bytes1)
- • 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 onlyOwnerSet a new policy; policies are immutable per policyId
policyId- Unique identifier (bytes32)policy- Policy data (IntentTypes.Policy calldata)
PolicyAlreadyExists- If policyId already exists
getPolicy
external viewGet a policy by id
policyId- Policy identifier (bytes32)
policy- Policy data (IntentTypes.Policy memory)
StatusCodes Library
Library of standardized status code constants and helper functions.
Common Status Codes
STATUS_SUCCESS0x01STATUS_DISALLOWED0x10STATUS_ALLOWED0x11STATUS_TOO_EARLY0x20STATUS_TOO_LATE0x21STATUS_INSUFFICIENT_FUNDS0x54