Faucet
Last updated
import { ethers } from "@armchain-ethersv6/ethers";
const provider = new ethers.JsonRpcProvider("http://localhost:18545");
// The validator account private key (from fakenet genesis)
// Replace with the actual key from your fakenet setup
const faucet = new ethers.Wallet(VALIDATOR_PRIVATE_KEY, provider);
// Send ARM to a test address
async function fund(address) {
const tx = await faucet.sendTransaction({
to: address,
value: ethers.parseEther("100"),
type: 3,
});
await tx.wait();
console.log(`Funded ${address} with 100 ARM`);
}import { ethers } from "@armchain-ethersv6/ethers";
import express from "express";
const app = express();
app.use(express.json());
const provider = new ethers.JsonRpcProvider("http://localhost:18545");
const faucet = new ethers.Wallet(process.env.FAUCET_KEY, provider);
const cooldowns = new Map();
const AMOUNT = ethers.parseEther("10");
const COOLDOWN_MS = 60 * 60 * 1000; // 1 hour
app.post("/fund", async (req, res) => {
const { address } = req.body;
if (!ethers.isAddress(address)) {
return res.status(400).json({ error: "Invalid address" });
}
const lastRequest = cooldowns.get(address);
if (lastRequest && Date.now() - lastRequest < COOLDOWN_MS) {
return res.status(429).json({ error: "Rate limited" });
}
try {
const tx = await faucet.sendTransaction({
to: address,
value: AMOUNT,
type: 3,
});
await tx.wait();
cooldowns.set(address, Date.now());
res.json({ txHash: tx.hash });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(3000, () => console.log("Faucet running on :3000"));