Skip to main content

Plbtc: bitcoin library for humans

Project description

Pabtc: Bitcoin Library For Humans

Pabtc is a project that aims to provide human-friendly interfaces for common btc operations. Using pabtc, you can easily and happily complete everything you want to do on btc.

Features:

  • No third-party dependencies, everything is visible.
  • Incredibly simple, even a cat knows how to use it.

Installation

$ pip install pabtc
# or
$ git clone https://github.com/mohanson/pabtc
$ cd pabtc
$ python -m pip install --editable .

Usage

By default, pabtc is configured on the develop. To switch networks, use pabtc.config.current = pabtc.config.mainnet.

example/addr.py

Calculate the address from a private key.

$ python example/addr.py --net mainnet --prikey 1

# p2pkh       1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
# p2sh-p2wpkh 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN
# p2wpkh      bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
# p2tr        bc1pmfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5sspknck9

example/message.py

Sign a message with the private key and verify it. Actually, only the public key is needed to verify the signature, but to simplify the process, this example will still ask you to provide the private key and then calculate the public key from the private key.

$ python example/message.py --prikey 1 --msg pybtc
# ICvzXjwjJVMilSGyMqwlqMTuGF6UMwddFJzVmm0Di5qNnqkBRKP8Pldm3YbOskg3ewV1tszVLy8gVX1u+qFrx6o=

$ python example/message.py --prikey 1 --msg pybtc --sig ICvzXjwjJVMilSGyMqwlqMTuGF6UMwddFJzVmm0Di5qNnqkBRKP8Pldm3YbOskg3ewV1tszVLy8gVX1u+qFrx6o=
# True

example/satoshi_nakamoto.py

Brute-forcing the private key of Satoshi Nakamoto's address.

$ python example/satoshi_nakamoto.py
# {"n": "317fcdd61ca488d52b82735e00247d16954c4b60b54346c04b57f0a0c87ce613"} 17LMG7Cy8SrYTVoVuDHh3bgBD5pt8vh6kn
# {"n": "367bed0a65a9b46dd37509978e7bf85d25a54e1d41d8f4c777e04eb0607a1f46"} 1GJLb6iM3q1DuimVPm4GiAa5QJwU8zv3h9
# ...
# {"n": "****************************************************************"} 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
# Oh my god, you did it!

example/taproot.py

This example demonstrates how to create a P2TR script with two script spending paths: p2pk and p2ms(2-of-2 multisig).

$ python example/taproot.py

example/transfer.py

Transfer Bitcoin to another account. Pybtc supports four common types of Bitcoin transactions: P2PKH, P2SH-P2WPKH, P2WPKH, and P2TR. For more complex account types, such as P2SH-P2MS, please refer to test/test_wallet.py.

$ python example/transfer.py --net develop --prikey 1 --script-type p2pkh --to mg8Jz5776UdyiYcBb9Z873NTozEiADRW5H --value 0.1

# 0x039d1b0fe969d33341a7db9ddd236f632d6851292200603abc5a6c7738bf3079

Before using this script, you first need to execute the code in the Test section. This is because pybtc requires the bitcoin core wallet to provide an account's utxo set.

Test

The testing of this project relies on regtest. You can set up the regtest node using the following steps:

$ wget https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz
$ tar -xvf bitcoin-30.2-x86_64-linux-gnu.tar.gz
$ cp -R bitcoin-30.2 ~/app/bitcoin # Install to the target location.

$ mkdir ~/.bitcoin
$ echo "chain=regtest" >> ~/.bitcoin/bitcoin.conf
$ echo "rpcpassword=pass" >> ~/.bitcoin/bitcoin.conf
$ echo "rpcuser=user" >> ~/.bitcoin/bitcoin.conf
$ echo "txindex=1" >> ~/.bitcoin/bitcoin.conf

$ bitcoind
# Create default wallets
$ python example/regtest.py
$ pytest -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pabtc-1.3.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pabtc-1.3.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file pabtc-1.3.0.tar.gz.

File metadata

  • Download URL: pabtc-1.3.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pabtc-1.3.0.tar.gz
Algorithm Hash digest
SHA256 1a43ed1e9a99691416889dd8c3d4b1bbd2e9b723c26feac7633ddf347ac8a1dc
MD5 7142c009e0d3d33211809b18705e3378
BLAKE2b-256 13b64136e39cbb81fc801e99a6163bf6e70cb61ec57b8831b33a11d5c335aac7

See more details on using hashes here.

File details

Details for the file pabtc-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pabtc-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pabtc-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee5659ec9d596c1d6e588fc40ef010285e92ea40f2e8f9b5f592c728028bc33
MD5 bfb1abda48f82deafebb75da3a2e182c
BLAKE2b-256 2dd5d6db36878acc59acec65a4056fc5cec8296a9bd587fb5a8a2c480b11e9c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page