Who pays for what
Whoever calls a handler pays for that call. The actor pays for everything it starts itself: scheduled runs, runner jobs, off-chain functions, stored state and its own payments. People who hire your actor pay what the listing charges (Billing), but that money doesn’t flow into the actor’s balance by itself. It’s up to you to keep the actor funded for the work it does.Get money into the actor
An actor’s first money comes at deploy, which asks how much to move from your wallet to the new actor, 1 CBY by default, or takes--fund. After that, anyone can add to its balance:
Output
cowboy actor inspect <actor> shows the balance, and cowboy actor auto-topup refills the actor from your wallet automatically (Deploy and operate).
A payment into the actor runs none of its code, and actor code can’t read its own balance. To act on a payment, have the payer call a handler as well, and keep your own record in self.storage.
Pay someone from the actor
runtime.transfer_balance(to, amount) moves CBY from the actor’s balance to any address. The amount is in base units: 1 CBY is 1,000,000,000.
This actor pays out only when you, its owner, tell it to. Create a project:
Output
actors/payouts/main.py with:
@callable_by(OWNER) means only you can make the actor pay, and a handler that moves money must say who may call it. It also needs @deferred: a handler that pays or sends a message must be marked that way, or it raises PurityViolationError.
A payment is all or nothing. If the actor’s balance is short, the transfer raises and the handler changes nothing. If the handler raises after the transfer, the transfer is undone too.
Test it
Replacetests/test_payouts.py with:
Output
mock_host.get_transfer_log() lists each one. Test payments with cowboy test, not cowboy run.
A spending budget
To stop an actor overspending, it can cap its own spending per period;runtime.budget_left() reports what’s left (reference).