How I Modeled US Lottery Tax Withholding for 21 Countries Without a Backend
Every time a US Powerball or Mega Millions jackpot balloons enough to hit global headlines, the advertised number is misleading in a very specific way: it represents the pre-tax annuity total, paid out over 29 years. For anyone living outside the US, finding a straightforward answer to "okay, but what would actually land in my bank account, based on where I live?" is surprisingly hard to come by.…
Every time a US Powerball or Mega Millions jackpot reaches record-breaking heights, the advertised amount is deceptive. This figure represents the pre-tax annuity, paid out over 29 years. However, for non-US residents, determining the actual amount received is challenging. I created ChamTax to address this issue directly. The main engineering challenge was modeling the cross-border tax logic.
Winning a US lottery involves at least two distinct tax jurisdictions: US non-resident withholding under IRC §871(a), which imposes a flat 30% at the source before the money leaves the country; and home-country taxation, which varies significantly across countries. Most of these interactions involve a foreign tax credit (FTC), where the US withholding is credited against the home country's tax owed, up to the smaller amount.
However, if a country lacks an active tax treaty with the US, the two taxes add up in full. Building ChamTax without a backend required a client-side only approach, with all 21 country tax models and 50 US state rates stored as plain JavaScript objects within the browser. This design decision eliminated infrastructure costs and reduced the attack surface.
For most countries, the tax model follows a simple pattern: calculate US withholding, apply home country tax, apply foreign tax credit, and subtract the remaining tax from the original amount. This resulted in a flat-country function that requires only a currency-invariant percentage and a configuration of { rate, ftcAvailable } for each country.
Korea was the only country requiring real-money math, as it taxes foreign lottery winnings using a progressive bracket system with fixed KRW thresholds. This branch converts the USD payout to KRW, applies the 8-tier progressive tax table, and then converts the result back. One aspect that couldn't be verified was the tax laws of several countries, such as Thailand, Sri Lanka, Cambodia, Mongolia, Laos, and Pakistan.
These countries lack a clear statutory rule for taxing foreign lottery winnings, so the calculator provides an explicit note describing the approximation used. The calculator utilizes 26 languages, with some languages (Uzbek, Khmer, Sinhala, Kyrgyz) having no native speaker for translation checks. To improve translation quality, a second AI pass was employed, specifically designed to flag low-confidence lines.
This approach allowed for actionable feedback on uncertain translations, which is crucial as incorrect tax calculations can have significant financial consequences.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.