Very well explained mate. This is one of the best videos I've come across. Is there any video on same implementation through smart contract i.e. transaction getting initiated through metamask or something or it's implementation of public/private/hybrid blockchain.
Thank you so much for this video. Well explained. Given the example you created, how can one add the Smart Contract execution to it using python. I have been looking for content on how to add Smart Contracts to a custom python based blockchain.
Sir is it possible to make a video about ways of making Privacy-enhancing of blockchain data implementation and design, or its proof of stake? it would be great to know this part of blockchain from your generous explanation.
Can you explain this in more detail when you mean privacy enhancing block chains? Block chains aren’t meant to be private persay, only secure and immutable. Blockchain like ETH and BTC have transactions available on the open web by design.
I hope blockchain evolves in the direction of benevolence. Since it has a really good shot at screwing humanity. I can already tell you if im the guy accepting or rejecting products or any high value good or service integrated with future block chain - ill be a rich man. Many Crypto. Just for me :) Even if i need to turn a blind eye once.
You are amazing man, I was looking for this for so many days.... thank you so much.
can you please share your github or code for the same video
Very well explained mate. This is one of the best videos I've come across. Is there any video on same implementation through smart contract i.e. transaction getting initiated through metamask or something or it's implementation of public/private/hybrid blockchain.
Great explanation!.. you should do a second part with smart contracts
Great suggestion
@@SATSifaction That would be awesome. Do you have the code btw? If not I might be able to type it out for others too. Thank you.
Hello from a new subscriber. Most clear explenation of blockchain.
Any link for application?
please can anyone share the github for the same code
from hashlib import sha256
import json
from datetime import datetime
class Block:
def __init__(self, index, previous_hash, current_transactions, timestamp, nonce):
self.index = index
self.previous_hash = previous_hash
self.current_transactions = current_transactions
self.timestamp = timestamp
self.nonce = nonce
self.hash = self.compute_hash()
def compute_hash(self):
block_string = json.dumps(self.__dict__, sort_keys=True)
first_hash = sha256(block_string.encode()).hexdigest()
second_hash = sha256(first_hash.encode()).hexdigest()
return second_hash
def __str__(self):
return str(self.__dict__)
class BlockChain:
def __init__(self):
self.chain = []
self.transactions = []
self.genesis_block()
def __str__(self):
return str(self.__dict__)
def genesis_block(self):
genesis_block = Block('Genesis', 0x0, [3, 4, 5, 6, 7], 'datetime.now().timestamp()', 0)
genesis_block.hash = genesis_block.compute_hash()
self.chain.append(genesis_block.hash)
self.transactions.append(str(genesis_block.__dict__))
def getLastBlock(self):
return self.chain[-1]
def proof_of_work(self, block: Block):
difficulty = 1
block.nonce = 0
computed_hash = block.compute_hash()
while not (computed_hash.endswith('0'*difficulty) and ('55'*difficulty) in computed_hash):
block.nonce += 1
computed_hash = block.compute_hash()
return computed_hash
def add(self, data):
block = Block(len(self.chain), self.chain[-1], data, 'datetime.now().timestamp()', 0)
block.hash = self.proof_of_work(block)
self.chain.append(block.hash)
self.transactions.append(block.__dict__)
return json.loads(str(block.__dict__).replace('\'', '\"'))
def getTransactions(self, id):
labels = ['Manufacturer', 'Transportation', 'Retailer']
while True:
try:
if id == 'all':
for i in range(len(self.transactions)-1):
print('{}:
{}
'.format(labels[i], self.transactions[i+1]))
break
elif type(id) == int:
print(self.transactions[id])
break
except Exception as e:
print(e)
def main():
manufacturer = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}
]
}
transportation = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 100,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 101,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}, {
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 102,
'message': 'Product damaged',
'digital signiture': 'retailer review',
'flagged': 'Y'
}
]
}
retailer = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Retailer X',
'to': 'Retail Shelf',
'receiving_id': 400,
'message': 'This product is in good order, Received',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Retailer X',
'to': 'Retail Shelf',
'receiving_id': 400,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}, {
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Retailer X',
'to': 'RTV', # Return to Vendor
'receiving_id': 401,
'message': 'Box Damaged',
'digital signiture': 'rejected',
'flagged': 'Y'
}
]
}
B = BlockChain()
a = B.add(manufacturer)
b = B.add(transportation)
c = B.add(retailer)
B.getTransactions('all')
if __name__ == '__main__':
main()
How i can get the python code? you tell too fast
from hashlib import sha256
import json
from datetime import datetime
class Block:
def __init__(self, index, previous_hash, current_transactions, timestamp, nonce):
self.index = index
self.previous_hash = previous_hash
self.current_transactions = current_transactions
self.timestamp = timestamp
self.nonce = nonce
self.hash = self.compute_hash()
def compute_hash(self):
block_string = json.dumps(self.__dict__, sort_keys=True)
first_hash = sha256(block_string.encode()).hexdigest()
second_hash = sha256(first_hash.encode()).hexdigest()
return second_hash
def __str__(self):
return str(self.__dict__)
class BlockChain:
def __init__(self):
self.chain = []
self.transactions = []
self.genesis_block()
def __str__(self):
return str(self.__dict__)
def genesis_block(self):
genesis_block = Block('Genesis', 0x0, [3, 4, 5, 6, 7], 'datetime.now().timestamp()', 0)
genesis_block.hash = genesis_block.compute_hash()
self.chain.append(genesis_block.hash)
self.transactions.append(str(genesis_block.__dict__))
def getLastBlock(self):
return self.chain[-1]
def proof_of_work(self, block: Block):
difficulty = 1
block.nonce = 0
computed_hash = block.compute_hash()
while not (computed_hash.endswith('0'*difficulty) and ('55'*difficulty) in computed_hash):
block.nonce += 1
computed_hash = block.compute_hash()
return computed_hash
def add(self, data):
block = Block(len(self.chain), self.chain[-1], data, 'datetime.now().timestamp()', 0)
block.hash = self.proof_of_work(block)
self.chain.append(block.hash)
self.transactions.append(block.__dict__)
return json.loads(str(block.__dict__).replace('\'', '\"'))
def getTransactions(self, id):
labels = ['Manufacturer', 'Transportation', 'Retailer']
while True:
try:
if id == 'all':
for i in range(len(self.transactions)-1):
print('{}:
{}
'.format(labels[i], self.transactions[i+1]))
break
elif type(id) == int:
print(self.transactions[id])
break
except Exception as e:
print(e)
def main():
manufacturer = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Manufacturer X',
'to': 'Transportation X',
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}
]
}
transportation = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 100,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 101,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}, {
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Transportation X',
'to': 'Retailer X',
'shipping_id': 102,
'message': 'Product damaged',
'digital signiture': 'retailer review',
'flagged': 'Y'
}
]
}
retailer = {
'transactions': [
{
'timestamp': datetime.now().timestamp(),
'product_id': 1,
'product_serial': 50001000,
'name': 'cotton pants',
'from': 'Retailer X',
'to': 'Retail Shelf',
'receiving_id': 400,
'message': 'This product is in good order, Received',
'digital signiture': 'approved',
'flagged': 'N'
},
{
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002000,
'name': 'cotton shirt',
'from': 'Retailer X',
'to': 'Retail Shelf',
'receiving_id': 400,
'message': 'This product is in good order',
'digital signiture': 'approved',
'flagged': 'N'
}, {
'timestamp': datetime.now().timestamp(),
'product_id': 2,
'product_serial': 50002001,
'name': 'cotton shirt',
'from': 'Retailer X',
'to': 'RTV', # Return to Vendor
'receiving_id': 401,
'message': 'Box Damaged',
'digital signiture': 'rejected',
'flagged': 'Y'
}
]
}
B = BlockChain()
a = B.add(manufacturer)
b = B.add(transportation)
c = B.add(retailer)
B.getTransactions('all')
if __name__ == '__main__':
main()
@@imranrajjad7028 it still doesn't run
please help
Thank you so much for this video. Well explained. Given the example you created, how can one add the Smart Contract execution to it using python. I have been looking for content on how to add Smart Contracts to a custom python based blockchain.
Sir is it possible to make a video about ways of making Privacy-enhancing of blockchain data implementation and design, or its proof of stake? it would be great to know this part of blockchain from your generous explanation.
Can you explain this in more detail when you mean privacy enhancing block chains? Block chains aren’t meant to be private persay, only secure and immutable. Blockchain like ETH and BTC have transactions available on the open web by design.
Thank you for this video. Very well done 👏
From Line 205 what is written?
Thanks so much for making this.
You’re welcome. Thanks for watching. Please consider subscribing if you haven’t already
The while True: in getTransactions is absolutely unnecessary
hey, this video was really helpful, thanks a lot. Could you also please link your code in the description?
hi its in the following article i wrote for the startup --> medium.com/swlh/blockchain-simplified-and-explained-79c5844e318f
@@SATSifaction is not
I hope blockchain evolves in the direction of benevolence.
Since it has a really good shot at screwing humanity.
I can already tell you if im the guy accepting or rejecting products or any high value good or service integrated with future block chain - ill be a rich man.
Many Crypto. Just for me :)
Even if i need to turn a blind eye once.