I made a simple Bitcoin wallet with pycoin

Overview

It is a GUI application that implements the basic functions of the Bitcoin wallet. It is also possible to actually exchange bitcoins with this app. (We can't guarantee the operation, so we don't recommend it. If you do, it's a small amount ...)

code

https://github.com/momosuke4989/pycoin-demo

Reason for making

A library called pycoin was introduced in Mastering Bitcoin, which is a bitcoin bible, so I created it after studying python and bitcoin. At the Open Source Conference 2016 Tokyo / Fall, I was demonstrating with a Raspberry Pi with a 3.2 inch LCD. This is why the window size specification is strangely small.

How to use

See README key-generate.py is for Bitcoin address generation and create-tx.py is for transaction generation.

Commentary

What is a Bitcoin wallet in the first place?

An app for general users to manage Bitcoin is called a wallet. The main functions are the storage and sending / receiving of Bitcoin, which consists of the following elements.

Private key and address

In the world of Bitcoin, users are identified by the unit of private key and Bitcoin address (hereinafter referred to as the address). If you replace it with the world of banks, the private key is a PIN and the address is an account number. Public key cryptography (or elliptic curve cryptography to be exact) and hash functions are used to generate addresses, but interestingly, no organization or entity controls this task. Since the range of values that the private key can take is large enough (10 ^ 77), it is practically safe to ignore the possibility of address collision. For this reason, it is commonplace in the Bitcoin world to have multiple addresses by one person, and it is said that it is desirable to generate an address for each transaction from the viewpoint of security, but the private key and address each time. It's a lot of work to generate, and it's also complicated to manage.

Hierarchical Deterministic Wallet A mechanism called Hierarchical Deterministic Wallet, commonly known as HD wallet, was proposed to solve this problem. The HD wallet is very convenient because you can generate multiple private keys / addresses hierarchically from one master key, and if you have the master key, you can also get the balance of all the addresses under the hierarchy.

Although the introduction has become quite long, key-generate.py is an application that generates a private key and address based on this mechanism.

Transactions and digital signatures

To send Bitcoin to someone, the transfer information must be sent to the Bitcoin network in the form of a transaction and approved. However, in the world of Bitcoin, all the information about which address has and how much is open to the public, so it is easy to create a transaction such as sending money from another person's address in red to yourself. It would be irresistible if something like this was approved. In order to prevent such a situation, it is necessary to prevent Bitcoin from being moved unless it is a legitimate owner, but here is an electronic signature with a private key. Bitcoin takes advantage of the characteristics of public key cryptography and applies digital signatures to prove ownership. The private key is treated as WIF (Wallet Import Format) format. There is also a compressed WIF format, but details are omitted. (By the way, the above app uses compressed WIF format)

create-tx.py is an application that creates a signed transaction and sends it to the network.

Miscellaneous feelings

When I actually made something that works like this, I learned sensuously that the private key and address can be managed separately. Since the app I made this time was not supposed to be released in this way, I think that the license is not specified and there are various points of interest. (Can I add or change it later?) If you have any advice, such as something strange here or something like this, please comment.

reference

Mastering Bitcoin national translation PDF storage https://www.bitcoinbook.info/translations-of-mastering-bitcoin/

pycoin github repository https://github.com/richardkiss/pycoin

Recommended Posts

I made a simple Bitcoin wallet with pycoin
I made a simple blackjack with Python
I made a daemon with Python
I made a simple typing game with tkinter in Python
I made a simple book application with python + Flask ~ Introduction ~
A simple RSS reader made with Django
I made a character counter with Python
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a roguelike game with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I made a simple circuit with Python (AND, OR, NOR, etc.)
[Python] I made an image viewer with a simple sorting function.
I made a stamp substitute bot with line
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
〇✕ I made a game
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a LINE Bot with Serverless Framework!
I made a random number graph with Numpy
I made a simple RSS reader ~ C edition ~
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a QR code image with CuteR
[AWS] I made a reminder BOT with LINE WORKS
I made a Twitter BOT with GAE (python) (with a reference)
I made a household account book bot with LINE Bot
I made a ready-to-use syslog server with Play with Docker
I made a vim learning game "PacVim" with Go
I made a window for Log output with Tkinter
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I tried a simple RPA for login with selenium
I made a falling block game with Sense HAT
I made blackjack with python!
I made a python text
I made a discord bot
I made COVID19_simulator with JupyterLab
I made Word2Vec with Pytorch
I made blackjack with Python.
I made wordcloud with Python.
A story that stumbled when I made a chatbot with Transformer
I made a LINE BOT that returns parrots with Go
A simple interactive music player made with Chuck and OpenPose
I made a package to filter time series with python
I made a resource monitor for Raspberry Pi with a spreadsheet
I made a puzzle game (like) with Tkinter in Python
I made a rigid Pomodoro timer that works with CUI
I made a surveillance camera with my first Raspberry PI.
I made a plug-in that can "Daruma-san fell" with Minecraft
[AWS] I made a reminder BOT with LINE WORKS (implementation)
I made a C ++ learning site
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a wikipedia gacha bot