BitcoinLib

repository·master·Indexed 19 days ago

https://github.com/cryptean/bitcoinlib

A .NET library for interacting with Bitcoin and Altcoin daemons via RPC APIs. It provides strongly-typed structures and specific interfaces such as IBitcoinService, ILitecoinService, and ICryptocoinService to simplify blockchain operations.

Tokens
1.1K
Snippets
5
Records
5
Agent score
15%

What's inside bitcoinlib

  1. Configure Bitcoin Core for RPC access

    master

    To allow BitcoinLib to communicate with your Bitcoin daemon, you must enable the RPC server in your bitcoin.conf file.

    On Windows, this file is typically located at %AppData%\Roaming\Bitcoin.

    Add the following lines to your bitcoin.conf:

    rpcuser = MyRpcUsername
    rpcpassword = MyRpcPassword
    server=1
    txindex=1
  2. Install BitcoinLib via NuGet

    master

    BitcoinLib is available as a NuGet package for .NET projects. You can find it on the NuGet gallery to integrate Bitcoin and Altcoin RPC functionality into your application.

    # Search for BitcoinLib on NuGet or add via Package Manager Console
    Install-Package BitcoinLib
  3. Configure BitcoinLib via app.config

    master

    BitcoinLib can be configured using an app.config file. This allows you to define RPC timeouts, daemon URLs (including testnet), wallet passwords, and RPC credentials without hardcoding them.

    Note: If you change Bitcoin_RpcUsername or Bitcoin_RpcPassword in your config, you must also update your corresponding bitcoin.conf file to match.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
        <!-- BitcoinLib settings start -->
    
          <!-- Shared RPC settings start -->
          <add key="RpcRequestTimeoutInSeconds" value="10" />
          <!-- Shared RPC settings end -->
    
          <!-- Bitcoin settings start -->
          <add key="Bitcoin_DaemonUrl" value="http://localhost:8332" />
          <add key="Bitcoin_DaemonUrl_Testnet" value="http://localhost:18332" />
          <add key="Bitcoin_WalletPassword" value="MyWalletPassword" />
          <add key="Bitcoin_RpcUsername" value="MyRpcUsername" />
          <add key="Bitcoin_RpcPassword" value="MyRpcPassword" />
          <!-- Bitcoin settings end -->
    
        <!-- BitcoinLib settings end -->
      </appSettings>
    </configuration>
  4. Initialize Bitcoin, Litecoin, or generic Altcoin services

    master

    BitcoinLib provides specific interfaces for common coins and a generic interface for any Bitcoin clone.

    • Use IBitcoinService for Bitcoin.
    • Use ILitecoinService for Litecoin.
    • Use ICryptocoinService for any other Bitcoin clone (like Dogecoin, Dash, etc.) by providing connection details at runtime.

    You can further customize any coin instance at runtime using the .Parameters property of the ICryptocoinService interface.

    // Initialize Bitcoin service
    IBitcoinService BitcoinService = new BitcoinService();
    
    // Initialize Litecoin service
    ILitecoinService LitecoinService = new LitecoinService();
    
    // Initialize a generic Bitcoin clone (e.g., Dogecoin)
    ICryptocoinService cryptocoinService = new CryptocoinService("daemonUrl", "rpcUsername", "rpcPassword", "walletPassword");
    
    // Fully configure the coin pointer at run-time
    // (Assuming cryptocoinService is an ICryptocoinService)
    // cryptocoinService.Parameters[...]