Giter VIP home page Giter VIP logo

bitcoin-in-tiny-pieces's Introduction

bitcoin in tiny pieces

These are Python scripts made from scracth to play with Bitcoin addresses: public, private, WIF...

The scripts are compatible with Python 2 and Python 3.

before start

Install base58 for Python (tested with base58-1.0.0):

$ pip install base58

examples of use

$ ./bitcoin-public-from-private.py 0x01
	79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

# with VERBBOSE = True in bitcoin-address-from-public-key.py :
$ ./bitcoin-public-from-private.py 0x01 | ./bitcoin-address-from-public-key.py
	pubkey = 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

	Uncompressed public key:
	key_hash =      91b24bf9f5288532960ac687abb035127b1d28a5
	checksum =      0074ffe0526d823be09b39865422a1d6135afc85afb0a6863c58e9fe89989170
	key_hash + checksum =   0091b24bf9f5288532960ac687abb035127b1d28a5 0074ffe0
	bitcoin address =       1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm

	Compressed public key:
	key_hash =      751e76e8199196d454941c45d1b3a323f1433bd6
	checksum =      510d1634d943109b69da527ef5948106f22b655fb5193b4e9ef7e4dcd342d245
	key_hash + checksum =   00751e76e8199196d454941c45d1b3a323f1433bd6 510d1634
	bitcoin address =       1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

	Hybrid public key:
	key_hash =      7083929bc41c16f2337fbcd10cd73df8a4e2a2bb
	checksum =      74a0a7a97d3c7f60adceb3475880abac2231bc02b4f91753ae6dc20fcabe96ae
	key_hash + checksum =   007083929bc41c16f2337fbcd10cd73df8a4e2a2bb 74a0a7a9
	bitcoin address =       1BFvJKK757eGXdNHkXkgem4fWZU28d1cnk

$ ./bitcoin-wif-from-private-key.py 0x01
	privkey = 8001

	For compressed public key:
	checksum =      553bc06a6f4e0f4d575a9b43e2eb82546131dccec1c3a99151ee08cb5972c8a9
	key + checksum =        800101 553bc06a
	bitcoin address =       5rM1SJieKB

	For uncompressed public key:
	checksum =      e27a1d3a74fa86f9a913e996663ea76fc2333c3b77ae33ff18349a549fd36721
	key + checksum =        8001 e27a1d3a
	bitcoin address =       26k9aD1PF

$ echo 0x01 | ./bitcoin-public-from-private.py | ./bitcoin-address-from-public-key.py | xargs -I {} ./bitcoin-get-address-balance.py {}

	address         = 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm
	total_received  = 4.87126141 Bitcoin
	final_balance   = 0 Bitcoin


	address         = 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
	total_received  = 0.14609494 Bitcoin
	final_balance   = 0 Bitcoin


	address         = 1BFvJKK757eGXdNHkXkgem4fWZU28d1cnk
	total_received  = 0 Bitcoin
	final_balance   = 0 Bitcoin

# Use a SHA256 hashed string as private key, and check if it has been used:
$ ./bitcoin-test-address-balance.sh satoshi
	satoshi
	address         = 1ADJqstUMBB5zFquWg19UqZ7Zc6ePCpzLE
	total_received  = 0.00375370 Bitcoin
	final_balance   = 0 Bitcoin


	address         = 1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V
	total_received  = 0.00111100 Bitcoin
	final_balance   = 0 Bitcoin


	address         = 16uTbx4gagzvEzyeSh57SdxZNbZnTrRoks
	total_received  = 0 Bitcoin
	final_balance   = 0 Bitcoin

notes of usage

The scripts contain useful comments and links to documentation. Also contain configuration variables that can be preset:

Each script can be configured with at least the variable VERBOSE which can be True or False: if you want to concatenate scripts in command-line with |, you need to set VERBOSE = False.

bitcoin-address-from-public-key.py contains the variable COMPRESS_PUBKEY that accepts the values 0 to 3 in order to print uncompressed, compressed, hybrid, or all of the valid formats of a public bitcoin address.

bitcoin-wif-from-private-key.py contains the variable COMPRESS_PUBKEY that accepts the values 0 to 2 in order to print uncompressed, compressed, or both formats of WIF.

notes for Windows users

The folder batchs for Windows contains .bat files for ease of usage with Windows:

  • be sure you have Python in your %PATH%, or prepend the Python path to python inside each .bat

  • modify inside each .bat the complete path to the folder where you've copied all these Python scripts

  • Now usage in Windows is as easy as with Linux:

      C:\> echo 0x01 | bitcoin-public-from-private | bitcoin-address-from-public-key
          1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm
          1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
          1BFvJKK757eGXdNHkXkgem4fWZU28d1cnk
    

Please, see notes of usage above for configuring outputs and using with | concatenation.

License

Release under GPL 3.

bitcoin-in-tiny-pieces's People

Contributors

circulosmeos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitcoin-in-tiny-pieces's Issues

Results are different from blockchain.com

Hello,

I want to convert script pub key into bitcoin address.

I'm using script pub key from this transaction (tx hash) on blockchair.com: a070eda356c87a7af9bff22eab3b3c38460605eb00938c84a86a1d6d3c608078

Link:
https://blockchair.com/bitcoin/transaction/a070eda356c87a7af9bff22eab3b3c38460605eb00938c84a86a1d6d3c608078

It has next script pub key: fb2737b020d6c0555513092f7f004976c4c18c53
According to blockchair.com corresponding address is: 76a914fb2737b020d6c0555513092f7f004976c4c18c5388ac

But when I'm using bitcoin-in-tiny-pieces I have different addresses based on script pub key:

Uncompressed public key:
key_hash = 891b647d941b887ad4061cd22651d4b52682b5c8
checksum = 591f2031292a0e4144cf6c7659d87c158661b19396c890c2602ba87de71a3c7c
key_hash + checksum = 00891b647d941b887ad4061cd22651d4b52682b5c8 591f2031
bitcoin address = 1DVxPYn7t1J1U1MoLM8gCXZ17jCdPGe5je

Compressed public key:
key_hash = c02f664efb9341695f584eaa886ae27e59070c19
checksum = 7544f96a8b280ddc0301213c793831af4c6dd6994d982f3994a845dece56f0d9
key_hash + checksum = 00c02f664efb9341695f584eaa886ae27e59070c19 7544f96a
bitcoin address = 1JXBXDYofUjwV1CWLDMcY8jrJt4n3q8xaV

Hybrid public key:
key_hash = d6095f3e929ce503d6d47cb066d78b2b187e27a5
checksum = d8030cd715ccdbe308b45bbc64460aa0099dec113d96986383c1be12459d7e5e
key_hash + checksum = 00d6095f3e929ce503d6d47cb066d78b2b187e27a5 d8030cd7
bitcoin address = 1LWiqEX1PoyXHc7XMWeE2wyfMsYY8rYhHG

Non of them correspond to the address from blockchair.com. Can you please advice what am I doing wrong and why addresses from bitcoin-in-tiny-pieces are different from blockchair.com?

Private key

Hello sir
I want to convert my txt file full of private keys to addresses and balance check but it is not working. Please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.