Top Related Projects
Bitcoin Core integration/staging tree
A library for working with Bitcoin
Electrum Bitcoin Wallet
Bitcoin Wallet app for your Android device. Standalone Bitcoin node, no centralized backend required.
Quick Overview
btcwallet is an open-source Bitcoin wallet implementation written in Go. It provides a secure and feature-rich wallet solution for managing Bitcoin transactions and keys, designed to be used as a library or as a standalone application.
Pros
- Robust security features, including hierarchical deterministic (HD) wallets and support for hardware wallets
- Extensive API for integration with other applications and services
- Active development and maintenance by the btcsuite team
- Well-documented codebase with clear architecture
Cons
- Steep learning curve for newcomers to Bitcoin development
- Limited support for altcoins or other cryptocurrencies
- Requires significant system resources for full node functionality
- May be overkill for simple wallet needs
Code Examples
- Creating a new wallet:
import "github.com/btcsuite/btcwallet/wallet"
cfg := &wallet.Config{
DataDir: "/path/to/wallet/data",
Network: &chaincfg.MainNetParams,
PubPassphrase: []byte("public"),
PrivPassphrase: []byte("private"),
DisableTLS: false,
AccountGapLimit: 20,
}
w, err := wallet.Create(cfg)
if err != nil {
log.Fatal(err)
}
- Generating a new address:
account := uint32(0)
addr, err := w.NewAddress(account, wallet.WithGapPolicyWrap())
if err != nil {
log.Fatal(err)
}
fmt.Printf("New address: %s\n", addr.EncodeAddress())
- Sending a transaction:
import "github.com/btcsuite/btcd/chaincfg/chainhash"
amount := btcutil.Amount(1000000) // 0.01 BTC
addr, _ := btcutil.DecodeAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", &chaincfg.MainNetParams)
txHash, err := w.SendOutputs([]*wire.TxOut{
wire.NewTxOut(int64(amount), addr.ScriptAddress()),
}, wallet.DefaultAccountNum, 1, wallet.DefaultSatPerKbTxFee)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Transaction sent: %s\n", txHash.String())
Getting Started
To use btcwallet in your Go project:
- Install Go (version 1.13 or later)
- Install btcwallet:
go get -u github.com/btcsuite/btcwallet
- Import the package in your code:
import "github.com/btcsuite/btcwallet/wallet"
- Initialize and use the wallet as shown in the code examples above.
Note: For full functionality, you may need to run a Bitcoin full node or connect to an existing one.
Competitor Comparisons
Bitcoin Core integration/staging tree
Pros of bitcoin
- More comprehensive and feature-rich implementation of the Bitcoin protocol
- Larger and more active community of contributors and users
- Serves as the reference implementation for Bitcoin, setting standards for the network
Cons of bitcoin
- More complex codebase, potentially harder for newcomers to understand and contribute
- Slower development cycle due to rigorous review process and focus on stability
- Higher resource requirements for running a full node
Code comparison
btcwallet:
func (w *Wallet) CreateTransaction(amount btcutil.Amount, addr btcutil.Address, minconf int32) (*wire.MsgTx, error) {
// Implementation details
}
bitcoin:
UniValue sendtoaddress(const JSONRPCRequest& request)
{
// Implementation details
}
btcwallet is written in Go and provides a more straightforward API for wallet operations, while bitcoin is written in C++ and offers lower-level control over transaction creation and management.
A library for working with Bitcoin
Pros of bitcoinj
- Written in Java, offering better cross-platform compatibility and integration with Android
- More extensive documentation and a larger community
- Supports SPV (Simplified Payment Verification) mode for lightweight clients
Cons of bitcoinj
- Generally slower performance compared to Go-based implementations
- Less suitable for high-performance server-side applications
- May require more memory due to Java's garbage collection
Code Comparison
btcwallet (Go):
func (w *Wallet) CreateTransaction(amount btcutil.Amount, addr btcutil.Address, minconf int32, feeSatPerKB btcutil.Amount) (*wire.MsgTx, error) {
// Implementation details
}
bitcoinj (Java):
public Transaction createTransaction(Address address, Coin value) throws InsufficientMoneyException {
// Implementation details
}
Both repositories provide wallet functionality for Bitcoin, but they differ in language and approach. btcwallet is written in Go, offering better performance for server-side applications, while bitcoinj is more suitable for cross-platform and mobile development. The code snippets show similar transaction creation methods, but with language-specific syntax and types.
Electrum Bitcoin Wallet
Pros of Electrum
- Multi-platform support (Windows, macOS, Linux, Android)
- User-friendly GUI with advanced features like coin control
- Supports hardware wallets and multi-signature transactions
Cons of Electrum
- Relies on Electrum servers, potentially compromising privacy
- Less suitable for programmatic use compared to btcwallet
- Not as deeply integrated with the Bitcoin Core ecosystem
Code Comparison
Electrum (Python):
def get_tx_height(self, tx_hash):
tx_info = self.network.synchronous_get(('blockchain.transaction.get', [tx_hash]))
return tx_info.get('height')
btcwallet (Go):
func (w *Wallet) FetchTxHeight(txHash *chainhash.Hash) (int32, error) {
txDetails, err := w.TxStore.TxDetails(txHash)
if err != nil {
return 0, err
}
return txDetails.Height(), nil
}
Both examples show methods for retrieving transaction height, but Electrum uses a network request to an Electrum server, while btcwallet accesses local data from its TxStore.
Bitcoin Wallet app for your Android device. Standalone Bitcoin node, no centralized backend required.
Pros of bitcoin-wallet
- More user-friendly interface for mobile devices
- Supports multiple cryptocurrencies beyond just Bitcoin
- Regularly updated with new features and improvements
Cons of bitcoin-wallet
- Less customizable for advanced users
- May have slower transaction processing times
- Limited support for advanced Bitcoin features
Code Comparison
btcwallet:
func (w *Wallet) CreateTransaction(amount btcutil.Amount, addr btcutil.Address, feeRate btcutil.Amount) (*wire.MsgTx, error) {
// Implementation details
}
bitcoin-wallet:
public Transaction createTransaction(Coin value, Address address) throws InsufficientMoneyException {
// Implementation details
}
The code snippets show that btcwallet is implemented in Go, while bitcoin-wallet uses Java. btcwallet's function includes a fee rate parameter, indicating more granular control over transaction fees. bitcoin-wallet's method is simpler, potentially easier for beginners but less flexible for advanced users.
Both repositories serve as Bitcoin wallets but cater to different user needs. btcwallet is more suitable for developers and advanced users who require greater control and customization. bitcoin-wallet is better for general users, especially on mobile devices, who prefer a simpler interface and multi-cryptocurrency support.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
btcwallet
btcwallet is a daemon handling bitcoin wallet functionality for a single user. It acts as both an RPC client to btcd and an RPC server for wallet clients and legacy RPC applications.
Public and private keys are derived using the hierarchical
deterministic format described by
BIP0032.
Unencrypted private keys are not supported and are never written to
disk. btcwallet uses the
m/44'/<coin type>'/<account>'/<branch>/<address index>
HD path for all derived addresses, as described by
BIP0044.
Due to the sensitive nature of public data in a BIP0032 wallet, btcwallet provides the option of encrypting not just private keys, but public data as well. This is intended to thwart privacy risks where a wallet file is compromised without exposing all current and future addresses (public keys) managed by the wallet. While access to this information would not allow an attacker to spend or steal coins, it does mean they could track all transactions involving your addresses and therefore know your exact balance. In a future release, public data encryption will extend to transactions as well.
btcwallet is not an SPV client and requires connecting to a local or remote btcd instance for asynchronous blockchain queries and notifications over websockets. Full btcd installation instructions can be found here. An alternative SPV mode that is compatible with btcd and Bitcoin Core is planned for a future release.
Wallet clients can use one of two RPC servers:
-
A legacy JSON-RPC server mostly compatible with Bitcoin Core
The JSON-RPC server exists to ease the migration of wallet applications from Core, but complete compatibility is not guaranteed. Some portions of the API (and especially accounts) have to work differently due to other design decisions (mostly due to BIP0044). However, if you find a compatibility issue and feel that it could be reasonably supported, please report an issue. This server is enabled by default.
-
An experimental gRPC server
The gRPC server uses a new API built for btcwallet, but the API is not stabilized and the server is feature gated behind a config option (
--experimentalrpclisten
). If you don't mind applications breaking due to API changes, don't want to deal with issues of the legacy API, or need notifications for changes to the wallet, this is the RPC server to use. The gRPC server is documented here.
Requirements
Go 1.12 or newer.
Installation and updating
Windows - MSIs Available
Install the latest MSIs available here:
https://github.com/btcsuite/btcd/releases
https://github.com/btcsuite/btcwallet/releases
Windows/Linux/BSD/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 btcwallet, all dependencies, and install it:
$ cd $GOPATH/src/github.com/btcsuite/btcwallet
$ GO111MODULE=on go install -v . ./cmd/...
- btcwallet (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
Windows
Install a newer MSI
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/btcwallet
$ git pull
$ GO111MODULE=on go install -v . ./cmd/...
Getting Started
The following instructions detail how to get started with btcwallet connecting
to a localhost btcd. Commands should be run in cmd.exe
or PowerShell on
Windows, or any terminal emulator on *nix.
- Run the following command to start btcd:
btcd -u rpcuser -P rpcpass
- Run the following command to create a wallet:
btcwallet -u rpcuser -P rpcpass --create
- Run the following command to start btcwallet:
btcwallet -u rpcuser -P rpcpass
If everything appears to be working, it is recommended at this point to copy the sample btcd and btcwallet configurations and update with your RPC username and password.
PowerShell (Installed from MSI):
PS> cp "$env:ProgramFiles\Btcd Suite\Btcd\sample-btcd.conf" $env:LOCALAPPDATA\Btcd\btcd.conf
PS> cp "$env:ProgramFiles\Btcd Suite\Btcwallet\sample-btcwallet.conf" $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
PS> $editor $env:LOCALAPPDATA\Btcd\btcd.conf
PS> $editor $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
PowerShell (Installed from source):
PS> cp $env:GOPATH\src\github.com\btcsuite\btcd\sample-btcd.conf $env:LOCALAPPDATA\Btcd\btcd.conf
PS> cp $env:GOPATH\src\github.com\btcsuite\btcwallet\sample-btcwallet.conf $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
PS> $editor $env:LOCALAPPDATA\Btcd\btcd.conf
PS> $editor $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
Linux/BSD/POSIX (Installed from source):
$ cp $GOPATH/src/github.com/btcsuite/btcd/sample-btcd.conf ~/.btcd/btcd.conf
$ cp $GOPATH/src/github.com/btcsuite/btcwallet/sample-btcwallet.conf ~/.btcwallet/btcwallet.conf
$ $EDITOR ~/.btcd/btcd.conf
$ $EDITOR ~/.btcwallet/btcwallet.conf
Issue Tracker
The integrated github issue tracker is used for this project.
GPG Verification Key
All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from the btcsuite developers. To verify the signature perform the following:
-
Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt
-
Import the public key into your GPG keyring:
gpg --import GIT-GPG-KEY-conformal.txt
-
Verify the release tag with the following command where
TAG_NAME
is a placeholder for the specific tag:git tag -v TAG_NAME
License
btcwallet is licensed under the liberal ISC License.
Top Related Projects
Bitcoin Core integration/staging tree
A library for working with Bitcoin
Electrum Bitcoin Wallet
Bitcoin Wallet app for your Android device. Standalone Bitcoin node, no centralized backend required.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot