Author

Topic: Tutorial made simple blockchain on Cloud (Read 87 times)

legendary
Activity: 1666
Merit: 1037
October 23, 2024, 07:18:49 AM
#3
Stumbled on this thread after the satoshi troll, will be throwing merit at you the day I get some more OP but don't hold your breathe Lips sealed You deserve it though.

What can you actually use this for, a really simple database? Does it have the code for peer to peer sharing? Thank you.

I don't think it's intended for practical use-case, I suppose that it's more about the educational value of being able to replicate how a blockchain works on your own cloud server.
newbie
Activity: 16
Merit: 0
October 16, 2024, 02:54:02 PM
#2
What can you actually use this for, a really simple database? Does it have the code for peer to peer sharing? Thank you.
full member
Activity: 247
Merit: 124
dON'T tRUST, vERIFY!
October 16, 2024, 03:21:46 AM
#1
Blockchain is decentralized technology system that records transactions and securely cryptographi. Each block contains a number of transactions that are verified and validated by a peer-to-peer network.

Blockchain technology in the cloud is refers to the use of blockchain technologi in a cloud computing environment. It enable distributed storage and process data of blockchain via a cloud infrastructure, providing advantages in terms of security, transparency, and scalability.

By using the cloud, access to blockchain nodes can be expand globally, while the distributed cloud infrastructure provides resilience to local system failures.

You have to write simple code blockchain on visual studio code or notepad 1st like code below:

Code:
import json
from datetime import datetime

from hashlib import sha256
class Blockchain(object):
    def _init__(self):
         self.chain = []
         self.chain.append(self.new_block())

    def new_block(self):
         block = {
                'timestamp' datetime.now().isoformat(),
                'prev_hash': self.chain [-1]["hash"] if len(self.chain)>0 else None,
                'nonce': len(self.chain)
          }
          block["hash"]=sha256(json.dumps(block).encode()).hexdigest()
          return block

    def proof_of_work(self):
        while True:
             new_block = self.new_block()
             if new_block["hash"].startswith("0000"):
                 break
        self.chain.append(new_block)

    def get_block_count(self):
         return len(self.chain)

Code:
bc = Blockchain()
bc.proof_of_work()

Then login SSH like below



After login, create a new folder then enter to that new folder. Then create blockchain.py file using nano editor teks then paste code that was create before and save it.

Code:
root@not-3:-# mkdir notyourkeynotyourbtc
root@not-3:-# cd notyourkeynotyourbtc/
root@not-3:-/notyourkeynotyourbtc# nano blockchain.py

If want to show json data use the following command:
Code:
print(json.dumps(bc.chain, indent=4))

If want to show blockchain data use the following command:
Code:
print("amount of blochcain data", bc.get_block_count())

you can run blockchain.py after success created it. Output file you got from json data and amount data from blockchain

Code:
root@not-3:~/notyourkeynotyourbtc# python3 blockchain.py
[
    {
         "timestamp": "2024-10-15T19:35:43.065206",
         "prev_hash": null,
         "nonce": 0,
         "hash":
         "0efaec636d1c6a553d8139c82f40677249715a03a43ea93ed2081belbfc4e804"
     },
     {
         "timestamp": "2024-10-15T19:35:43.089915",
         "prev_hash":
         "0efaec636d1c6a553d8139c82f40677249715a03a43ea93ed2081belbfc4e804",
         "nonce": 1,
         "hash": "00008e23dadfaa45e2e4e20b4eccaaaleab091b9060875ce32a33def4a0a9292"
     }
Number of data on the blockchain: 2
root@not-3:~/notyourkeynotyourbtc#

Just simple like that
Jump to: