diff options
| author | Adam Soltys <[email protected]> | 2024-09-25 09:44:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-25 09:44:29 -0700 |
| commit | 61d246e1bca5566c93486312818e02b8a8aa70b3 (patch) | |
| tree | 3382a5db19e0dff6280232e77f3fd9f7cb1b0587 /mint.ts | |
| parent | 9ef8f0eea743929207009d0f42b9ba44eec00641 (diff) | |
| download | coinos-server-61d246e1bca5566c93486312818e02b8a8aa70b3.tar.gz coinos-server-61d246e1bca5566c93486312818e02b8a8aa70b3.zip | |
push to account invoices
Diffstat (limited to 'mint.ts')
| -rw-r--r-- | mint.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/mint.ts b/mint.ts new file mode 100644 index 00000000..8cf3e744 --- /dev/null +++ b/mint.ts @@ -0,0 +1,35 @@ +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.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); |
