Handing over the keys safely

One-step ownership transfer means one typo loses the contract forever. Two steps make the mistake recoverable.

The obvious ownership transfer is one line:

def transfer_ownership(new_owner: bytes) -> None:
    _only_owner()
    storage.set(K_OWNER, bytes(new_owner))

And if new_owner has a typo — an address nobody holds the key to — the contract is now owned by nobody, permanently. Every owner-only function is dead. There is no undo, no support line, no recovery.

The two-step pattern removes that class of mistake entirely:

1. The current owner nominates a successor. Ownership does not change. 2. The successor accepts. Only now does ownership move.

A typo'd address can never accept, because nobody controls it — so the nomination simply expires unused and the current owner stays in place.

This costs one extra transaction and removes an entire category of irreversible failure. It is standard practice in serious contracts for exactly that trade.

Your turn

Implement two-step ownership. init(owner) sets the first owner. nominate(addr) is owner-only and records a pending owner. accept() may only be called by the pending owner and completes the transfer. owner() and pending() read the state.

Hints

Stuck? Ask

Answered by Animica's own free inference network. It is donated GPU capacity, so give it 20-30 seconds.