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:
@@ -778,17 +778,11 @@ const server = http.createServer(async (req, res) => {
|
||||
const b = await readBody(req);
|
||||
const addr = String(b.address || '').trim().toLowerCase();
|
||||
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;
|
||||
if (now - last < 120000) return json(res, 429, { error: 'Just topped up. Give it a minute, then try again.' });
|
||||
try {
|
||||
const balHex = await chain.rpc('eth_getBalance', [addr, 'latest']);
|
||||
const bal = BigInt(balHex || '0x0');
|
||||
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.' }); }
|
||||
// Amoy is a public testnet: testers fund their own connected wallet from
|
||||
// the public Amoy faucet (no server-minted balance). We just echo the
|
||||
// address + faucet link; the client copies the address and opens it.
|
||||
let balHex = '0x0'; try { balHex = await chain.rpc('eth_getBalance', [addr, 'latest']); } catch (e) {}
|
||||
return json(res, 200, { ok: true, faucetUrl: 'https://faucet.polygon.technology/', address: addr, balanceWei: BigInt(balHex || '0x0').toString() });
|
||||
}
|
||||
// -- report an ad (auto-approved ads need a safety valve): store + notify admin
|
||||
if (p === '/api/report-ad' && req.method === 'POST') {
|
||||
|
||||
Reference in New Issue
Block a user