Creating Your First BTCv2 Application

Documentation

This guide will walk you through creating your first application on the Bitcoin Mobile platform, from initial setup to deploying a functional app.

Prerequisites

  • Basic understanding of JavaScript/TypeScript
  • Node.js installed (v14 or later)
  • A Bitcoin Mobile developer account
  • BTCv2 SDK installed

Setup Your Development Environment

Before you begin, make sure you've set up your development environment by following our Developer Environment Setup Guide.

Step 1: Initialize Your Project

# Create a new directory for your project
mkdir my-btcv2-app
cd my-btcv2-app

# Initialize a new Node.js project
npm init -y

# Install the BTCv2 SDK
npm install @btcmobile/sdk

Step 2: Configure Your Application

Create a config file to store your Bitcoin Mobile API credentials and configuration.

// config.js
export const config = {
  network: process.env.BTCV2_NETWORK || 'testnet',
  apiKey: process.env.BTCV2_API_KEY || 'your-api-key'
};

Step 3: Create Your First Transaction

Let's create a simple script that connects to the BTCv2 network and displays the current network status.

// index.js
import { BTCv2Client } from '@btcmobile/sdk';
import { config } from './config.js';

// Initialize the client
const client = new BTCv2Client({
  network: config.network,
  apiKey: config.apiKey
});

async function main() {
  try {
    // Connect to the network
    await client.connect();
    console.log('Connected to BTCv2 network!');
    
    // Get network status
    const status = await client.getNetworkStatus();
    console.log('Network Status:', status);
    
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

Step 4: Run Your Application

Run your application using the following command:

node index.js

Next Steps

Now that you've created your first BTCv2 application, explore more advanced features:

  • Sending and receiving BTCv2 tokens
  • Integrating with the mining system
  • Using the bridge to convert between BTC and BTCv2
  • Building a user interface for your application