Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
Background
An AI agent or an external service can complete a task and receive payment after its work has been reviewed. ERC-8183 defines an escrow model in which the client deposits a budget, the provider submits a deliverable, and the evaluator decides whether to release the payment.
Overview
A job with a deliverable
Suppose a client commissions a data analysis and wants to check the result before paying. The party who decides whether to pay or refund after submission is the evaluator. ERC-8183 records the requester as the client, the party submitting the result as the provider, and the decision maker as the evaluator. The evaluator can be an account or a contract that applies its own decision logic.

The client deposits the budget and the provider submits a reference to the deliverable. If the evaluator calls complete, the escrow pays the provider. If the evaluator calls reject, it refunds the client. An expiry refund follows a separate recovery path through claimRefund. Recording the three roles in one job makes it possible to track who created it, submitted the result, and decided the outcome under one identifier. The standard connects role permissions and the resulting fund transfers to job states. The evaluation logic can be implemented elsewhere.
Holding the budget until a decision
The contract holds the job's budget in ERC-20 tokens until the decision. The client cannot unilaterally reclaim the funds after submission, so the provider can rely on the stated payment conditions. Before calling fund, the client sets the token allowance. The contract then collects the budget using transferFrom.
For more on ERC-20, see the following article.
[ERC-20] Understanding the ERC-20 token standard
Routing funds according to the outcome
Completion pays the provider. Rejection or expiry refunds the client. Applications can track the state, caller, and ERC-20 recipient for one budget using its jobId.
Motivation
Unilateral refunds give providers no assurance
If the client can reclaim the funds after a submission, the provider cannot know whether completed work will be paid. If submitting alone settles the job, the client cannot obtain a refund for incomplete work. The evaluator therefore controls completion and rejection after submission.
Submission alone cannot settle the job
The client can act as the evaluator for a small task. A job that calls for third-party verification can name a contract with evaluation logic. The evaluator has authority to record the result on-chain. The standard leaves correctness, dispute resolution, and deliverable authenticity to the application.
Refunds when evaluation stalls
Once the job expires, the client can call claimRefund to recover the budget. This path does not invoke a hook, so recovery remains possible if an extension is unavailable. Expiry enables fund recovery when there is no evaluation result.
Specification
Job lifecycle
A job is Open, Funded, Submitted, or terminal. The terminal states are Completed, Rejected, and Expired. An Open job has been created but has no funds in escrow. In this phase the parties can set the budget and the client can set an unassigned provider or reject the job without a transfer. When it becomes Funded, the ERC-20 tokens have moved into escrow and the client cannot withdraw them unilaterally. The provider can then submit the work. In Submitted, the evaluator has yet to decide. Completed pays the provider, Rejected refunds the client if funded, and Expired records a refund after the deadline.

| Transition | Caller or condition | Effect on funds |
|---|---|---|
Open → Funded |
The client deposits the budget. | Moves ERC-20 tokens into escrow. |
Open → Rejected |
The client rejects the job. | No transfer occurs because it was not funded. |
Funded → Submitted |
The provider submits a deliverable reference. | Keeps the funds in escrow. |
Funded → Rejected |
The evaluator rejects the job. | Refunds the client. |
Funded → Expired |
claimRefund is called after expiry. |
Refunds the client. |
Submitted → Completed |
The evaluator completes the job. | Pays the provider. |
Submitted → Rejected |
The evaluator rejects the job. | Refunds the client. |
Submitted → Expired |
claimRefund is called after expiry. |
Refunds the client. |
A refund after expiry must be available from Funded or Submitted. The standard recommends allowing anyone to call claimRefund, but implementations may restrict it to the client. This gives the client a way to recover funds even if the evaluator goes offline. Before expiry, the client cannot use this path, and permissions for complete and reject remain tied to the job state.
Operations by role
The client creates the job, sets the budget, and deposits ERC-20 tokens. The provider submits the deliverable and receives payment if the job completes. The evaluator decides completion or rejection after submission. If the job is created without a provider, the client must call setProvider before funding it. The client and provider can record the agreed amount with setBudget, but the tokens only move when the client calls fund. The provider cannot decide completion or rejection in that role, and the evaluator cannot submit in that role. The contract checks the caller against the three addresses stored on the job.
Job
struct Job {
uint256 id;
address client;
address provider;
address evaluator;
string description;
uint256 budget;
uint256 expiredAt;
JobStatus status;
address hook;
}The struct stores the parties, description, budget, deadline, state, and optional extension associated with a job.
- Fields
| Field | Description |
|---|---|
id |
Sequential job identifier. |
client |
Creates and funds the job and receives refunds. |
provider |
Submits the deliverable and receives payment on completion. |
evaluator |
Decides whether to complete or reject the job. |
description |
Text describing the job. |
budget |
Amount to deposit in ERC-20 tokens. |
expiredAt |
Expiry timestamp. |
status |
Current job state. |
hook |
Optional contract that receives pre- and post-action callbacks. |
Creating and funding a job
createJob
function createJob(address provider, address evaluator, uint256 expiredAt, string calldata description, address hook) external returns (uint256);The client creates an Open job and receives its jobId.
- Validate the evaluator, expiry, and hook.
- Store the parties, description, and expiry.
- Emit
JobCreatedand return thejobId.
- Arguments
| Argument | Description |
|---|---|
provider |
Submits the work. Use the zero address to assign the provider later. |
evaluator |
Decides completion or rejection. |
expiredAt |
Deadline after which the funds can be refunded. |
description |
Description of the requested work. |
hook |
Optional contract for pre- and post-action callbacks. |
- Return value
| Value | Description |
|---|---|
jobId |
Identifier of the newly created job. |
Requirements
| Item | Requirement |
|---|---|
| Evaluator address | A decision maker must be assigned so the payment can be resolved. |
| Expiry | The implementation may require a minimum time window so the deposit cannot become refundable before the provider has time to work. |
setProvider
function setProvider(uint256 jobId, address provider, bytes calldata optParams) external;The client assigns a provider to a job that does not have one.
- Check that the job is
Openand the caller is the client. - Store the provider address.
- Emit
ProviderSet.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to update. |
provider |
Address that submits the deliverable. |
optParams |
Additional data to pass to the hook. |
Requirements
| Item | Requirement |
|---|---|
| Job state | The job must be Open, before the budget is deposited. |
| Caller | Only the client can assign the provider. |
| Provider assignment | The provider must not already be set. This prevents changing the assigned submitter midway through the job. |
setBudget
function setBudget(uint256 jobId, uint256 amount, bytes calldata optParams) external;The client or provider sets the budget on an Open job.
- Check that the caller is the client or provider.
- Store the amount on the job.
- Emit
BudgetSet.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to update. |
amount |
Agreed budget. |
optParams |
Additional data to pass to the hook. |
Requirements
| Item | Requirement |
|---|---|
| Job state | The job must be Open. Funding fixes the amount. |
| Caller | The client or provider can record the agreed amount. |
fund
function fund(uint256 jobId, uint256 expectedBudget, bytes calldata optParams) external;The client checks the stored budget against expectedBudget, deposits the ERC-20 tokens, and moves the job to Funded.
- Compare the stored budget with
expectedBudget. - Transfer the ERC-20 tokens from the client to the contract.
- Move to
Fundedand emitJobFunded.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to fund. |
expectedBudget |
Budget the client has confirmed. |
optParams |
Additional data to pass to the hook. |
Requirements
| Item | Requirement |
|---|---|
| Caller | Only the client can start funding. |
| Provider assignment | A provider must be assigned before the funds are transferred. |
| Budget check | The stored budget must match expectedBudget so that an outdated amount cannot be funded accidentally. |
| Token payment | The ERC-20 balance and allowance must cover the transfer. Otherwise the transfer and transition to Funded fail. |
Submitting and evaluating a deliverable
submit
function submit(uint256 jobId, bytes32 deliverable, bytes calldata optParams) external;The provider submits a deliverable reference and moves the job to Submitted.
- Check that the caller is the provider.
- Include the deliverable reference in the event.
- Move to
Submittedand emitJobSubmitted.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job being submitted. |
deliverable |
A 32-byte reference to the deliverable, such as a content ID or evidence hash. |
optParams |
Additional data to pass to the hook. |
Requirements
| Item | Requirement |
|---|---|
| Caller | Only the assigned provider can submit the result. |
| Job state | The job must be Funded, with its budget deposited and no prior submission. |
complete
function complete(uint256 jobId, bytes32 reason, bytes calldata optParams) external;The evaluator completes a Submitted job and pays the provider from escrow.
- Check that the caller is the evaluator.
- Calculate the payout after any applicable fees.
- Move to
Completedand pay the provider.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to complete. |
reason |
A 32-byte reference to the evaluation reason or evidence. |
optParams |
Additional data to pass to the hook. |
Requirements
| Item | Requirement |
|---|---|
| Caller | Only the evaluator can complete the job, separating submission from the authority to release payment. |
| Job state | The job must be Submitted. Completion requires a recorded deliverable reference. |
reject
function reject(uint256 jobId, bytes32 reason, bytes calldata optParams) external;Rejects the job and refunds the client if it was funded.
- Check whether the caller is the client or evaluator, as required by the current state.
- Move to
Rejected. - If the job was funded, refund the client and emit the relevant event.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to reject. |
reason |
A 32-byte reference to the rejection reason or evidence. |
optParams |
Additional data to pass to the hook. |
Requirements
| Job state | Authorized caller |
|---|---|
Open |
Only the client can cancel an unfunded job. |
Funded or Submitted |
Only the evaluator can reject a funded job. This prevents the client from deciding the refund unilaterally. |
Expiry refunds
claimRefund
function claimRefund(uint256 jobId) external;Moves an expired Funded or Submitted job to Expired and refunds the client.
- Check that the current time is at or past
expiredAt. - Update the state to
Expired. - Return the ERC-20 tokens to the client and emit
Refunded.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job to refund. |
Requirements
| Item | Requirement |
|---|---|
| Job state | The job must be Funded or Submitted, with funds still in escrow. |
| Timing | The current time must be at or past expiredAt, preventing early recovery through this path. |
| External hook | Do not call the hook, so the client can recover the funds even if it or an external service is unavailable. |
IACPHook
interface IACPHook {
function beforeAction(uint256 jobId, bytes4 selector, bytes calldata data) external;
function afterAction(uint256 jobId, bytes4 selector, bytes calldata data) external;
}The interface lets an extension add validation or notifications before or after core functions.
beforeAction
function beforeAction(uint256 jobId, bytes4 selector, bytes calldata data) external;Runs before changes to state or ERC-20 transfers. If it fails, it stops the operation.
- Check the job ID and selector.
- Read the data and validate any additional conditions.
- Return to the core operation if validation succeeds.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job identifier. |
selector |
Four-byte selector of the core function. |
data |
Data representing the function arguments. |
Requirements
| Item | Requirement |
|---|---|
| Caller | Only the core contract should call the hook, so an arbitrary address cannot directly invoke callbacks that appear to come from a job action. |
| Validation | Revert if the hook's conditions are not met. The operation's state changes and transfers are reverted in the same transaction. |
afterAction
function afterAction(uint256 jobId, bytes4 selector, bytes calldata data) external;Runs after state changes and transfers. If it fails, the whole transaction reverts, including the core operation.
- Check the job ID and selector.
- Read the data and notify a service such as an external registry.
- Commit the core operation and notification if the call succeeds.
- Arguments
| Argument | Description |
|---|---|
jobId |
Job identifier. |
selector |
Four-byte selector of the core function. |
data |
Data representing the function arguments. |
Requirements
| Item | Requirement |
|---|---|
| Caller | Only the core contract should call the hook, which links the notification to the completed job state change and transfer. |
| Failure | The entire transaction reverts, so a failed notification cannot leave the payment committed on its own. |

claimRefund is outside the hook flow.
Tracking outcomes with events
Applications can use jobId to look up state changes and fund movements.

JobCreated
event JobCreated(uint256 indexed jobId, address indexed client, address indexed provider, address evaluator, uint256 expiredAt, address hook);Records the parties, expiry, and hook when a job is created.
| Field | Description |
|---|---|
jobId |
Links the stored job to later events. |
client |
Starts the request and funding. |
provider |
Initial provider, or the zero address if assigned later. |
evaluator |
Decides completion or rejection. |
expiredAt |
Timestamp used to determine refund eligibility. |
hook |
Contract receiving the pre- and post-action callbacks. |
ProviderSet
event ProviderSet(uint256 indexed jobId, address indexed provider);Emitted when an unassigned provider is registered.
| Field | Description |
|---|---|
jobId |
Job whose provider was set. |
provider |
Submitter assigned by the client. |
BudgetSet
event BudgetSet(uint256 indexed jobId, uint256 amount);Emitted when the budget is stored.
| Field | Description |
|---|---|
jobId |
Job whose budget changed. |
amount |
Budget agreed before funding. |
JobFunded
event JobFunded(uint256 indexed jobId, address indexed client, uint256 amount);Emitted when tokens move into escrow and the job becomes Funded.
| Field | Description |
|---|---|
jobId |
Funded job. |
client |
Party that deposited the ERC-20 tokens. |
amount |
Budget deposited into escrow. |
JobSubmitted
event JobSubmitted(uint256 indexed jobId, address indexed provider, bytes32 deliverable);Emitted when the provider submits a deliverable reference.
| Field | Description |
|---|---|
jobId |
Submitted job. |
provider |
Party that submitted the work. |
deliverable |
Content ID or hash referring to the deliverable. |
JobCompleted
event JobCompleted(uint256 indexed jobId, address indexed evaluator, bytes32 reason);Emitted when the evaluator completes the job.
| Field | Description |
|---|---|
jobId |
Completed job. |
evaluator |
Party that made the decision. |
reason |
Reference to the evaluation reason or evidence. |
JobRejected
event JobRejected(uint256 indexed jobId, address indexed rejector, bytes32 reason);Emitted when the client or evaluator rejects the job.
| Field | Description |
|---|---|
jobId |
Rejected job. |
rejector |
The client for Open, or the evaluator for Funded or Submitted. |
reason |
Reference to the rejection reason or evidence. |
JobExpired
event JobExpired(uint256 indexed jobId);Emitted when claimRefund moves the job to Expired.
| Field | Description |
|---|---|
jobId |
Expired job. |
PaymentReleased
event PaymentReleased(uint256 indexed jobId, address indexed provider, uint256 amount);Records how much escrow paid the provider for a completed job.
| Field | Description |
|---|---|
jobId |
Job from which payment was released. |
provider |
Recipient of the net amount. |
amount |
Amount paid after fees. |
Refunded
event Refunded(uint256 indexed jobId, address indexed client, uint256 amount);Records how much was refunded to the client after rejection or expiry.
| Field | Description |
|---|---|
jobId |
Job from which the refund was paid. |
client |
Refund recipient. |
amount |
Amount returned to the client. |
Additional notes
Keeping references to results and decisions
deliverable and reason are 32-byte references to off-chain files, content IDs, or evidence hashes. A separate evaluation or verification layer checks the underlying data.
Separating evaluation and payment
ERC-8004 deals with agent identity and reputation. ERC-8183 deals with job budgets, submissions, escrow, payments, and refunds.
For more on ERC-8004, see the following article.
[ERC-8004] How trustless agents work
Compatibility
Integrating with ERC-20 tokens
fund uses transferFrom to collect tokens from the client. Settlement uses transfer to pay the provider on completion or refund the client on rejection or expiry. For a chosen token, verify the client's balance and allowance, how much the contract receives, and where funds go in each terminal state.
For more on ERC-20, see the following article.
[ERC-20] Understanding the ERC-20 token standard
Supporting relayed calls
An ERC-2771 trusted forwarder submits a signed request. The ACP contract can use _msgSender() to identify the original signer.
For more on ERC-2771, see the following article.
[ERC-2771] Meta-transactions that let another address pay for gas
Supporting signed token approvals
ERC-2612 lets an application create a token allowance from a signature, so it can combine permit and fund in one transaction.
For more on ERC-2612, see the following article.
[ERC-2612] Combining ERC-20 approval and transfer in one transaction
Keeping optional extensions separate
Per-job tokens, platform fees, evaluator fees, hook allowlists, and meta-transactions are implementation choices. The core specifies job states, the three roles' permissions, provider payments on completion, and client refunds on rejection or expiry.
Reference implementation
Reading IACPHook.sol
The reference hook inherits IERC165 and exposes two callbacks.
interface IACPHook is IERC165 {
function beforeAction(uint256 jobId, bytes4 selector, bytes calldata data) external;
function afterAction(uint256 jobId, bytes4 selector, bytes calldata data) external;
}beforeAction runs before the core action, and afterAction runs after state changes and transfers. A hook revert cancels the operation. Hooks can apply allowlists or validate input without directly modifying core escrow. The implementation leaves claimRefund outside the hook flow so funds can be returned after expiry even if the hook becomes unavailable.
Reading AgenticCommerce.sol
AgenticCommerce.sol is an upgradeable core contract. initialize stores the payment token and treasury, assigns administrator roles, and allows the zero address as a hook.
function initialize(address paymentToken_, address treasury_) public initializer;createJob checks expiry, evaluator, hook allowlist, and ERC-165 support before storing the job in jobs[jobId]. setBudget stores the amount. fund uses SafeERC20.safeTransferFrom to transfer tokens from the client to the contract and sets Funded.
complete computes fees and distributes funds to the treasury, evaluator, and provider. reject refunds the client if the job was funded. Functions that transfer funds are protected by nonReentrant.
Reference implementation constraints
| Code element | What the implementation does | Relation to the standard |
|---|---|---|
AccessControlUpgradeable |
Uses ADMIN_ROLE to update fees, the treasury, and the hook allowlist. |
Reference implementation choice. |
UUPSUpgradeable |
Lets only DEFAULT_ADMIN_ROLE upgrade the implementation. |
Reference implementation choice. |
ReentrancyGuardTransient |
Prevents reentrant calls to operations that transfer tokens. | Implementation protection. |
SafeERC20 |
Detects failed ERC-20 transfers. | Implementation protection. |
ERC165Checker |
Checks whether a hook implements IACPHook. |
Reference implementation choice. |
platformFeeBP / evaluatorFeeBP |
Deducts fees only on completion. | Optional extension. |
Custom errors such as ExpiryTooShort, ProviderNotSet, FeesTooHigh, and HookNotWhitelisted represent additional failure conditions in the reference implementation.
How it differs from the core requirements
The standard requires the job lifecycle, permissions for the three roles, ERC-20 escrow, provider payment on completion, and client refunds on rejection or expiry. The reference implementation additionally imposes a minimum expiry window of five minutes, a hook allowlist, and an ERC165Checker check. It also computes platform and evaluator fees. Upgradeability, role management, fees, and hook allowlists are choices made by that implementation.
Security considerations
Trusting the evaluator
After submission, the evaluator decides whether to pay or reject. ERC-8183 does not guarantee a fair decision or arbitrate disputes. High-value jobs can add reputation, stake, or external evidence through separate mechanisms. A malicious or mistaken evaluator can finalize payment or refund on-chain, and the core operations cannot reverse that outcome. Because deliverable and reason are references, the contract alone cannot verify the underlying data exists or justify the decision. Applications must decide who selects the evaluator, how to handle stake, and where to resolve appeals.

When a hook blocks an operation
A failing hook rolls back the operation, including its state changes and transfers. A call by the hook to an external registry or token can also trigger a revert. beforeAction runs before the state changes, and afterAction runs after them. Either can revert the entire transaction, so the job cannot advance while its corresponding transfer fails. External dependencies can still block normal operations. Review hook permissions, registry availability, gas limits, and retry behavior, and verify that the client can recover using claimRefund after expiry without invoking the hook.
Protecting ERC-20 transfers against reentrancy
fund, complete, reject, and claimRefund can transfer tokens. The reference implementation combines ReentrancyGuardTransient and SafeERC20 so state changes and transfer failures are handled together. A reentrancy guard alone cannot address unusual token return values or incorrect payout calculations. For example, mistakes in how complete distributes funds to the treasury, evaluator, and provider or calculates the provider's net amount can lead to duplicate payouts or insufficient funds. Review the scope of nonReentrant, when the job enters a terminal state, transfer failures handled by SafeERC20, nonstandard return values, and the token's upgrade authority. A malicious token can exceed the protections available to the escrow contract alone.
Keeping expiry refunds available
claimRefund only runs when the job is Funded or Submitted and its deadline has passed. It returns the full budget to the client without invoking a hook. Verify the time check, accepted states, refund recipient, and inability to call the recovery path early. Short deadlines can leave the provider too little time to submit, while long deadlines can lock the client's funds. The surrounding application must define dispute resolution, off-chain verification, and suitable deadlines.
Conclusion
ERC-8183 standardizes the sequence in which the client deposits a budget, the provider submits a deliverable, and the evaluator decides whether to pay or refund. Implementers need to account for evaluator trust, recovery after expiry, hook failures, and the differences between the core and the reference implementation.
I also publish elsewhere.




