Technical Documentation
Basic Docs
  • X (Twitter)
  • Discord
  • 👋Welcome
  • Introduction to CapsureLabs Ecosystem and Architecture
    • Overview of CapsureLabs System and Components
    • Target Audiences and Use Cases
    • Security Model and Access Management
  • System Architecture of CapsureLabs
    • Platform Architecture Overview
    • Microservices Architecture
    • Blockchain and External System Integration
  • API and Integrations
    • REST and WebSocket API
    • GraphQL API for Developers
    • Integration with Third-Party Services and Modules
  • Tools for Traders and Investors
    • AiTradeBot: Algorithms and Prediction
    • NFT Sniper: Data Analysis and Automation
    • DeFi Yield Optimizer: Integration and Yield Automation
    • Arbitrage Scanner: Automated Trade Execution
  • Smart Contract Development and Deployment
    • Essential Patterns and Practices in Smart Contract Development
    • Development Tools: Solidity, Hardhat, Truffle
    • Gas Optimization Solutions
  • Tools for Content Creators
    • NFT Creator Hub: Generation and Management
    • MetaGallery: Creating Virtual Galleries
    • IP Protection Tool: Smart Contracts for IP Protection
    • Revenue Splitter: Automated Revenue Distribution
  • Developer Tools
    • Web3 Dev Toolkit: Libraries and Frameworks
    • Smart Contract Debugger: Contract Testing
    • Chain Interoperability Tool: Building Cross-Chain Applications
  • Wallet Management and Monitoring
    • Wallet Aggregator: Managing Multiple Wallets
    • Decentralized Identity Manager: Access Control and Management
    • Transaction and Balance Monitoring Tools
  • Gaming and Metaverse
    • Game Asset Tracker: Monitoring Game Assets
    • Play-to-Earn Optimizer: Earnings Optimization
    • Virtual Land Manager: Virtual Real Estate Management
  • DAO and Decentralized Governance
    • DAO Governance Tool: Creation and Management
    • Community Incentive Manager: Token and Reward Management
  • Security Protocols and Data Protection
    • Authentication and Access Control
    • Data and Communication Encryption Methods
    • Compliance and Regulatory Alignment
  • Cloud Infrastructure and DevOps
    • Server and Network Configuration Management
    • Monitoring, CI/CD, and Disaster Recovery
    • Auto-Scaling and Load Balancing
  • Payment Gateways and Financial Integration
    • Cryptocurrency Payment Gateways
    • Fiat Payment Systems Integration
  • Machine Learning and Prediction Techniques
    • AI Algorithms for Data Analysis
    • Real-Time User Behavior Analysis
    • Automation and Content Generation
  • Testing and Quality Assurance
    • Automated and Manual Testing
    • Load Testing and Performance Optimization
    • System Monitoring and Auto-Recovery
  • GitHub
Powered by GitBook
On this page
  • 1.1 T&B Monitoring Overview
  • 1.2 Code for Monitoring Balances and Transactions
  • 1.2.1 Monitoring Wallet Balance
  • 1.2.2 Real-Time Balance Monitoring with WebSocket
  • 1.2.3 Transaction Monitoring
  • 1.2.4 Multi-Asset Balance Monitoring (ERC-20 Tokens)
  • 1.3 API Integration
  • 1.3.1 GET /wallets/{wallet_id}/balance
  • 1.3.2 GET /wallets/{wallet_id}/transactions
  • 1.3.3 WebSocket /wallets/subscribe
  1. Wallet Management and Monitoring

Transaction and Balance Monitoring Tools

1.1 T&B Monitoring Overview

Transaction and Balance Monitoring Tools in the CapsureLabs platform allow users to track real-time wallet activity, including balance updates and transaction histories. These tools are designed to support both Ethereum-compatible blockchains and can be extended to support additional chains. This documentation provides code examples using Web3.js to monitor balances and transactions efficiently.


1.2 Code for Monitoring Balances and Transactions

1.2.1 Monitoring Wallet Balance

const Web3 = require('web3');
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/YOUR_INFURA_PROJECT_ID');

// Define the user's wallet address
const walletAddress = '0xYourEthereumAddressHere';

// Function to retrieve the current balance
async function checkBalance() {
  try {
    const balance = await web3.eth.getBalance(walletAddress);
    console.log(`Wallet Balance: ${web3.utils.fromWei(balance, 'ether')} ETH`);
  } catch (error) {
    console.error("Error fetching balance:", error);
  }
}

// Check balance at regular intervals (e.g., every minute)
setInterval(checkBalance, 60000);

1.2.2 Real-Time Balance Monitoring with WebSocket

web3.eth.subscribe('newBlockHeaders', (error, block) => {
  if (error) console.error("Subscription error:", error);
  else checkBalance();
});

1.2.3 Transaction Monitoring

const monitoredAddress = walletAddress;

// Function to monitor new transactions in each block
web3.eth.subscribe('pendingTransactions', async (error, txHash) => {
  if (error) return console.error("Error:", error);

  // Get transaction details
  const tx = await web3.eth.getTransaction(txHash);

  if (tx && (tx.to === monitoredAddress || tx.from === monitoredAddress)) {
    console.log("Transaction detected:");
    console.log(`From: ${tx.from}`);
    console.log(`To: ${tx.to}`);
    console.log(`Amount: ${web3.utils.fromWei(tx.value, 'ether')} ETH`);
    console.log(`Tx Hash: ${tx.hash}`);
  }
});

1.2.4 Multi-Asset Balance Monitoring (ERC-20 Tokens)

const tokenContractAddress = '0xTokenContractAddressHere';
const tokenABI = [
  // Minimal ABI to get balance
  {
    "constant": true,
    "inputs": [{ "name": "_owner", "type": "address" }],
    "name": "balanceOf",
    "outputs": [{ "name": "balance", "type": "uint256" }],
    "type": "function"
  }
];

// Create contract instance
const tokenContract = new web3.eth.Contract(tokenABI, tokenContractAddress);

// Function to check token balance
async function checkTokenBalance() {
  try {
    const tokenBalance = await tokenContract.methods.balanceOf(walletAddress).call();
    console.log(`Token Balance: ${web3.utils.fromWei(tokenBalance, 'ether')} Tokens`);
  } catch (error) {
    console.error("Error fetching token balance:", error);
  }
}

// Check token balance periodically
setInterval(checkTokenBalance, 60000);

1.3 API Integration

1.3.1 GET /wallets/{wallet_id}/balance

curl -X GET "https://api.capsurelabs.com/wallets/0xYourWalletAddress/balance" \
  -H "Authorization: Bearer <token>"

1.3.2 GET /wallets/{wallet_id}/transactions

curl -X GET "https://api.capsurelabs.com/wallets/0xYourWalletAddress/transactions" \
  -H "Authorization: Bearer <token>"

1.3.3 WebSocket /wallets/subscribe

{
  "type": "subscribe",
  "walletId": "0xYourWalletAddress"
}

PreviousDecentralized Identity Manager: Access Control and ManagementNextGame Asset Tracker: Monitoring Game Assets

Last updated 7 months ago

Page cover image