mint_token.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const {
  2. loadWasmAsync,
  3. Wallet,
  4. CurrencyUnit
  5. } = require("../");
  6. async function main() {
  7. await loadWasmAsync();
  8. let seed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  9. let mint_url = "https://testnut.cashu.space";
  10. let currency = CurrencyUnit.Sat;
  11. wallet = await new Wallet(seed, []);
  12. await wallet.addMint(mint_url);
  13. await wallet.refreshMint(mint_url);
  14. let amount = 10;
  15. let quote = await wallet?.mintQuote($mint_url, BigInt(amount), currency);
  16. let quote_id = quote?.id;
  17. let invoice = quote?.request;
  18. if (invoice != undefined) {
  19. data = invoice;
  20. }
  21. let paid = false;
  22. while (paid == false) {
  23. let check_mint = await wallet?.mintQuoteStatus(mint_url, quote_id);
  24. if (check_mint?.paid == true) {
  25. paid = true;
  26. } else {
  27. await new Promise((r) => setTimeout(r, 2000));
  28. }
  29. await wallet?.mint(
  30. mint_url,
  31. quote_id,
  32. undefined,
  33. undefined,
  34. undefined,
  35. );
  36. let token = await wallet?.send(
  37. mint_url,
  38. currency,
  39. undefined,
  40. BigInt(amount) undefined,
  41. undefined,
  42. );
  43. console.log(token);
  44. }
  45. }
  46. main();