ARC-21: Scheduled Execution and Subscriptions.
A protocol-level cron registry for AsentumChain, and an ARC-20-compatible subscriptions standard built on top of it. No keeper bots, no third-party executors, no missed schedules.
| Number | ARC-21 |
| Title | Scheduled Execution and Subscriptions |
| Status | Draft |
| Type | Standards Track |
| Category | ARC (Application) |
| Created | 2026-05-17 |
| Requires | ARC-20 (for token denomination) |
Abstract
ARC-21 defines two things. First, a cron registry system contract pre-deployed at ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgkr943, which lets any account or contract schedule a future call. Every node executes due jobs while applying the first block whose timestamp reaches them, without relying on an external keeper. Second, a subscriptions interfacefor ARC-20 tokens, so any merchant can accept recurring payments without redeploying its own scheduling infrastructure.
Motivation
Recurring on-chain payments, vesting schedules, treasury rebalancing, auto-compounding yield, and time-locked operations are all "scheduled execution" problems. Every other major chain solves this with an off-chain keeper network (Gelato, Chainlink Automation, Keeper Network) that polls the chain and triggers contracts when conditions are met. That introduces a third party you have to trust: a keeper can be sanctioned, sued, or just forget to run.
ARC-21 puts scheduling inside the chain. The block builder is responsible for executing due jobs, deterministically, as part of consensus. There is no separate operator network to bribe or break. A payroll cron set up today will fire on schedule for as long as the chain runs and as long as its gas escrow holds.
The subscriptions interface gives merchants a uniform way to accept recurring payments without writing the scheduling logic themselves. Any wallet, exchange, or dapp can present a "manage subscriptions" view that speaks one shape.
Specification
Cron registry: pre-deployed system contract
The cron registry is a system contract deployed at the reserved addressase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgkr943 at chain genesis. Its source is part of the chain release artifact and is not deployed via a user transaction.
schedule(target, method, args, nextRunAt, intervalSec, maxRuns, gasLimit) -> stringRegister a scheduled call to target.method(...args). nextRunAt is an absolute block time in milliseconds and must be in the future. intervalSec, despite its name, is in milliseconds: 0 for a one-shot, or 60,000 to 31,536,000,000 (60 seconds to 365 days) for recurring. maxRuns is 0 for "until escrow runs out or cancelled", or N for exactly N runs. gasLimit per run is 21,000 to 5,000,000. msg.value funds the gas escrow and must be at least gasLimit wei. target must be a contract address in hex and cannot be the registry itself. The caller becomes the job owner. Returns the job id as a string.
cancel(id) -> boolCancel a job. Only callable by the job's owner. The remaining escrow is refunded to the owner with transfer. Emits JobCancelled. Called from inside the job's own run, the cancel is deferred: the run is billed first, then the job is removed and refunded (JobCancelRequested, then JobCancelled).
topUp(id)Add msg.value to a job's escrow. Anyone can top up any job (good for sponsored execution). Emits JobToppedUp.
getJob(id) -> objectRead view. Returns the full job record or null. Every numeric field is a decimal string. Used by UIs to display upcoming runs.
currentJob() -> objectReturns { id, owner, target, method } of the job whose run is in progress, or null outside a run. A target that wants to accept only its own job checks that msg.sender is the registry, then compares currentJob().id with the id it stored.
listDue(nowMs, max), startRun(id), recordRun(id, gasUsed, success)Chain-only. Any other caller gets "restricted". The block apply path uses them to find due jobs, mark one as running, and bill it afterwards.
Block builder behaviour
While applying each block with timestamp T (in milliseconds), every node MUST:
- Call
listDue(T, 100): walk the registry storage keysdue:<ts>:<id>for everyts ≤ T, in ascending order, up to 100 jobs. - For each due job, call
startRun(id), then runtarget.method(...args)as a full call tree, withmsg.senderset to the registry and a gas limit of the job'sgasLimit(or what is left of the block's cron budget, if less).E()andtransfer()work inside the run. - Call
recordRun(id, gasUsed, success). The registry billsgasUsedfrom the escrow at 1 wei per gas (contracts are not given a base fee, so the registry uses its fallback of 1). A failed run is billed too. EmitsJobExecuted. - If the job was a one-shot, has used its runs, was cancelled during its run, or has less escrow left than
gasLimit, remove it, emitJobExhausted(orJobCancelled) and refund the rest to the owner. Otherwise setnextRunAt = previousNextRunAt + intervalSec, skipping any slots that are already in the past (the phase is kept), decrementrunsLeftand re-insert the due key. - Stop once the jobs have used
CRON_BLOCK_GAS_BUDGET(15M gas). Jobs that don't fit stay due and run in a later block.
This sequence is part of consensus. All validators MUST produce identical cron execution results given identical state, or block apply will fail with a state root mismatch.
Subscriptions interface (built on cron)
Any contract that wants to accept recurring ARC-20 payments SHOULD implement this interface. It's not a system contract; merchants deploy their own instances.
approveSubscription(token, merchant, amount, intervalMs, maxCharges) -> idCustomer authorises a recurring charge. Token must be an ARC-20. The customer must first call token.approve(subscriptionContract, total) for at least amount * maxCharges, because the subscription contract is the spender. ASE attached to the call is forwarded to the cron registry as the job's gas escrow. Schedules the charges via the cron registry. Returns the subscription id.
chargeSubscription(id)Called by the cron registry (and only for this subscription's own job) on the configured schedule. Transfers one charge from customer to merchant. On failure (insufficient allowance, insufficient balance), emits SubscriptionFailed but does not cancel the subscription.
cancelSubscription(id)Customer cancels. The subscription is removed and its cron job is cancelled with cancel(jobId). The remaining escrow is refunded to the job owner, which is the subscription contract.
Events
JobScheduledfrom cron{ id, owner, target, method, nextRunAt, intervalSec }
JobExecutedfrom cron{ id, success, gasUsed, escrowLeft }
JobCancelRequestedfrom cron{ id, owner }
JobCancelledfrom cron{ id, owner, refunded }
JobToppedUpfrom cron{ id, amount, totalEscrow }
JobExhaustedfrom cron{ id, reason }
SubscriptionApprovedfrom subscription contract{ id, customer, merchant }
SubscriptionChargedfrom subscription contract{ id, amount, chargesLeft }
SubscriptionFailedfrom subscription contract{ id, reason }
SubscriptionCancelledfrom subscription contract{ id }
Rationale
Why pre-deploy as a system contract
The cron registry has to exist before any user contract can reference it, and its address has to be stable so dapps can hardcode it. Putting it atase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgkr943 at genesis solves both. It also means the registry can't be redeployed by an attacker who front-runs a regular deploy.
Why a gas escrow per job
Block-builder-driven execution still costs gas. Someone has to pay it. A per-job prepaid escrow keeps the accounting local: the job runs as long as its escrow can fund a run, then emits JobExhausted and stops. This avoids both spam (a job with no escrow does nothing) and unbounded liability (the chain never runs a job for free).
Why a per-block cron gas budget
Without a cap, a popular schedule (for example a million subscriptions all due at midnight UTC) would crowd out regular transactions in that block. Capping cron at 15M gas (50 percent of the 30M block gas limit at v1) leaves room for normal use, and jobs that don't fit just roll to the next block.
Why a minimum interval of 60 seconds (60,000 ms)
Shorter intervals don't add real economic value but they multiply scheduling overhead. 60 seconds is below any reasonable subscription cadence and far above what would be useful as a high-frequency execution mechanism (which is a different problem with different solutions).
Why the subscriptions interface is separate from cron
Cron is general purpose: schedule any contract call. Subscriptions are specifically about ARC-20 transfer authorisations on a schedule. Keeping them separate means wallets can present a clean "manage subscriptions" view without needing to introspect every cron job to see which are subscription charges.
Reference implementations
Cron registry system contract
// Cron registry (v2): protocol system contract at the reserved address
// ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgkr943. Pre-deployed at genesis,
// replaced by v2 in the Shannon upgrade (block 528,000).
// Abridged: the full source is CRON_REGISTRY_V2_SOURCE in
// packages/node/src/chain/cron-registry.ts.
//
// All times are block time in MILLISECONDS, like chain.blockTimestamp.
// The interval field keeps its v1 name, intervalSec, but holds ms.
//
// Storage layout (every value is a string):
// nextJobId -> counter, decimal string
// job:<id> -> JSON { id, owner, target, method, args, nextRunAt,
// intervalSec, maxRuns, runsLeft, gasLimit, gasEscrow }
// due:<14-digit ms>:<id> -> "1" (the chain walks this prefix in order)
// owner:<addr>:<id> -> "1" (index for "list my jobs")
// running -> id of the job whose run is in progress
const CHAIN_CALLER = '0x' + '0'.repeat(40); // the chain's own caller
const MIN_INTERVAL = 60000n; // 60 s, in ms
const MAX_INTERVAL = 31_536_000_000n; // 365 days, in ms
function tsKey(ts) { return String(ts).padStart(14, '0'); }
function chainOnly() {
assert(String(msg.sender).toLowerCase() === CHAIN_CALLER, 'restricted');
}
({
schedule(target, method, args, nextRunAt, intervalSec, maxRuns, gasLimit) {
assert(typeof target === 'string' && /^0x[0-9a-fA-F]{40}$/.test(target), 'invalid target address');
assert(target.toLowerCase() !== String(msg.contractAddress).toLowerCase(),
'a job cannot target the cron registry');
assert(typeof method === 'string' && method.length > 0, 'method required');
const next = BigInt(nextRunAt);
assert(next > BigInt(chain.blockTimestamp), 'nextRunAt must be in the future');
const interval = BigInt(intervalSec);
assert(interval === 0n || (interval >= MIN_INTERVAL && interval <= MAX_INTERVAL),
'interval must be 0 or between 60000 and 31536000000 ms');
const gas = BigInt(gasLimit);
assert(gas >= 21_000n && gas <= 5_000_000n, 'gasLimit out of range');
const maxR = BigInt(maxRuns);
assert(maxR >= 0n, 'maxRuns must be non-negative');
// msg.value is the gas escrow. chain.baseFee is not provided to contracts,
// so the fee per gas is 1 wei: the escrow must be at least gasLimit wei.
const escrow = BigInt(msg.value);
const baseFee = BigInt(chain.baseFee || 1n);
assert(escrow >= gas * baseFee, 'escrow must cover at least one run at the current base fee');
const id = String(BigInt(storage.get('nextJobId') || '0') + 1n);
storage.set('nextJobId', id);
const job = {
id,
owner: String(msg.sender).toLowerCase(),
target: target.toLowerCase(),
method,
args: args || [],
nextRunAt: next.toString(),
intervalSec: interval.toString(),
maxRuns: maxR.toString(),
runsLeft: maxR.toString(),
gasLimit: gas.toString(),
gasEscrow: escrow.toString(),
};
storage.set('job:' + id, JSON.stringify(job));
storage.set('due:' + tsKey(job.nextRunAt) + ':' + id, '1');
storage.set('owner:' + job.owner + ':' + id, '1');
emit('JobScheduled', { id, owner: job.owner, target: job.target, method,
nextRunAt: job.nextRunAt, intervalSec: job.intervalSec });
return id;
},
topUp(id) {
const raw = storage.get('job:' + id);
assert(raw, 'no such job');
const job = JSON.parse(raw);
job.gasEscrow = (BigInt(job.gasEscrow) + BigInt(msg.value)).toString();
storage.set('job:' + id, JSON.stringify(job));
emit('JobToppedUp', { id, amount: String(msg.value), totalEscrow: job.gasEscrow });
return true;
},
cancel(id) {
const raw = storage.get('job:' + id);
assert(raw, 'no such job');
const job = JSON.parse(raw);
assert(job.owner === String(msg.sender).toLowerCase(), 'not the owner');
if (storage.get('running') === String(id)) {
// Called from inside this job's own run: recordRun bills the run first,
// then removes the job and refunds the rest.
job.cancelRequested = true;
storage.set('job:' + id, JSON.stringify(job));
emit('JobCancelRequested', { id, owner: job.owner });
return true;
}
storage.delete('job:' + id);
storage.delete('due:' + tsKey(job.nextRunAt) + ':' + id);
storage.delete('owner:' + job.owner + ':' + id);
const refund = BigInt(job.gasEscrow);
if (refund > 0n) transfer(msg.sender, refund);
emit('JobCancelled', { id, owner: job.owner, refunded: refund.toString() });
return true;
},
getJob(id) {
const raw = storage.get('job:' + id);
return raw ? JSON.parse(raw) : null;
},
// The job being run right now, or null.
currentJob() {
const id = storage.get('running');
if (id === undefined) return null;
const raw = storage.get('job:' + id);
if (!raw) return null;
const job = JSON.parse(raw);
return { id: job.id, owner: job.owner, target: job.target, method: job.method };
},
// Chain-only methods, called by the block apply path:
// listDue(nowMs, max) up to max due ids, oldest first
// startRun(id) marks the job as running, returns it
// recordRun(id, gasUsed, ok) bills gasUsed from the escrow, then removes
// or reschedules the job (see the spec above)
listDue(currentTimestamp, max) { chainOnly(); /* ... */ },
startRun(id) { chainOnly(); /* ... */ },
recordRun(id, gasUsed, success) { chainOnly(); /* ... */ },
})Subscription merchant contract
// ARC-21 subscriptions reference implementation.
// A merchant deploys this once. Customers approve subscriptions.
// The chain's cron registry charges them on schedule.
//
// Deploy, then call init(cron) with the registry's address,
// ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgkr943. The SDK converts ase1
// arguments to the lowercase hex form that contracts see.
const lc = (a) => String(a).toLowerCase();
({
init(cron) {
assert(!storage.get('cron'), 'already initialised');
storage.set('cron', lc(cron));
return true;
},
// Customer approves a recurring charge.
// token ARC-20 contract address (e.g. aUSD)
// merchant who gets paid
// amount per-charge amount (decimal string)
// intervalMs charge frequency in ms, e.g. 2592000000 = 30 days
// maxCharges 0 = unlimited, otherwise stops after N
// Attach ASE with the call: it becomes the cron job's gas escrow
// (at least 100000 wei, the per-charge gas limit below).
// Before this, the customer calls token.approve(<this contract>, total).
approveSubscription(token, merchant, amount, intervalMs, maxCharges) {
const cron = storage.get('cron');
assert(cron, 'not initialised');
const id = (BigInt(storage.get('nextSubId') || '0') + 1n).toString();
storage.set('nextSubId', id);
// Schedule the charges via the protocol cron registry, forwarding the
// escrow. This contract becomes the job's owner.
const firstChargeAt = BigInt(chain.blockTimestamp) + BigInt(intervalMs);
const jobId = E(cron, { value: msg.value }).schedule(
msg.contractAddress,
'chargeSubscription',
[id],
firstChargeAt.toString(),
String(intervalMs),
String(maxCharges),
'100000', // gasLimit per charge
);
const sub = {
customer: lc(msg.sender),
merchant: lc(merchant),
token: lc(token),
amount: String(amount),
maxCharges: String(maxCharges),
charges: '0',
lastChargeAt: '0',
jobId: String(jobId),
};
storage.set('sub:' + id, JSON.stringify(sub));
emit('SubscriptionApproved', { id, customer: sub.customer, merchant: sub.merchant });
return id;
},
// Called by the cron registry, and only for this subscription's own job.
chargeSubscription(id) {
const cron = storage.get('cron');
assert(lc(msg.sender) === cron, 'caller must be cron registry');
const raw = storage.get('sub:' + id);
if (!raw) return false; // cancelled
const sub = JSON.parse(raw);
const job = E(cron).currentJob();
assert(job && job.id === sub.jobId, 'not this subscription\'s job');
const max = BigInt(sub.maxCharges);
if (max !== 0n && BigInt(sub.charges) >= max) return false;
// transferFrom the customer to the merchant via the ARC-20 token.
// This contract is the spender, so the customer's allowance is to it.
try {
E(sub.token).transferFrom(sub.customer, sub.merchant, sub.amount);
} catch (err) {
emit('SubscriptionFailed', { id, reason: String(err && err.message ? err.message : err) });
return false;
}
const charges = BigInt(sub.charges) + 1n;
sub.charges = charges.toString();
sub.lastChargeAt = chain.blockTimestamp.toString();
storage.set('sub:' + id, JSON.stringify(sub));
const chargesLeft = max === 0n ? 'unlimited' : (max - charges).toString();
emit('SubscriptionCharged', { id, amount: sub.amount, chargesLeft });
return true;
},
// Customer cancels. The cron job is cancelled too; its remaining escrow is
// refunded to this contract (the job owner).
cancelSubscription(id) {
const raw = storage.get('sub:' + id);
assert(raw, 'no such subscription');
const sub = JSON.parse(raw);
assert(sub.customer === lc(msg.sender), 'not the customer');
storage.delete('sub:' + id);
E(storage.get('cron')).cancel(sub.jobId);
emit('SubscriptionCancelled', { id });
return true;
},
})Test cases
A compliant cron registry MUST pass at minimum the following behavioural tests:
schedule(...)withnextRunAtin the past MUST throw.schedule(...)with insufficientmsg.valuefor at least one run MUST throw.- A one-shot job (intervalSec = 0) fires exactly once at the scheduled time, then is removed from
due:. - A recurring job with
maxRuns = 3fires three times then emitsJobExhausted. - A recurring job with
maxRuns = 0fires everyintervalSecuntil its escrow runs out, then emitsJobExhausted. cancel(id)by the owner refunds the remaining escrow and removes the job.cancel(id)by anyone other than the owner MUST throw.- When the cron block-gas budget is exhausted, remaining jobs roll to the next block in the same due order.
Security considerations
Reentrancy via scheduled execution
A job calls target.method(args) while the block is applied. A new job must have nextRunAt later than the current block time, so a job scheduled during a run never fires in the same block. The cron step works from the list listDue returned at its start. A job cannot target the registry itself, and the chain's reentrancy guard applies to every call inside a run.
Front-running cancellation
A user who calls cancel(id) the same block their job is due will race the block builder. If the block builder's cron pass runs first, the cancel goes through but the job has already executed once. Implementations SHOULD document this. Users who want a hard stop SHOULD cancel at least one full block before the next scheduled run.
Allowance erosion for subscriptions
The subscriptions interface uses ARC-20 transferFrom, which means a subscription effectively spends down the customer's pre-approved allowance. If the allowance runs out, chargeSubscription emits SubscriptionFailed and the subscription continues to schedule (it doesn't auto-cancel) so the customer can top up the allowance and resume.
Block-gas griefing
A spammer who creates many low-gas jobs all due at the same second cannot DoS the chain: the per-block cron gas budget caps total execution at 15M gas. Excess jobs simply roll forward. The spammer also pays for every run via the escrow mechanism, so the attack is self-limiting.
ARC-21 is in Draft. Registry v2, described here, has been live since the Shannon upgrade at block 528,000.