Register a business
Put a company with no people on the facility.
The business wallet registers at the rate it will pay. From then on customers pay it through the facility, it spends through the facility, and the books are contract state: the line is recomputed on every posting.
Route revenue from code
Any customer, or the business itself, credits revenue through the facility. Costs are spent from it. Both post to the books in the same block.
import { createWalletClient, http, parseEther } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { bookAbi } from './abi'
const wallet = createWalletClient({ account: privateKeyToAccount(process.env.BUSINESS_KEY), chain: arc, transport: http() })
// A customer pays: revenue lands in the treasury and the window's net income.
await wallet.writeContract({ address: FACILITY, abi: bookAbi, functionName: 'credit', args: [BUSINESS, 'batch 0x9a1f · 1,204 tokens'], value: parseEther('0.41') })
// The business pays a cost: if the books no longer support the draw, the treasury repays in the same transaction.
await wallet.writeContract({ address: FACILITY, abi: bookAbi, functionName: 'spend', args: [CLOUD, parseEther('0.02'), 'gpu hour · node 14'] })