{"id":13650781,"url":"https://github.com/sr-gi/bitcoin_tools","last_synced_at":"2026-01-18T03:53:29.193Z","repository":{"id":47388548,"uuid":"74142790","full_name":"sr-gi/bitcoin_tools","owner":"sr-gi","description":"Python Bitcoin tools","archived":false,"fork":false,"pushed_at":"2022-01-30T09:47:26.000Z","size":1023,"stargazers_count":295,"open_issues_count":4,"forks_count":94,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-11-08T22:16:41.902Z","etag":null,"topics":["bitcoin","bitcoin-transaction","leveldb","python","tools","utxo"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sr-gi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-18T15:39:20.000Z","updated_at":"2024-10-24T20:30:18.000Z","dependencies_parsed_at":"2022-08-12T13:22:28.608Z","dependency_job_id":null,"html_url":"https://github.com/sr-gi/bitcoin_tools","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-gi%2Fbitcoin_tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-gi%2Fbitcoin_tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-gi%2Fbitcoin_tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-gi%2Fbitcoin_tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sr-gi","download_url":"https://codeload.github.com/sr-gi/bitcoin_tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903168,"owners_count":17222495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","bitcoin-transaction","leveldb","python","tools","utxo"],"created_at":"2024-08-02T02:00:40.933Z","updated_at":"2026-01-18T03:53:29.120Z","avatar_url":"https://github.com/sr-gi.png","language":"Python","funding_links":[],"categories":["Python Libraries","Go Tools"],"sub_categories":["E-Books"],"readme":"![bitcoin_tools](https://srgi.me/assets/images/bitcoin_tools_logo.png)\n\n[![Mentioned in Awesome](https://awesome.re/mentioned-badge.svg)](https://github.com/igorbarinov/awesome-bitcoin) \u003ca href=\"https://blockstream.info/address/1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP\"\u003e\u003cimg width=110 src=\"https://srgi.me/assets/images/beer_badge.png\"\u003e\u003c/a\u003e [![tippin.me](https://badgen.net/badge/%E2%9A%A1%EF%B8%8Ftippin.me/@sr_gi/F0918E)](https://tippin.me/@sr_gi)\n\nbitcoin_tools is a Python library created for teaching and researching purposes. It's main objective is twofold. First it \naims to ease the understanding of Bitcoin transaction creation, by using well-documented and easy to understand\npython code. Second, it aims to provide a tool able to create custom `transactions` / `scripts`. Either `scriptSig` and \n`scriptPubKey` can be built from human readable strings created using `Script` syntax. Finally, tools for accessing and \nanalysing interesting data such as the `utxo set` are also provided, along with several examples.\n\nbitcoin_tools allows you to:\n\n* Bitcoin keys creation and management.\n* Creation of Bitcoin transactions from scratch.\n* Customize any field of your transaction.\n* Transaction serialization / deserialization.\n* Creation of standard and custom scripts (`scriptSig` and `scriptPubKey`).\n* Transaction analysis from hex encoded transactions.\n\nAdditionally, bitcoin_tools contains ``STATUS`` an\n**ST**atistical **A**nalysis **T**ool for **U**txo **S**et under [`analysis/status`](bitcoin_tools/analysis/status)\n\n### Dependencies\n\nRefer to [DEPENCENCIES.md](DEPENDENCIES.md)\n\n### Installation\n\nRefer to [INSTALL.md](INSTALL.md)\n\n### Some trouble getting started with the repo?\n\nRefer to [FAQ.md](FAQ.md)\n\n### Still not working?\n\nFeel free to open an issue.\n\n### Examples\n\nDown below you can find some examples of how to use some of the library functions. More examples can be found in \n[`examples/`](examples/)\n\n#### Key management and Bitcoin address generation\n```python\nfrom bitcoin_tools.core.keys import generate_keys, store_keys\nfrom bitcoin_tools.wallet import generate_wif, generate_btc_addr\n\n# First of all the ECDSA keys are generated.\nsk, pk = generate_keys()\n# Then, the Bitcoin address is derived from the public key created above.\nbtc_addr = generate_btc_addr(pk)\n# Both the public and private key are stored in disk in pem format. The Bitcoin address is used as an identifier in the\n# name of the folder that contains both keys.\nstore_keys(sk.to_pem(), pk.to_pem(), btc_addr)\n# Finally, the private key is encoded as WIF and also stored in disk, ready to be imported in a wallet.\ngenerate_wif(btc_addr, sk)\n```\n\n#### Raw transaction building  \n```python\nfrom bitcoin_tools.core.keys import load_keys\nfrom bitcoin_tools.core.transaction import TX\n\n# Key loading\nbtc_addr = \"miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t\"\nsk, pk = load_keys(btc_addr)\n\n# Reference to the previous transaction output that will be used to redeem and spend the funds, consisting on an id and\n# an output index.\nprev_tx_id = \"7767a9eb2c8adda3ffce86c06689007a903b6f7e78dbc049ef0dbaf9eeebe075\"\nprev_out_index = 0\n\n# Amount to be spent, in Satoshis, and the fee to be deduced (should be calculated).\nvalue = 6163910\nfee = 230 * 240\n\n# Destination Bitcoin address where the value in bitcoins will be sent and locked until the owner redeems it.\ndestination_btc_addr = \"miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t\"\n\n# First, we  build our transaction from io (input/output) using the previous transaction references, the value, and the\n# destination.\ntx = TX.build_from_io(prev_tx_id, prev_out_index, value - fee, destination_btc_addr)\n# Finally, the transaction is signed using the private key associated with the Bitcoin address from each input.\n# Input 0 will be signed, since we have only created one.\ntx.sign(sk, 0)\n\n# Once created we can display the serialized transaction. Transaction is now ready to be broadcast.\nprint \"hex: \" + tx.serialize()\n\n# Finally, we can analyze each field of the transaction.\ntx.display()\n```\n#### Raw tx analysis\n\n```python\nfrom bitcoin_tools.core.transaction import TX\n\n# First a transaction object is created (through the deserialize constructor) by deserializing the hex transaction we\n# have selected.\nhex_tx = \"01000000013ca58d2f6fac36602d831ee0cf2bc80031c7472e80a322b57f614c5ce9142b71000000006b483045022100f0331d85cb7f7ec1bedc41f50c695d654489458e88aec0076fbad5d8aeda1673022009e8ca2dda1d6a16bfd7133b0008720145dacccb35c0d5c9fc567e52f26ca5f7012103a164209a7c23227fcd6a71c51efc5b6eb25407f4faf06890f57908425255e42bffffffff0241a20000000000001976a914e44839239ab36f5bc67b2079de00ecf587233ebe88ac74630000000000001976a914dc7016484646168d99e49f907c86c271299441c088ac00000000\"\ntx = TX.deserialize(hex_tx)\n\n# Then, the transaction can be displayed using the display method to analyze how it's been constructed.\ntx.display()\n``` \n\n#### Using STATUS to dump the UTXOs LevelDB\n```python\nfrom bitcoin_tools.analysis.status.data_dump import utxo_dump\nfrom bitcoin_tools.analysis.status.utils import parse_ldb\n\n# Set the version of the Bitcoin Core you are using (which defines the chainstate format)\n# and the IO files.\n\nf_utxos = \"decoded_utxos.txt\"\nf_parsed_utxos = \"parsed_utxos.txt\"\n\n# Set the coin we're working with\ncoin = 'bitcoin'\n\n# Parse all the data in the chainstate.\nparse_ldb(f_utxos)\n# Parses transactions and utxos from the dumped data.\nutxo_dump(f_utxos, f_parsed_utxos, coin)\n\n# Data is stored in f_utxos and f_parsed_utxos files respectively\n```\n\n### Support\n\nIf you find this repository useful, show us some love, give us a star!\n\nSmall Bitcoin donations to the following address are also welcome:\n\n[1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP](https://blockstream.info/address/1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP)\n\n### Disclaimer\n\nThis library allow you to modify any transaction field as you pleased. However, some modifications can make your \ntransactions non-standard, or even non-spendable. We totally discourage the  use of the library outside the testnet if \nyou are not sure about what you are doing, specially when dealing with non-standard scripts. A bad use of the library \ncan lead you to lose some of your bitcoins.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsr-gi%2Fbitcoin_tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsr-gi%2Fbitcoin_tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsr-gi%2Fbitcoin_tools/lists"}