首页 > 解决方案 > Coinbase api - 确认交易的通知

问题描述

海洛斯。

我有一个代码可以让人们使用 coinbase API 进行存款。API 为人员/人员提供地址,并在接收交易时发送 webhook。

有没有办法让它在确认时启用通知?或者代码可以检查确认。

我的代码:


        // Create a new document
        const newTransaction = new CryptoTransaction({
          type: "deposit", // Transaction type

          currency, // Crypto currency name
          siteValue: exchangedAmount, // Value in site balance (USD)
          cryptoValue: cryptoAmount, // Value in crypto currency
          address: notification.data.address, // Crypto address

          txid: notification.additional_data.hash, // Blockchain transaction id
          state: 3, // 1 = pending, 2 = declined, 3 = completed

          _user: user.id, // User who made this transaction
        });

        // Save the document
        await newTransaction.save();

        // Update user document
        await User.updateOne(
          { _id: user.id },
          {
            $inc: {
              wallet: exchangedAmount,
              totalDeposited: exchangedAmount,
              wagerNeededForWithdraw:
                user.wagerNeededForWithdraw < 0
                  ? Math.abs(user.wagerNeededForWithdraw) +
                    exchangedAmount * 0.5
                  : exchangedAmount * 0.5, // Add 50% to required wager amount
            },
          }
        );
        insertNewWalletTransaction(user.id, exchangedAmount, "Crypto deposit", {
          transactionId: newTransaction.id,
        });

此代码无需等待 1-blockchain 块即可添加余额

标签: node.jscoinbase-api

解决方案


推荐阅读