Tap Faucet Endpoint

Learn how to dispense satoshis from your Droplit instance.

Tap Faucet Endpoint

This endpoint allows you to "tap" the Droplit, dispensing a pre-configured amount of satoshis to a specified Bitcoin SV address. This functionality is only available if the Droplit has been configured with a drop_sats value greater than 0.

  • Endpoint: POST /faucets/{droplitName}/tap
    • Replace {droplitName} with the name of your Droplit.
  • Authentication: Required (see Authentication)

Conditional Availability

The "Tap" functionality depends on the Droplit's configuration. If drop_sats is not set or is zero, this endpoint will likely return an error or indicate that tapping is not enabled. The satoshis value in the request body should match the Droplit's configured drop_sats amount.

Request Body

The request body must be a JSON object with the following structure:

{
  "recipient_address": "your_bsv_address",
  "satoshis": 1000 // This should match the Droplit's configured tap amount
}
  • recipient_address: The Bitcoin SV address to which the satoshis will be sent.
  • satoshis: The amount of satoshis to dispense. This must match the drop_sats value configured for the Droplit.

Example: Curl

Replace <YOUR_WIF>, <RECIPIENT_BSV_ADDRESS>, <DROPLIT_NAME>, <TAP_AMOUNT>, <GENERATED_AUTH_TOKEN_VALUE>, and <YOUR_DROPLIT_API_URL> with your actual values. The <TAP_AMOUNT> should be the amount configured in the Droplit's settings.

# 1. Define variables (example)
RECIPIENT_BSV_ADDRESS="1..." 
DROPLIT_NAME="your-droplit-name"
TAP_AMOUNT=1000 # This MUST match the Droplit's configured drop_sats
PAYLOAD_BODY="{ \"recipient_address\": \"${RECIPIENT_BSV_ADDRESS}\", \"satoshis\": ${TAP_AMOUNT} }"
PATHNAME_VALUE="/faucets/${DROPLIT_NAME}/tap"
# Note: For the AUTH_TOKEN_VALUE, you need to generate it using a bitcoin-auth library.
# The message to sign is typically: PATHNAME_VALUE + PAYLOAD_BODY
# For curl, you might pre-generate this token.
AUTH_TOKEN_VALUE="<GENERATED_AUTH_TOKEN_VALUE>"
YOUR_DROPLIT_API_URL="http://localhost:8080" # Or your deployed URL

# 2. Make the request
curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Auth-Token: ${AUTH_TOKEN_VALUE}" \
  -d "${PAYLOAD_BODY}" \
  ${YOUR_DROPLIT_API_URL}/faucets/${DROPLIT_NAME}/tap

Example: JavaScript (Node.js using node-fetch and bitcoin-auth)

import fetch from 'node-fetch'; // npm install node-fetch
import { AuthConfig, getAuthToken } from 'bitcoin-auth'; // npm install bitcoin-auth, corrected to getAuthToken

async function tapDroplitFaucet() {
  const droplitName = "your-droplit-name"; // Replace
  const userWIF = "your-private-key-wif"; // Replace
  const recipientBsvAddress = "1..."; // Replace with recipient's BSV address
  const tapAmount = 1000; // IMPORTANT: This must match the Droplit's configured drop_sats amount
  const droplitApiUrl = "http://localhost:8080"; // Replace with your API URL

  // First, you might want to fetch the Droplit's config to confirm tapAmount if not known
  // For this example, we assume tapAmount is correctly set.

  const requestPath = `/faucets/${droplitName}/tap`;
  const payload = {
    recipient_address: recipientBsvAddress,
    satoshis: tapAmount,
  };
  const bodyString = JSON.stringify(payload);

  const authConfig: AuthConfig = {
    privateKeyWif: userWIF,
    requestPath: requestPath,
    body: bodyString,
    // scheme defaults to 'bsm' in this version of bitcoin-auth
  };

  try {
    const authToken = await getAuthToken(authConfig); // Corrected to getAuthToken
    console.log('Auth Token:', authToken);

    const response = await fetch(`${droplitApiUrl}${requestPath}`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Auth-Token": authToken,
      },
      body: bodyString,
    });

    // It's good practice to check if the response is JSON before parsing
    let responseData;
    const contentType = response.headers.get("content-type");
    if (contentType && contentType.includes("application/json")) {
      responseData = await response.json();
    } else {
      responseData = await response.text(); // Or handle as appropriate
    }

    if (!response.ok) {
      console.error('API Error:', responseData);
      throw new Error(`HTTP error! Status: ${response.status} - ${responseData}`);
    }

    console.log("Tap successful:", responseData);
    // Expected response: { txid: "transaction_id" }
  } catch (error) {
    console.error("Error tapping faucet:", error);
  }
}

tapDroplitFaucet();

Success Response

On success, the API returns a JSON object containing the transaction ID (txid) of the Bitcoin transaction that paid the recipient.

{
  "txid": "abcdef123456..."
}

Error Responses

Common errors include:

  • 400 Bad Request: Invalid request body, parameters (e.g., satoshis amount mismatch), or recipient address.
  • 401 Unauthorized: Missing or invalid X-Auth-Token.
  • 403 Forbidden or 422 Unprocessable Entity: Tapping not enabled for the Droplit, or insufficient funds.
  • 500 Internal Server Error: Server-side issue.

The error response body will typically contain a JSON object with an error or message field.