Skip to main content

Integrating Bitcoin Fee Estimation into a Wallet: Step-by-Step

· 2 min read
OverBlock Team
OverBlock Engineering

Fee estimation in a Bitcoin wallet is a user experience problem as much as a technical one. Users see a transaction stuck for hours and blame the wallet, regardless of what caused the delay.

What users need vs what developers show

Most wallets show sat/vB fee tiers. This is useful for power users. Regular users need: "this will cost approximately X sats (≈ $Y)."

Use ?txType=p2wpkh (or p2tr, p2pkh, etc.) to get estimatedFeeSat - the actual fee in satoshis for the specific transaction format your wallet uses. Display that, not the rate.

SSE-based fee updates

Polling fees on a fixed interval has a fundamental problem: during congestion, fees change faster than your polling interval. A user who sees an estimate from 2 minutes ago submits a transaction with a stale rate.

The correct approach: subscribe to SSE when the fee display is visible, unsubscribe when hidden.

// React hook example
function useBitcoinFees() {
const [fees, setFees] = useState(null);

useEffect(() => {
const es = new EventSource(
'https://api.overblock.io/bitcoin-fees/fees/stream',
{ headers: { 'X-API-Key': process.env.FEES_API_KEY } }
);

es.addEventListener('fees', (e) => setFees(JSON.parse(e.data)));
return () => es.close();
}, []);

return fees;
}

The RBF "Speed up" pattern

Every wallet that allows fee customization should have a "Speed up" button for pending transactions.

When tapped: call the RBF endpoint with the current transaction's fee rate and vsize. Get back the recommended new rate and additional sat amount. Show it to the user, let them confirm.

curl -X POST .../fee-advisor/rbf-bump \
-d '{"currentFeeRateSatVb": 15, "currentFeeSat": 2115, "vsize": 141}'

Edge cases to handle

Congestion: when the fast tier is above a threshold (say, 100 sat/vB), show a warning: "Bitcoin fees are currently high."

Weekend dips: when slow tier drops below 2 sat/vB, economy transactions are unusually cheap - optionally surface this to users.

Pre-signed transactions: for hardware wallets, fees are locked at signing. Display the current rate alongside the signed rate so users understand the context.

bitcoin-fees-advisor provides SSE feed, per-txType estimates, and the RBF calculator.

→ Related: Bitcoin Fee Estimation Guide