easyway
Sign inCreate free account

Sell digital files for crypto with one-time download codes

You have a file to sell: an e-book, a Lightroom preset pack, a font, a sample library. You want buyers to pay in crypto and get the file without you sending it by hand. A easyway product link handles the payment and hands every buyer a unique code. This post shows three ways to turn that into a download, and two small Node.js scripts for the one that stops a shared link from giving the file away.

What a product link already does

A product link sells one item at a fixed USD price. The buyer enters their e-mail, picks one of 101 coins, and pays on the hosted checkout. Once the invoice is paid, the checkout shows two things you set in advance:

The delivery text, up to 5,000 characters. Web addresses in it become clickable links.

One code from your stock, if you added codes. You paste them in batches of up to 1,000, each up to 500 characters. Every buyer gets a different one, oldest first. The checkout shows the code as text with a copy button.

The buyer also gets one e-mail with the code, the text and a link back to the payment page, which works as a receipt they can reopen. easyway does not host your file. The delivery is the text and the code, so the file itself has to live somewhere you control.

Three ways to deliver the file

MethodWhat you set upIf a buyer shares it
A link in the delivery textUpload the file anywhere and paste the linkAnyone with the link can download, forever
A unique code + your download pageA code stock and a small server (below)The code stops working after a few downloads
Your own store + the APICreate invoices from your backend, deliver on the invoice.paid webhookWhatever your store allows

The first method is fine for cheap files or for things you don't mind being passed around. The third makes sense if you already run a shop; see the crypto payment API and the webhook signature guide. The rest of this post is the second method: no backend for payments, only a tiny file server.

Step 1: make the codes

Each code is a random 16-character token. The script writes codes.txt, which you paste into the product link, and adds the same tokens to tokens.json with a download count of zero. Run it again later to add more codes without losing the counts.

// node make-codes.mjs 50  →  codes.txt (paste into the product link) + tokens.json (for download.mjs)
import { randomBytes } from "node:crypto";
import { existsSync, readFileSync, writeFileSync } from "node:fs";

const n = Number(process.argv[2] ?? 50);
const tokens = existsSync("tokens.json") ? JSON.parse(readFileSync("tokens.json", "utf8")) : {};
const fresh = Array.from({ length: n }, () => randomBytes(12).toString("base64url")); // 16 characters
for (const t of fresh) tokens[t] = 0; // downloads so far
writeFileSync("tokens.json", JSON.stringify(tokens));
writeFileSync("codes.txt", fresh.join("\n") + "\n");
console.log(`${n} new codes in codes.txt, ${Object.keys(tokens).length} in tokens.json`);

Step 2: the download server

The server checks the code against tokens.json, counts each download, and refuses a code after three. It uses only Node.js built-ins, so there is nothing to install. Put it behind HTTPS on a host you control, for example behind the reverse proxy you already use.

// node download.mjs  →  https://files.example.com/?code=<code> sends the file, at most 3 times per code
import { createServer } from "node:http";
import { createReadStream, readFileSync, writeFileSync } from "node:fs";

const FILE = "ebook.pdf";
const MAX = 3;
const tokens = JSON.parse(readFileSync("tokens.json", "utf8"));

createServer((req, res) => {
  const code = new URL(req.url, "http://x").searchParams.get("code")?.trim() ?? "";
  if (!Object.hasOwn(tokens, code)) {
    res.writeHead(code ? 404 : 400, { "Content-Type": "text/plain" });
    return res.end(code ? "Unknown code.\n" : "Add ?code=<your code> to the address.\n");
  }
  if (tokens[code] >= MAX) {
    res.writeHead(410, { "Content-Type": "text/plain" });
    return res.end(`This code was used ${MAX} times. Contact the seller.\n`);
  }
  tokens[code] += 1;
  writeFileSync("tokens.json", JSON.stringify(tokens));
  res.writeHead(200, {
    "Content-Type": "application/pdf",
    "Content-Disposition": `attachment; filename="${FILE}"`,
    "Cache-Control": "no-store",
  });
  createReadStream(FILE).pipe(res);
}).listen(8080, () => console.log("download server on :8080"));

We ran both scripts with Node.js 22 before publishing: the first three downloads with a code answered 200, the fourth 410, and an unknown code 404. Object.hasOwn matters: a plain code in tokens check would treat a code like constructor as known, because every object inherits it.

In Dashboard → Payment links, create a Product link with a title and a price, paste codes.txt into the codes box, and write delivery text that tells the buyer what to do with the code:

Thanks for buying the e-book!
Download it here: https://files.example.com/?code=
Paste the code shown above after "code=". Each code works 3 times.

Share the link in your channel, bio or newsletter. The sell digital products page lists every field of a product link.

How the code stock behaves

SituationWhat happens to the code
A buyer opens the checkoutThe oldest unused code is held for that invoice
The invoice is paidThe code is shown on the payment page and e-mailed
The invoice expires or is cancelledThe code goes back to the stock
The buyer sends less than the priceThe code stays held until they pay the rest
The last code is held by an open checkoutThe next visitor sees the link as sold out
You added codes after earlier salesEarlier buyers keep their old delivery; new codes go to new buyers

Because a code is held from the moment the checkout opens, two buyers can never pay for the same last code. Keep the stock topped up: run make-codes.mjs again and paste the new codes.txt. The dashboard shows how many codes are left and which buyer got which one, which helps when someone writes in that their download stopped working.

Fees and getting paid

Each sale costs a flat 0.5% platform fee. Nothing is charged per link or per code. The buyer pays in the coin they chose and you receive that coin. easyway holds your balance until you withdraw it to a wallet you have whitelisted; the pricing page lists each coin's withdrawal fee and minimum. If you price a file in dollars and want to keep dollars, point buyers to a stablecoin such as USDT on TRON.

Common questions

Can the code itself be the download link? Yes, a code can be up to 500 characters, so a full URL fits. But the checkout shows codes as copyable text, not as a link, so a short token plus a link in the delivery text is easier for the buyer.

What if the e-mail never arrives? The delivery e-mail is sent once. The payment page stays open to the buyer as a receipt (for example from their browser history), and it always shows the code and the text.

Can I test this without real money? Yes. Create the link in test mode, buy from it, then press Simulate payment on the invoice in the dashboard to see the code appear. See testing crypto payments.

Create free accountRead the API docsAlready have an account? Sign in
Sell digital files for crypto with download codes | easyway