SELFHOLD / FOR DEVELOPERS Guide pages ↓
Pay fees with work
Every Lattice transaction pays a fee to the miner who records it. With a fee sponsor, your app lets people pay that fee with their device's work instead of coins. A new account can write at once.
How it works
A fee sponsor is a miner that runs beside a node. It trades work for fees:
- The device mines. Selfhold's window asks the sponsor for work. The person's device (its GPU, or its processor where there's no GPU) grinds shares of the sponsor's next block. A share is about 17 million hashes by default, and a fee takes as many shares as the sponsor asks. The window shows its progress, and stops at about 2 minutes.
- Each share is a real chance at a block. The sponsor's block template pays it on Nexus and on every chain its node hosts. If a share wins, the sponsor earns that block's reward and fees.
- The sponsor credits the person. Each accepted share is worth its chance of winning times the block's reward, on the chain the write goes to.
- The sponsor pays the fee from that credit. It adds a debit of the fee from its own account to the person's transaction, and co-signs it.
- The person's wallet checks and signs. Selfhold's window checks that the sponsor added only its own fee, then signs the same transaction and sends it. It carries a real fee, so any node takes it.
The sponsor can't change the write: the window refuses a transaction that differs from the one the person approved in anything but the sponsor's fee.
Each app runs its own sponsor
A sponsor earns on the chains its node hosts, so it pays fees on those chains: the ones your app writes to. There's no shared public sponsor. To offer coin-free writes, deploy one beside a node that hosts your chain:
- lattice-sponsor ↗: what it is, how to run it, its options (the work per share, the smallest fee it pays, the most it pays per transaction) and its routes.
- lattice.build ↗: running a Lattice node and hosting a chain.
Its key holds the coins it pays fees from, and nothing else: a co-signature lends the key's authority to the transaction.
Use it
const wallet = selfhold({
sponsor: () => "https://sponsor.your-app.example",
hosts: () => ["https://node.your-app.example"],
});
The URL is the sponsor's base: the window calls its routes under it (/work, /shares and /sponsor). If you serve the sponsor under a path, such as https://your-app.example/sponsor, give that path. The window, at https://wallet.selfhold.app, calls it from the person's browser, so the sponsor must allow requests from that origin.
Selfhold's window shows the person the fee, and that their device pays it with work. While it works, the window shows its progress, and progress hears it.
When work can't pay
Selfhold's window falls back to the account's coins when it has them. If it doesn't, the write fails with NeedsCoins, and its sponsor says why work couldn't pay:
"down": the sponsor didn't pay: it isn't answering, is busy, or takes no work now. Trying again in a few minutes may work."dear": too much work. The window won't work for more than about 2 minutes on this device."most": a payment over the sponsor's limit. A sponsor can also pay part of a payment for work, up to its limit.
Selfhold for Chrome doesn't use a sponsor: it pays fees from the account's coins.
Without a sponsor, the account pays each fee from its coins: the window shows how much before the person approves.
Something wrong or missing here? Report it on GitHub ↗