Developer Docs
10 / 10
Gas
Who pays network fees today, and how to add gas sponsorship later.
Today: users pay their own gas
Every on-chain action is sent from the acting user's wallet, which pays the network fee:
| Action | Who sends it |
|---|---|
| Deploy a competition escrow (factory.createEscrow) | Organizer |
| Fund a prize pool (approve + escrow.fund) | Any contributor |
| Announce winners (escrow.announceWinners) | Organizer |
| Claim a prize / refund (claimPrize / claimRefund) | Winner / contributor |
On Base these cost a few cents. On Base Sepolia, users get free test ETH from a faucet; the UI shows a notice with a faucet link whenever a wallet has no ETH (GasNotice).
Where gas is handled
Gas handling lives in exactly two files:
src/lib/gas.ts— readsNEXT_PUBLIC_GAS_MODE(currently onlyuser).src/hooks/useChainTx.ts— the single path every write goes through. It switches the wallet to the target chain, checks for gas when the user pays, sends the transaction and waits for a successful receipt.
Components never call writeContractAsync on their own; they pass it to run() from useChainTx.
Adding sponsorship later
- Add a
"sponsored"mode toGasModeinsrc/lib/gas.ts. - In
useChainTx, branch on the mode: for"sponsored", send through a paymaster — for example Privy's native gas sponsorship for embedded wallets, or an ERC-4337 smart wallet with a Base paymaster. - Set
NEXT_PUBLIC_GAS_MODE=sponsored.GasNoticehides itself automatically becauseUSER_PAYS_GASbecomes false.
Keep the user's wallet as msg.sender. The escrow records msg.sender of createEscrow as the competition's on-chain organizer, and only that address can announce winners. A server relayer that sends transactions from a platform key would make Counterparti the organizer of every escrow. Sponsorship must pay the gas, not change the sender.
You could also sponsor only some actions (say, claims, so winners never need ETH) by passing an option to run() and checking it alongside the mode.