AppleSauce
    Preparing search index...
    • A generic action that safely selects tokens, performs an async operation, and handles change. This action requires a couch for safety - tokens are stored in the couch before the operation and can be recovered if something goes wrong.

      Parameters

      • minAmount: number

        The minimum amount of tokens to select (in sats)

      • operation: (
            params: { cashuWallet: Wallet; mint: string; selectedProofs: Proof[] },
        ) => Promise<{ change?: Proof[] }>

        An async function that receives selected proofs and performs the operation. Should return any change proofs. All selected proofs are considered used.

      • options: { couch: Couch; mint?: string; tokenSelection?: TokenSelectionFunction }

        Configuration options including mint filter, required couch, and optional custom token selection

      Returns Action

      // Use with NutzapProfile
      await run(TokensOperation, 100, async ({ selectedProofs, mint, cashuWallet }) => {
      const { keep, send } = await cashuWallet.ops.send(100, selectedProofs).asP2PK({ pubkey }).run();
      await run(NutzapProfile, recipient, { mint, proofs: send, unit: "sat" });
      return { change: keep };
      }, { couch });
      // Use with melt
      await run(TokensOperation, meltAmount + feeReserve, async ({ selectedProofs, mint, cashuWallet }) => {
      const meltQuote = await cashuWallet.createMeltQuoteBolt11(invoice);
      const { keep, send } = await cashuWallet.send(meltAmount + meltQuote.fee_reserve, selectedProofs, { includeFees: true });
      const meltResponse = await cashuWallet.meltProofs(meltQuote, send);
      return { change: meltResponse.change };
      }, { couch });
      // Use with custom token selection
      await run(TokensOperation, 100, async ({ selectedProofs, mint, cashuWallet }) => {
      // ... operation
      }, { couch, tokenSelection: myCustomSelectionFunction });