How to create a Cryptocurrency with Python #1

in #utopian-io6 years ago (edited)

What Will I Learn?

  • How to Build a Blockchain with Python
  • Creating Blocks to SignTransactions
  • Adding Transactions to a Block

Requirements

  • A Laptop or Desktop Computer (Windows, Linux or Mac)
  • Simple Python Knowledge
  • Python 3.6
  • Django

Difficulty

  • Intermediate

Tutorial Contents

Project Structure
asdasd

Building a Blockchain

First, create a django model for Blokchain transactions.

What does the model mean?

A model is a single source of information about your data. It contains the basic areas and behaviors of the data you store.
In short, models are a structure for the information you need.

What variables do we need?

Sender = Information on who is the person performing the transaction.

Receiver = Person who has reached the transaction.

Previous blockhash = Previous blockhash result.

Blockhash = Current blockhash result.

Amount = Balance

Nonce = Number of attempts to find the key word specified in the miner algorithm.

Timestamp = Means a record that is stamped with an electronic signature by an electronic certificate service provider so that the time at which an electronic data is generated, modified, sent, received, and / or saved is identified.

First/Saved timestamp = Start and end timestamp.

P2PKH = Payment address comprising a hashed public key, allowing the spender to create a standard pubkey script that Pays To PubKey Hash (P2PKH).

 class transaction(models.Model):
    sender = models.CharField(max_length=5000,null=False) 
    senderhexdigest = models.CharField(max_length=5000,null=False) #Sender's Digest
    receiver = models.CharField(max_length=5000,null=False) 
    receiverhexdigest = models.CharField(max_length=5000,null=False) #Receivers's Digest
    prevblockhash = models.CharField(max_length=5000,null=False)
    blockhash = models.CharField(max_length=5000,null=False)
    amount = models.IntegerField(null=False)
    nonce = models.IntegerField(null=False)
    first_timestamp = models.IntegerField(null=False)
    saved_timestamp = models.DateTimeField(auto_now_add=True)
    P2PKH = models.CharField(max_length=5000,null=True)
    

Creating a Wallet

We need wallets where we can keep our values. We need to talk about Public and Private Key.

Public key:
The public key uses asymmetric algorithms that transform messages into an unreadable format.
A person with a common key can encrypt the message for a particular recipient. The private key
recipient can only decrypt the message encrypted by the public key. The key can be accessed through the public directory.

Private key:
The private key is a secret key used to decrypt the message, and the party knows the change message.
In the conventional method, a secret key is shared in the communicators to enable encryption and decryption,
but if the key is lost, the system becomes invalid. To prevent this weakness, the PKI (public key infrastructure)
in which a public key is used together with the private key has entered into force. The PKI allows internet users
to exchange information securely using a public and private key.

RSA key:
It is an asymmetric encryption algorithm. Instead of using a single key as in symmetric encryption,
two keys are used, one being a private key and the other being a public key.

def instantwallet():
    new_key = RSA.generate(1024, Random.new().read)
    public_key = new_key.publickey().exportKey("PEM")
    private_key = new_key.exportKey("PEM")
    keys = []
    wallet_id = SHA256.new(public_key).hexdigest()
    keys.append(private_key)
    keys.append(public_key)
    keys.append(wallet_id)
    private_key = keys[0]
    public_key = keys[1]

    # print(private_key)
    # print("-*-*-*-*-*-*-*-*-**-*-----------*-*-*-*-*-*-*-*-*-*")
    # print(public_key)
    # print("-*-*-*-*-*-*-*-*-**-*-----------*-*-*-*-*-*-*-*-*-*")
    # print(wallet_id)
    return keys

Github

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • Too short.
  • A tutorial needs to be more complete and with more information to be easy for users to learn.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Shorter posts were accepted. The subject can be considered difficult already. I left it like this so that it does not get any more complicated. @portugalcoin

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.029
BTC 61657.19
ETH 3452.67
USDT 1.00
SBD 2.52