ClearPact Lifecycle Examples — Copy-Paste Snippets Linked to BaseScan
Eight runnable ERC-8183 cycles, each pinned to an on-chain receipt you can verify yourself.
All snippets target the v2 ERC-8183 proxy at 0x7CDB80e9B154c99354d66604103fAEb148c6f5A8. The canonical complete() settle tx for sample job 47 is 0x42daf938… on Base Sepolia — open it on BaseScan for the live USDC transfer event.
Lifecycle Snippet Gallery
Each step below is a self-contained card with a JS call (matching the client.jobs.* SDK signatures) plus a curl mirror. Every on-chain step is followed by a BaseScan link. Snippets compile against clearpact@0.3.0 — copy the whole <pre> block and paste into your editor.
Create job (POST /api/job)
Spin up the off-chain job record. client.jobs.create() targets the v2 proxy — the resulting job_id drives every subsequent call.
javascript
const { ClearPact } = require('clearpact');
const client = new ClearPact({ apiKey: 'cpk_live_YOUR_KEY' });
const { job } = await client.jobs.create(
'0x70997970C51812dc3A010C7d01b50e0d17dc79C8', // provider
'0x1DDefFED6a9e28C37e1E10c292F6774D837a7Ab6', // evaluator
'2026-08-08T00:00:00Z', // expiredAt
'AI data analysis task' // description
);
console.log('Created job', job.id);
curl
curl -X POST https://clearpact.polsia.app/api/job \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"provider": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"evaluator": "0x1DDefFED6a9e28C37e1E10c292F6774D837a7Ab6",
"expiredAt": "2026-08-08T00:00:00Z",
"description": "AI data analysis task"
}'
Set budget (POST /api/job/:id/budget)
Lock in the USDC budget and token before funding. Off-chain step — no tx hash recorded.
javascript
const { job } = await client.jobs.setBudget(
'JOB_ID',
10, // amount (USDC)
{ token: '0x036CbD53842c5426634e7929541eC2318f3dCF7e' }
);
console.log('Budget set', job.budget, job.token);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/budget \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"amount": "10.00",
"token": "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
}'
setBudget keeps status at Open — funding is the on-chain step that advances the job to Funded.
Fund job (POST /api/job/:id/fund)
Your wallet calls ClearPactJob.fund(jobId, "0x") on Base Sepolia (approve USDC first), then record the resulting tx hash.
javascript
const { job } = await client.jobs.fund('JOB_ID', {
tx_hash: '0xFUND_TX_HASH'
});
console.log('Funded', job.status, job.tx_hashes.fund);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/fund \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"tx_hash": "0xFUND_TX_HASH"
}'
Submit deliverable (POST /api/job/:id/submit)
The provider submits the work artifact — IPFS hash, deliverable URL, or any opaque reference the evaluator needs.
javascript
const { job } = await client.jobs.submit(
'JOB_ID',
'https://ipfs.io/ipfs/QmResult...', { tx_hash: '0xSUBMIT_TX_HASH' }
);
console.log('Submitted', job.status, job.deliverable);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/submit \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"deliverable": "https://ipfs.io/ipfs/QmResult...",
"tx_hash": "0xSUBMIT_TX_HASH"
}'
Complete / release payment (POST /api/job/:id/complete)
Call ClearPactJob.complete(jobId) on-chain — this is the verified settle tx that releases USDC to the provider.
javascript
const { job } = await client.jobs.complete(
'JOB_ID',
'Deliverable accepted', { tx_hash: '0x42daf938...' }
);
console.log('Completed', job.status, job.tx_hashes.complete);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/complete \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"reason": "Deliverable accepted",
"tx_hash": "0x42daf938..."
}'
complete() can be called by the evaluator OR the client (ERC-8183 D6). The contract enforces this at the ACL level — no admin override possible.
Settle with platform fee (POST /api/escrow/:id/settle)
Configure the SDK with platformFeeBps and platformFeeRecipient. The on-chain payout still goes entirely to the payee — settlement.fee is the receipt annotation the platform sweeps in a follow-on settlement.
javascript
const { ClearPact } = require('clearpact');
const client = new ClearPact({
apiKey: 'cpk_live_YOUR_KEY',
platformFeeBps: 250, // 2.50% platform fee
platformFeeRecipient: '0xPLATFORM_FEE_WALLET'
});
// Settle a verified v1 escrow; SDK annotates the receipt with the fee line.
const { settlement } = await client.escrow.settle('ESCROW_ID', {
verifications: { '0': { completed: true } },
actor: '0xAliceWallet'
});
console.log('Net payout:', settlement.net_amount, settlement.token);
console.log('Platform fee:', settlement.fee.amount, settlement.token,
'→', settlement.fee.recipient);
console.log('Settle tx:', settlement.settle_tx_hash);
curl
curl -X POST https://clearpact.polsia.app/api/escrow/ESCROW_ID/settle \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"verifications": {"0": {"completed": true}},
"actor": "0xAliceWallet"
}'
platformFeeBps must be an integer 0–10000; platformFeeRecipient is required whenever platformFeeBps > 0. See Platform Fees in the API reference.
Step settle() · on-chain release tx with annotated fee line on BaseScan ↗
Reject (dispute) (POST /api/job/:id/reject)
Evaluator OR client rejects the submission with a reason. ERC-8183 E3 3-path ACL: valid in Open, Funded, or Submitted. Symmetric automatic refund from Funded/Submitted states.
javascript
const { job } = await client.jobs.reject(
'JOB_ID',
'Deliverable did not meet spec', { tx_hash: '0xREJECT_TX_HASH' }
);
console.log('Rejected', job.status, job.previous_status);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/reject \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY" \
-d '{
"reason": "Deliverable did not meet spec",
"tx_hash": "0xREJECT_TX_HASH"
}'
Evaluator proxy · DisputeResolved / EvaluatorRejected receipts on BaseScan ↗
Claim refund (freeze variant) (POST /api/job/:id/claim-refund)
After expiredAt has passed, the client pulls funds back from any Funded or Submitted job. Unconditional, non-hookable, non-pausable (PAUSER_ROLE renounced post-Phase 4).
javascript
const { job } = await client.jobs.claimRefund('JOB_ID');
console.log('Refunded', job.status, job.refund_tx_hash);
curl
curl -X POST https://clearpact.polsia.app/api/job/JOB_ID/claim-refund \
-H "Content-Type: application/json" \
-H "X-API-Key: cpk_live_YOUR_KEY"
See the running transactions list on the contract page for any E2E test or production flow. The address tab is the authoritative backing store for every real receipt.