Transaction Guide

This guide covers transaction management features in the BitPowr API that work across all supported blockchain networks. These features provide enhanced control over transaction processing, prevent duplicate transactions, enable complex workflows, and improve transaction organization.

Base URL: https://developers.bitpowr.com/api/v1/transactions

Authentication: Bearer token required in Authorization header


Common Transaction Parameters

Core Workflow Parameters

ParameterTypeDescriptionSupported Chains
idempotencyKeystringUnique key to prevent duplicate transactionsAll chains
queuedbooleanWhether to queue transaction or send directlyAll chains
memostringMemo string included in blockchain transactionStellar, Solana
dependsOnarrayList of transaction IDs to wait for completionAll chains
customerIdstringCustomer identifier for transaction trackingAll chains
subAccountIdstringSub-account to spend from automaticallyAll chains
walletIdstringWallet to spend from automaticallyAll chains
descriptionstringTransaction descriptionAll chains
assetTypestringCrypto currency e.g ETH, BTC, USDT, USDT_BASEAll chains
fromstringList of addresses to spend fromAll chians

1. Idempotent Transactions

Prevent duplicate transactions and race conditions by using idempotency keys. This ensures that multiple identical requests don't create multiple transactions.

How Idempotency Works

  • First Request: Creates new transaction with the idempotency key
  • Duplicate Requests: Should return the original transaction instead of creating new ones
  • Scope: Keys are scoped to your account/wallet

Basic Idempotent Transaction

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "BTC",
          "tos": [{
              "address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
              "value": "0.001"
          }],
          "idempotencyKey": "payment-order-12345-attempt-1",
          "description": "Idempotent Bitcoin payment"
      }'

Idempotency Key Best Practices

// Generate idempotency key with order ID and timestamp
const generateIdempotencyKey = (orderId, userId) => {
  const timestamp = Date.now();
  return `order-${orderId}-user-${userId}-${timestamp}`;
};

// Example usage
const idempotencyKey = generateIdempotencyKey("12345", "user789");

Handling Idempotent Responses

const createTransaction = async (transactionData) => {
  try {
    const response = await fetch('/api/v1/transactions', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer <token>'
      },
      body: JSON.stringify({
        ...transactionData,
        idempotencyKey: generateIdempotencyKey(transactionData.orderId)
      })
    });
    
    const result = await response.json();
    
    if (response.status === 201) {
      console.log('New transaction created:', result.data.uid);
    } else if (response.status === 200) {
      console.log('Existing transaction returned:', result.data.uid);
    }
    
    return result;
  } catch (error) {
    console.error('Transaction failed:', error);
  }
};

2. Queued vs Direct Processing

Control whether transactions are processed immediately or queued for batch processing.

Direct Processing (queued: false)

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "ETH",
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "0.1"
          }],
          "queued": false,
          "description": "Immediate ETH transfer"
      }'

Direct Processing Characteristics:

  • Transaction processed immediately
  • Response includes blockchain hash
  • Faster for single transactions
  • Higher resource usage

Queued Processing (queued: true)

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "USDC_ETH",
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "100"
          }],
          "queued": true,
          "description": "Queued USDC transfer"
      }'

Queued Processing Characteristics:

  • Transaction added to processing queue
  • Response does not include hash initially
  • Better for batch operations
  • Optimized resource usage
  • Handles nonce management automatically

When to Use Each Mode

Use CaseRecommended ModeReason
High-frequency tradingqueued: falseImmediate execution needed
Batch paymentsqueued: trueOptimized processing
User-initiated transfersqueued: falseBetter user experience
Automated workflowsqueued: trueEfficient resource usage
Emergency transactionsqueued: falseImmediate processing

3. Memo Support

Include memo strings in blockchain transactions for Stellar and Solana networks.

Stellar Memo Transaction

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "XLM",
          "tos": [{
              "address": "GAHK7EEG2WWHVKDNT4CEQFZGKF2LGDSW2IVM4S5DP42RBW3K6BTODB4A",
              "value": "10"
          }],
          "memo": "Payment for Invoice INV-2024-001",
          "description": "Stellar payment with memo"
      }'

Solana Memo Transaction

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "SOL",
          "tos": [{
              "address": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
              "value": "1"
          }],
          "memo": "Monthly subscription payment - User ID: 12345",
          "description": "SOL payment with memo"
      }'

Memo Use Cases

  1. Invoice References: Link payments to specific invoices
  2. Order IDs: Connect transactions to e-commerce orders
  3. User Identification: Include user IDs for payment tracking. E.g username, email
  4. Compliance: Required information for regulatory compliance
  5. Internal Tracking: Business-specific reference data

Memo Limitations

ChainMax LengthEncodingNotes
Stellar28 bytesUTF-8Text memo type
Solana~1000 charsUTF-8Part of transaction data

4. Transaction Dependencies

Ensure transactions are processed in specific order by using the dependsOn parameter.

Basic Dependency Example

# First transaction
curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "ETH",
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "1"
          }],
          "idempotencyKey": "funding-tx-001",
          "description": "Initial funding transaction"
      }'

# Response: { "data": { "uid": "tx-funding-123" } }

# Dependent transaction
curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "USDC_ETH",
          "tos": [{
              "address": "0x1180a4c0c71b5eb0256edcffcc3389f1f085c502",
              "value": "100"
          }],
          "dependsOn": ["tx-funding-123"],
          "idempotencyKey": "payment-tx-001",
          "description": "Payment after funding"
      }'

Multiple Dependencies

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "BTC",
          "tos": [{
              "address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
              "value": "0.01"
          }],
          "dependsOn": ["tx-gas_funding-456", "tx-approve-789"],
          "description": "Final payment after approvals"
      }'

Dependency Use Cases

  1. Sequential Workflows: Ensure transactions happen in order
  2. Conditional Payments: Wait for approvals before processing
  3. Multi-Step Operations: Complex business logic requiring order
  4. Risk Management: Verify previous transactions before proceeding
  5. Compliance Workflows: Wait for compliance checks

Dependency Behavior

  • Waiting State: Dependent transactions remain in QUEUE until dependencies complete
  • Failure Handling: If any dependency fails, dependent transaction may be cancelled
  • Timeout: Dependencies have timeout limits to prevent indefinite waiting
  • Circular Dependencies: System prevents circular dependency chains

5. Customer Tracking

Associate transactions with specific customers for better organization and reporting.

Customer-Linked Transaction

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "USDC_ETH",
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "500"
          }],
          "customerId": "customer-premium-789",
          "idempotencyKey": "premium-payment-001",
          "description": "Premium service payment"
      }'

Customer Analytics Example

// Filter transactions by customer
const getCustomerTransactions = async (customerId) => {
  const response = await fetch(`/api/v1/transactions?customerId=${customerId}`, {
    headers: { 'Authorization': 'Bearer <token>' }
  });
  return response.json();
};

// Customer transaction summary
const getCustomerSummary = async (customerId) => {
  const transactions = await getCustomerTransactions(customerId);
  
  return {
    totalTransactions: transactions.length,
    totalVolume: transactions.reduce((sum, tx) => sum + parseFloat(tx.amount), 0),
    successRate: transactions.filter(tx => tx.status === 'CONFIRMED').length / transactions.length,
    lastTransaction: transactions[0]?.createdAt
  };
};

Customer Tracking Benefits

  1. Transaction History: Easy customer transaction lookup
  2. Analytics: Customer-specific transaction analytics
  3. Support: Quick customer support with transaction history
  4. Compliance: Customer due diligence and reporting
  5. Business Intelligence: Customer behavior analysis

6. Sub-Account Management

Use sub-accounts to automatically select addresses and UTXOs for transactions without specifying exact sources.

Sub-Account Transaction

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "BTC",
          "subAccountId": "trading-account-001",
          "tos": [{
              "address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
              "value": "0.005"
          }],
          "description": "Payment from trading sub-account"
      }'

Sub-Account with Customer Tracking

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "USDC_SOL",
          "subAccountId": "customer-wallet-456",
          "customerId": "premium-customer-789",
          "tos": [{
              "address": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
              "value": "1000"
          }],
          "memo": "Large payment from customer wallet",
          "description": "Customer-to-customer transfer"
      }'

Sub-Account Error Handling

# This will cause an error - mixing sub-account with explicit address
curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "ETH",
          "subAccountId": "trading-account-001",
          "from": ["0x40fa00fe4a0a655240fede3149e9ea55118241e2"],
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "0.1"
          }]
      }'

Error Response:

{
  "status": "error",
  "message": "Address 0x40fa... is not under sub-account trading-account-001"
}

Sub-Account Features

  1. Automatic Selection: System selects optimal addresses/UTXOs
  2. Isolation: Transactions isolated to specific sub-account funds
  3. Simplified Usage: No need to track individual addresses
  4. Error Prevention: Prevents using addresses from wrong sub-accounts
  5. Balance Management: Clear separation/segregation of funds by purpose

7. Combined Advanced Features

Example combining multiple advanced features for a complex business workflow.

E-commerce Order Processing

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "USDC_ETH",
          "subAccountId": "escrow-account-001",
          "customerId": "customer-premium-789",
          "tos": [{
              "address": "0x742d35Cc6644C0532925a3b8C17DAb6F2c8f1234",
              "value": "2500"
          }],
          "dependsOn": ["gas_funding", "payment_send"],
          "idempotencyKey": "order-12345-payment-final",
          "queued": true,
          "description": "E-commerce order payment after all verifications"
      }'

Subscription Payment Workflow

curl --request POST \
     --url https://developers.bitpowr.com/api/v1/transactions \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <encodedToken>' \
     -d '{
          "walletId": "e3455-15b5-46ad-84de-34555",
          "assetType": "SOL",
          "subAccountId": "subscription-wallet",
          "customerId": "subscriber-monthly-456",
          "tos": [{
              "address": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
              "value": "50"
          }],
          "memo": "Monthly subscription - Plan Premium - Month 3",
          "idempotencyKey": "subscription-456-month-3-2025-01",
          "queued": true,
          "description": "Monthly subscription payment"
      }'

Transaction Response with Advanced Features

{
  "status": "success",
  "data": {
    "hash": "0x8f2a5b3c9d1e4f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a",
    "status": "PENDING",
    "amount": "2500",
    "uid": "6680c116-c803-4e46-aa99-2f261cd216ac",
    "assetType": "USDC_ETH",
    "chain": "ETHEREUM",
    "fee": "0.000195",
    "ref": "BTP-EthTx123#ABC456",
    "network": "MAINNET",
    "customerId": "customer-premium-789",
    "subAccountId": "escrow-account-001",
    "idempotencyKey": "order-12345-payment-final",
    "queued": true,
    "dependsOn": ["kyc-verification-tx", "fraud-check-tx"],
    "memo": null,
    "createdAt": "2025-01-15T10:30:00Z",
    "updatedAt": "2025-01-15T10:30:00Z"
  }
}

Best Practices

Idempotency

  1. Unique Keys: Use business-specific identifiers in keys
  2. Key Format: Include timestamp and context for uniqueness
  3. Key Storage: Store keys for audit and debugging
  4. Retry Logic: Use same key for retries

Queue Management

  1. Direct for Urgent: Use direct processing for time-sensitive transactions
  2. Queue for Batch: Use queued processing for bulk operations
  3. Monitor Queues: Track queue depths and processing times
  4. Error Handling: Handle queue failures gracefully

Dependencies

  1. Limit Depth: Avoid deep dependency chains
  2. Timeout Planning: Plan for dependency timeouts
  3. Failure Handling: Define behavior when dependencies fail
  4. Status Monitoring: Monitor dependency resolution

Organization

  1. Customer Linking: Always link transactions to customers when possible
  2. Sub-Account Strategy: Use sub-accounts for clear fund separation
  3. Memo Usage: Include relevant reference information
  4. Description Standards: Use consistent description formats