Amoy rehearsal: faucet points testers to the public Amoy faucet

anvil_setBalance doesn't exist on Amoy. The faucet now connects the wallet,
copies the address, and opens faucet.polygon.technology so testers fund their
own wallet with test POL (choose Polygon Amoy). Server endpoint returns the
faucet link + address instead of minting balance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-08 08:33:46 -05:00
parent 9cff0dc667
commit 653a5e333a
3 changed files with 17 additions and 21 deletions
+7 -5
View File
@@ -1416,12 +1416,14 @@
await render(); await render();
})); }));
if ($('faucetBtn')) $('faucetBtn').addEventListener('click', busy($('faucetBtn'), async () => { if ($('faucetBtn')) $('faucetBtn').addEventListener('click', busy($('faucetBtn'), async () => {
IAP.status('Connect your wallet to receive test POL…'); IAP.status('Connect your wallet first…');
const addr = await IAPWallet.connect(); const addr = await IAPWallet.connect();
const r = await api('/api/my/faucet', { address: addr }); let copied = false;
const pol = (Number(BigInt(r.balanceWei) / (10n ** 15n)) / 1000).toFixed(3); try { await navigator.clipboard.writeText(addr); copied = true; } catch (e) {}
$('faucetInfo').textContent = 'Funded — balance ' + pol + ' test-POL. Head to Buy packages.'; window.open('https://faucet.polygon.technology/', '_blank', 'noopener');
IAP.status('Your wallet now holds test POL. Go buy a package.', 'ok'); $('faucetInfo').innerHTML = 'Your address <span class="mono">' + addr.slice(0, 8) + '…' + addr.slice(-6) + '</span>'
+ (copied ? ' is copied' : '') + '. On the faucet, choose <b>Polygon Amoy</b>, paste your address, and request POL. Then come back and buy.';
IAP.status('Faucet opened in a new tab. Choose Polygon Amoy, paste your address, and request test POL.', 'ok');
})); }));
$('activateBtn').addEventListener('click', busy($('activateBtn'), async () => { $('activateBtn').addEventListener('click', busy($('activateBtn'), async () => {
const me = await (await fetch('/api/me')).json(); const me = await (await fetch('/api/me')).json();
+5 -5
View File
@@ -639,10 +639,10 @@
<div class="pane" id="pane-wallet" hidden> <div class="pane" id="pane-wallet" hidden>
<div class="card" id="faucetCard" hidden> <div class="card" id="faucetCard" hidden>
<h3>Get test POL</h3> <h3>Get test POL</h3>
<p class="muted small">This is the rehearsal chain, so purchases use valueless <b>test POL</b>, not real money. <p class="muted small">This is the Polygon <b>Amoy testnet</b>, so purchases use valueless <b>test POL</b>, not real money.
Tap below to top your connected wallet up to 10 test-POL, then buy a package and watch the payouts Grab free test POL for your connected wallet from the Amoy faucet, then buy a package and watch the payouts
move on the live ledger exactly like the real chain will.</p> move on the live ledger exactly like mainnet will.</p>
<p><button class="btn" id="faucetBtn" type="button">Get test POL</button> <p><button class="btn" id="faucetBtn" type="button">Get free test POL</button>
<span class="small muted" id="faucetInfo"></span></p> <span class="small muted" id="faucetInfo"></span></p>
</div> </div>
<div class="grid c2"> <div class="grid c2">
@@ -691,7 +691,7 @@
</div> </div>
<script src="/assets/common.js?v=20260908c"></script> <script src="/assets/common.js?v=20260908c"></script>
<script src="/assets/wallet.js?v=20260908b"></script> <script src="/assets/wallet.js?v=20260908b"></script>
<script src="/assets/my.js?v=20260908h"></script> <script src="/assets/my.js?v=20260908i"></script>
<script src="/assets/chat.js?v=20260907l"></script> <script src="/assets/chat.js?v=20260907l"></script>
</body> </body>
</html> </html>
+5 -11
View File
@@ -778,17 +778,11 @@ const server = http.createServer(async (req, res) => {
const b = await readBody(req); const b = await readBody(req);
const addr = String(b.address || '').trim().toLowerCase(); const addr = String(b.address || '').trim().toLowerCase();
if (!/^0x[0-9a-f]{40}$/.test(addr)) return json(res, 400, { error: 'Connect your wallet first.' }); if (!/^0x[0-9a-f]{40}$/.test(addr)) return json(res, 400, { error: 'Connect your wallet first.' });
const now = Date.now(), last = faucetHits.get(addr) || 0; // Amoy is a public testnet: testers fund their own connected wallet from
if (now - last < 120000) return json(res, 429, { error: 'Just topped up. Give it a minute, then try again.' }); // the public Amoy faucet (no server-minted balance). We just echo the
try { // address + faucet link; the client copies the address and opens it.
const balHex = await chain.rpc('eth_getBalance', [addr, 'latest']); let balHex = '0x0'; try { balHex = await chain.rpc('eth_getBalance', [addr, 'latest']); } catch (e) {}
const bal = BigInt(balHex || '0x0'); return json(res, 200, { ok: true, faucetUrl: 'https://faucet.polygon.technology/', address: addr, balanceWei: BigInt(balHex || '0x0').toString() });
const target = 10n * (10n ** 18n); // 10 test-POL
if (bal < 5n * (10n ** 18n)) await chain.rpc('anvil_setBalance', [addr, '0x' + target.toString(16)]);
faucetHits.set(addr, now);
const nb = await chain.rpc('eth_getBalance', [addr, 'latest']);
return json(res, 200, { ok: true, balanceWei: BigInt(nb || '0x0').toString() });
} catch (e) { return json(res, 502, { error: 'Faucet is unavailable right now.' }); }
} }
// -- report an ad (auto-approved ads need a safety valve): store + notify admin // -- report an ad (auto-approved ads need a safety valve): store + notify admin
if (p === '/api/report-ad' && req.method === 'POST') { if (p === '/api/report-ad' && req.method === 'POST') {