Block() takes no argument

class Block:

def init(self, previous_hash, transaction):

self.transactions = transaction

self.previous_hash = previous_hash

string_to_hash = "".join(transaction) + previous_hash

self.block_hash = hashlib.sha256(string_to_hash.encode()).hexdigest()

blockchain =

genesis_block = Block(“Blockchain is Amazing…”, [“X sent 1 BTC to Y”,

                                                 "X sent 2 BTC to Y",

                                                 "X sent 3 BTC to Y",

                                                 "X sent 4 BTC to Y"])

print(genesis_block.block_hash)


TypeError Traceback (most recent call last)
in ()
4 “X sent 2 BTC to Y”,
5 “X sent 3 BTC to Y”,
----> 6 “X sent 4 BTC to Y”])
7
8

TypeError: Block() takes no arguments

Surround the def for __init__ with two underscores, not one.

Thanks now it is showing

NameError Traceback (most recent call last)
in ()
1 blockchain =
2
----> 3 genesis_block = Block(“Blockchain is Amazing…”, [“X sent 1 BTC to Y”,
4 “Y sent 2 BTC to X”])
5

NameError: name ‘Block’ is not defined

You have written it with the following indentation?

>>> class Block():
...     def __init__(self, level):
...         self.level = level
...     rooted = Block(1)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in Block
NameError: name 'Block' is not defined

The issue is caused because creating what I call “rooted” is indented and therefore part of the Block definition. During the definition, the name is not yet available for use.

Indentation is important, make sure you show it when asking a question like this.