last
Returns the last revision of an on-chain object after its tip has been spent (for example after delete).
Type
last(rev: string): Promise<string | undefined>
Parameters
rev
A revision encoded as a string of the form <transaction-id>:<output-number>.
Return Value
A Promise that resolves to:
- The latest revision of the object when that tip is spent.
undefinedwhen the latest revision is still unspent.
Description
Unlike latest, which returns the current tip whether spent or unspent, last only returns a value when the tip is spent. That makes it suitable for terminal checks (escrow settlement, final withdraws) rather than reading the live tip.
Typical flow:
- Update or finalize the object.
- Spend the tip (for example with
delete). - Wait for confirmation.
- Call
last(rev)to obtain the terminal revision.
Inside smart contracts (InnerComputer)
Behavior is stricter than the outer client API:
- The starting revision, the returned tip, and the tip’s spending transaction must all be confirmed.
- An unspent tip (or a mempool-only spend) invalidates the evaluation — there is no stable
undefinedsuccess path inside contracts. - Do not treat
lastas “current live tip”; use confirmed history (first/prev/getAncestors) for that style of walk.
See Contract – Querying.
Example
const counter = await computer.new(Counter, [])
await counter.inc()
// Tip is still unspent → undefined
const open = await computer.last(counter._rev)
// Spend the tip, then last returns the terminal revision
const tip = await computer.latest(counter._id)
await computer.delete([tip])
// For InnerComputer callers: wait until the spend is confirmed
const terminal = await computer.last(counter._id)
// terminal === tip