Convert Figma logo to code with AI

btcsuite logobtcd

An alternative full node bitcoin implementation written in Go (golang)

6,169
2,343
6,169
272

Top Related Projects

78,260

Bitcoin Core integration/staging tree

7,630

Lightning Network Daemon ⚡️

A secure bitcoin wallet daemon written in Go (golang)

Core Lightning — Lightning Network implementation focusing on spec compliance and performance

A library for working with Bitcoin

2,995

Javascript bitcoin library for node.js and browsers

Quick Overview

btcd is an alternative full node Bitcoin implementation written in Go. It provides a robust, modular, and extensible Bitcoin node and wallet implementation, offering developers a platform to build Bitcoin-related applications and services.

Pros

  • Written in Go, providing excellent performance and concurrency
  • Modular architecture, making it easier to extend and maintain
  • Well-documented codebase with extensive test coverage
  • Actively maintained and regularly updated

Cons

  • Less widely adopted compared to Bitcoin Core
  • May have fewer features compared to Bitcoin Core
  • Potential compatibility issues with some Bitcoin services that expect Bitcoin Core
  • Steeper learning curve for developers not familiar with Go

Code Examples

  1. Connecting to the Bitcoin network:
config := &chaincfg.MainNetParams
btcdHomeDir := btcutil.AppDataDir("btcd", false)
db, err := database.Create("ffldb", dbPath, net)
if err != nil {
    return err
}
chain, err := blockchain.New(&blockchain.Config{
    DB:          db,
    ChainParams: config,
})
if err != nil {
    return err
}
server, err := server.NewServer(config, listeners, chain, nil)
if err != nil {
    return err
}
server.Start()
  1. Creating a new Bitcoin address:
privKey, err := btcec.NewPrivateKey()
if err != nil {
    return err
}
pubKey := privKey.PubKey()
pubKeyHash := btcutil.Hash160(pubKey.SerializeCompressed())
addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, &chaincfg.MainNetParams)
if err != nil {
    return err
}
fmt.Println("New Bitcoin address:", addr.EncodeAddress())
  1. Sending a Bitcoin transaction:
tx := wire.NewMsgTx(wire.TxVersion)
txOut := wire.NewTxOut(amount, pkScript)
tx.AddTxOut(txOut)

txHash, err := chainhash.NewHashFromStr(prevTxHash)
if err != nil {
    return err
}
prevOut := wire.NewOutPoint(txHash, prevTxIndex)
txIn := wire.NewTxIn(prevOut, nil, nil)
tx.AddTxIn(txIn)

signedTx, err := txscript.SignTx(tx, txscript.SigHashAll, privKey, pkScript)
if err != nil {
    return err
}

err = client.SendRawTransaction(signedTx, false)
if err != nil {
    return err
}

Getting Started

  1. Install Go (version 1.16 or later)
  2. Clone the repository:
    git clone https://github.com/btcsuite/btcd.git
    
  3. Build btcd:
    cd btcd
    go install . ./cmd/...
    
  4. Run btcd:
    btcd
    

For more detailed instructions and configuration options, refer to the project's README and documentation.

Competitor Comparisons

78,260

Bitcoin Core integration/staging tree

Pros of bitcoin

  • More comprehensive and widely adopted implementation
  • Serves as the reference client for Bitcoin protocol
  • Extensive documentation and community support

Cons of bitcoin

  • Larger codebase, potentially more complex to navigate
  • Slower development cycle due to rigorous review process
  • C++ language may be less accessible for some developers

Code Comparison

bitcoin (C++):

CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;

btcd (Go):

func (b *BlockChain) calcNextSubsidy(height int32) int64 {
    if b.subsidyCache != nil {
        subsidy := b.subsidyCache.Lookup(height)
        if subsidy != -1 {
            return subsidy
        }
    }

Key Differences

  • Language: bitcoin uses C++, while btcd is written in Go
  • btcd is a full node implementation, not a wallet
  • bitcoin includes a GUI wallet, btcd is command-line only
  • btcd may be easier to integrate into existing Go projects
  • bitcoin has more extensive peer review and testing processes

Both repositories are actively maintained and contribute to the Bitcoin ecosystem in different ways, catering to different developer preferences and use cases.

7,630

Lightning Network Daemon ⚡️

Pros of lnd

  • Implements the Lightning Network protocol, enabling fast and low-cost off-chain Bitcoin transactions
  • Provides a more user-friendly API and command-line interface for managing Lightning Network nodes
  • Offers additional features like autopilot for channel management and watchtower services

Cons of lnd

  • Higher complexity due to implementing the Lightning Network protocol on top of Bitcoin
  • Requires more resources to run and maintain compared to a full node implementation
  • May have a steeper learning curve for developers new to Lightning Network concepts

Code Comparison

btcd (Bitcoin full node implementation):

block := wire.MsgBlock{}
err := block.Deserialize(r)
if err != nil {
    return err
}

lnd (Lightning Network node implementation):

invoice, err := lnd.AddInvoice(ctx, &lnrpc.Invoice{
    Memo:  "Test payment",
    Value: 1000,
})
if err != nil {
    return err
}

The code snippets demonstrate the difference in focus between the two projects. btcd deals with low-level Bitcoin protocol operations, while lnd provides higher-level Lightning Network functionality.

A secure bitcoin wallet daemon written in Go (golang)

Pros of btcwallet

  • Focused on wallet functionality, providing a more specialized and user-friendly interface for managing Bitcoin wallets
  • Supports SPV (Simplified Payment Verification) mode, allowing for lightweight clients without full blockchain download
  • Integrates with btcd for full-node functionality, offering a complete Bitcoin ecosystem solution

Cons of btcwallet

  • More limited in scope compared to btcd, which provides full node implementation
  • Requires additional setup and configuration when used alongside btcd for full functionality
  • May have a steeper learning curve for developers new to Bitcoin wallet development

Code Comparison

btcwallet (wallet creation):

wallet, err := wallet.Create(db, pubPassphrase, privPassphrase, seed, &chaincfg.MainNetParams)
if err != nil {
    return err
}

btcd (node initialization):

node, err := node.New(&config, nil)
if err != nil {
    return err
}
err = node.Start()

Both repositories are part of the btcsuite project, with btcwallet focusing on wallet management and btcd providing full node implementation. While btcwallet offers more specialized wallet functionality, btcd provides a broader range of Bitcoin network features. Developers may choose to use both in conjunction for a complete Bitcoin application stack.

Core Lightning — Lightning Network implementation focusing on spec compliance and performance

Pros of lightning

  • Focuses on the Lightning Network, enabling fast and low-cost Bitcoin transactions
  • Supports multiple implementations and network interoperability
  • Actively developed with frequent updates and improvements

Cons of lightning

  • More complex to set up and use compared to btcd
  • Requires additional infrastructure and knowledge of Lightning Network concepts
  • May have higher resource requirements due to maintaining Lightning channels

Code comparison

lightning (C implementation):

static struct command_result *json_fundchannel(struct command *cmd,
                                               const char *buffer,
                                               const jsmntok_t *obj UNNEEDED,
                                               const jsmntok_t *params)
{
    u8 *msg;
    struct amount_sat amount;
    struct node_id *destination;

btcd (Go implementation):

func (s *server) handleNewPeer(sp *serverPeer) {
    go s.peerDoneHandler(sp)

    // Send version message to the peer.
    sp.PushAddrMsg(s.addrManager.GetAddresses())
    sp.PushVersionMsg(s.chainParams, &s.services, sp.LastBlock(),
        s.cfg.ExternalIPs)
}

The code snippets demonstrate the different languages and focuses of the projects. lightning deals with channel funding and Lightning-specific concepts, while btcd handles peer connections and Bitcoin protocol messages.

A library for working with Bitcoin

Pros of bitcoinj

  • Written in Java, offering better platform compatibility and integration with Android
  • Lightweight and suitable for mobile and embedded devices
  • Provides a more comprehensive API for building Bitcoin applications

Cons of bitcoinj

  • Less performant than btcd for full node operations
  • May not be as up-to-date with the latest Bitcoin protocol changes
  • Smaller developer community compared to Go-based projects

Code Comparison

bitcoinj (Java):

NetworkParameters params = TestNet3Params.get();
Wallet wallet = Wallet.createBasic(params);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addWallet(wallet);
peerGroup.start();

btcd (Go):

cfg := chaincfg.TestNet3Params
wallet, _ := wallet.Create(cfg)
peerCfg := peer.Config{ChainParams: &cfg}
peer, _ := peer.NewOutboundPeer(&peerCfg, "peer_address:port")
peer.Connect(conn)

Both examples demonstrate basic wallet creation and peer connection, but bitcoinj's API appears more abstracted and easier to use for beginners. btcd's code is more low-level, offering finer control over the Bitcoin network interactions.

2,995

Javascript bitcoin library for node.js and browsers

Pros of bcoin

  • Written in JavaScript, making it more accessible to web developers
  • Supports both full node and SPV modes
  • Includes a wallet system and mining capabilities out of the box

Cons of bcoin

  • Potentially slower performance due to being JavaScript-based
  • Less mature and battle-tested compared to btcd
  • Smaller community and fewer contributors

Code Comparison

bcoin (JavaScript):

const Chain = require('bcoin/lib/blockchain/chain');
const chain = new Chain({
  memory: true,
  network: 'testnet'
});

btcd (Go):

import "github.com/btcsuite/btcd/blockchain"

chain := blockchain.New(&blockchain.Config{
    DB:          db,
    ChainParams: chaincfg.TestNet3Params,
})

Both examples show the initialization of a blockchain object, but bcoin uses a more JavaScript-friendly approach with options passed as an object, while btcd follows Go conventions with a structured config parameter.

bcoin's JavaScript implementation makes it more approachable for web developers, but may sacrifice some performance compared to btcd's Go-based codebase. btcd benefits from Go's strong typing and concurrency features, potentially offering better performance and reliability for high-load scenarios. However, bcoin's all-in-one approach with built-in wallet and mining capabilities might be more convenient for some use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

btcd

Build Status Coverage Status ISC License GoDoc

btcd is an alternative full node bitcoin implementation written in Go (golang).

This project is currently under active development and is in a Beta state. It is extremely stable and has been in production use since October 2013.

It properly downloads, validates, and serves the block chain using the exact rules (including consensus bugs) for block acceptance as Bitcoin Core. We have taken great care to avoid btcd causing a fork to the block chain. It includes a full block validation testing framework which contains all of the 'official' block acceptance tests (and some additional ones) that is run on every pull request to help ensure it properly follows consensus. Also, it passes all of the JSON test data in the Bitcoin Core code.

It also properly relays newly mined blocks, maintains a transaction pool, and relays individual transactions that have not yet made it into a block. It ensures all individual transactions admitted to the pool follow the rules required by the block chain and also includes more strict checks which filter transactions based on miner requirements ("standard" transactions).

One key difference between btcd and Bitcoin Core is that btcd does NOT include wallet functionality and this was a very intentional design decision. See the blog entry here for more details. This means you can't actually make or receive payments directly with btcd. That functionality is provided by the btcwallet and Paymetheus (Windows-only) projects which are both under active development.

Requirements

Go 1.17 or newer.

Installation

https://github.com/btcsuite/btcd/releases

Linux/BSD/MacOSX/POSIX - Build from Source

  • Install Go according to the installation instructions here: http://golang.org/doc/install

  • Ensure Go was installed properly and is a supported version:

$ go version
$ go env GOROOT GOPATH

NOTE: The GOROOT and GOPATH above must not be the same path. It is recommended that GOPATH is set to a directory in your home directory such as ~/goprojects to avoid write permission issues. It is also recommended to add $GOPATH/bin to your PATH at this point.

  • Run the following commands to obtain btcd, all dependencies, and install it:
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ go install -v . ./cmd/...
  • btcd (and utilities) will now be installed in $GOPATH/bin. If you did not already add the bin directory to your system path during Go installation, we recommend you do so now.

Updating

Linux/BSD/MacOSX/POSIX - Build from Source

  • Run the following commands to update btcd, all dependencies, and install it:
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ git pull
$ go install -v . ./cmd/...

Getting Started

btcd has several configuration options available to tweak how it runs, but all of the basic operations described in the intro section work with zero configuration.

Linux/BSD/POSIX/Source

$ ./btcd

IRC

  • irc.libera.chat
  • channel #btcd
  • webchat

Issue Tracker

The integrated github issue tracker is used for this project.

Documentation

The documentation is a work-in-progress. It is located in the docs folder.

Release Verification

Please see our documentation on the current build/verification process for all our releases for information on how to verify the integrity of published releases using our reproducible build system.

License

btcd is licensed under the copyfree ISC License.