RailPay - Private on-chain payments on Ethereum and Arbitrum, powered by RAILGUN
// wallet.getAddress() === resolve(ensName)
const ensName = "pay.vitalik.eth"
const wallet = new ethers.Wallet(process.env.ETH_PRIVATE_KEY.trim());
const now = Math.floor(Date.now() / 1000);
const invoice = JSON.stringify({
amount: ethers.toBeHex(ethers.parseEther("0.001")),
domain: "pay.su3.io",
description: "my first invoice",
nonce: crypto.randomUUID(),
validFrom: now - 180,
validUntil: now + 180,
});
const sig = await wallet.signMessage(
new TextEncoder().encode(`RAILPAY_INVOICE\n${invoice}`)
);
const output = await (await fetch("https://pay.su3.io/api/invoice", {
method: "POST",
headers: { "x-ens-name": ensName, "x-signature": sig },
body: invoice,
})).json();