Demos Network Specifications
  • Introduction
    • What is Demos Network
    • Demos Network Architecture
  • FAQ
  • Cookbook
    • Project setup
      • Run the project (MacOS)
      • Run the project (Windows)
        • WSL 2 Setup on Windows (10 and 11 only)
        • Issue Troubleshooting
      • Run the project (Ubuntu)
  • SDK
    • Getting Started
    • WebSDK
      • Authentication
        • FIDO2 Passkeys
          • Under the Hood: FIDO2 Passkeys
      • NodeCalls
      • Transactions
        • Creating a transaction
        • Signing a transaction
        • Broadcasting a transaction
      • L2PS SDK
        • The l2ps module
        • Interacting with the L2PS
        • L2PS Messaging System
      • Instant Messaging
        • What is the Instant Messaging Protocol?
        • Architecture Overview
        • Encryption
        • Quickstart
        • Message Types
        • API Reference
        • FAQ
    • Cross Chain
      • General layout of the XM SDKs
      • EVM
      • BTC
      • Solana
      • MultiversX (EGLD)
      • NEAR
      • IBC
      • TON
      • XRPL
      • The XMScript
      • Identities
    • Demoswork
    • Cookbook
      • Demoswork
        • Creating work steps
        • Conditional Operation
        • Base Operation
        • Signing and broadcasting
      • Transactions
        • Crosschain Transaction
        • Native Transactions
      • SWAP
        • Crosschain SWAP
    • Web2
      • Quick Start
      • DAHR API Reference
        • Types
      • Making Requests
      • Identities
        • Twitter
        • GitHub
    • API Reference
    • Bridges
      • Rubic Bridge Test
    • Post Quantum Cryptography
  • Backend
    • Internal Mechanisms
      • Network Time Synchronization
      • Cross Context Identities
    • Global Change Registry
      • GCR Structure
      • How is GCR Synced?
    • Consensus Mechanism
      • Unparalleled Scalability
      • Decentralization in PoR-BFT
      • Enhanced Security
      • Comparative Advantage
      • Addressing Potential Criticisms
      • Conclusion
    • Communications Stack
    • L2PS (Subnet) Framework
      • How are L2PS transactions handled?
    • Miscellaneous
      • Browsing the Postgres DB via psql
    • Bridges
      • Rubic Bridge
    • Developers Testbed
      • Setting up the environment
      • Setting up the repository
      • Installing dependencies
      • Node Configuration
      • Running the node
  • Frontend
    • Demos Providers Discovery Mechanism
Powered by GitBook
On this page
  • Wallet setup
  • Get tokens on the testnet
  • Initialization
  • Wallet connect
  • Create payload for the token transfer
  • Create payload for the multiple transfers
  • Checking Balance
  • Resources
  1. SDK
  2. Cross Chain

BTC

PreviousEVMNextSolana

Last updated 2 months ago

The Bitcoin SDK provides an interface to interact with Bitcoin blockchains using SegWit (P2WPKH) transactions. It supports wallet connectivity, transaction preparation, and balance checking, using the bitcoinjs-lib library for core functionality.

Wallet setup

To generate new Bitcoin WIF (Wallet Import Format) private keys for P2WPKH wallets, you can use the following tools:

  • (testnet)

Get tokens on the testnet

For testing process, you can use following links to get token on the testnet

Initialization

Import the SDK and create a new instance:

import { BTC } from "@kynesyslabs/demosdk/xm-websdk"

const rpc_url = "https://blockstream.info/testnet/api";
const network = BTC.networks.testnet;

const instance = await BTC.create(rpc_url, network);

Wallet connect

Connect your wallet using a private key in WIF format:

const privateKeyWIF = "cTb..."; // Your WIF private key
await instance.connectWallet(privateKeyWIF);

You can view the connected wallet’s address using the getAddress method:

const address = instance.getAddress();
console.log(`Address: ${address}`);

Create payload for the token transfer

Prepare a signed transaction to transfer BTC using preparePay method:

const receiverAddress = "tb1q...";
const amount = "560"; // Amount in satoshis

const signedTx = await instance.preparePay(receiverAddress, amount);

The signedTx is a hex-encoded signed transaction ready for use in a DEMOS transaction.

Create payload for the multiple transfers

You can create multiple Bitcoin transfer payloads by using the preparePays method as shown:

const transfers = [
    { address: "tb1q...", amount: "550" },
];
const signedTxs = await instance.preparePays(transfers);

The signedTxs is an array of hex-encoded signed transaction payloads.

Checking Balance

You can check the balance of the connected wallet, including change addresses as shown:

const balance = await instance.getBalance();
console.log(`Balance: ${balance} satoshis`);

Resources

Bitcoin Tools
Bitaddress.org
Coinfaucet
Testnet Faucet
Bitcoin Website
BitcoinJS Documentation
Blockstream Explorer
Testnet Explorer