aboutsummaryrefslogtreecommitdiffstats
path: root/mint.ts
blob: e63ede10bea101109d21cf56da69ba54b31f06b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import config from "$config";
import { createClient } from "redis";
import { CashuMint, CashuWallet, getEncodedTokenV4, MintQuoteState } from "@cashu/cashu-ts";

const mintUrl = "http://mint:3338"; // the mint URL
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint);
let amt = 100000;
const mintQuote = await wallet.createMintQuote(amt);
console.log(mintQuote.request);

let interval = setInterval(async () => {
  const mintQuoteChecked = await wallet.checkMintQuote(mintQuote.quote);
  if (mintQuoteChecked.state == MintQuoteState.PAID) {
    const { proofs } = await (wallet as any).mintTokens(amt, mintQuote.quote);

    const token = getEncodedTokenV4({
      token: [{ mint: mintUrl, proofs }],
    });

    let db = createClient({
      url: config.db,
    });

    await db.connect();
    await db.set("cash", token);

    clearInterval(interval);
  }
}, 1000);