How would i fix this error in creating a genesis block

Question:

Traceback (most recent call last):
  File "C:UsersRACcrypto...blockchain.py", line 178, in <module>
    blockchain = Blockchain()
                 ^^^^^^^^^^^^
  File "C:UsersRACcrypto...blockchain.py", line 49, in __init__       
    self.chain = [self.create_genesis_block(0)]
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Blockchain.create_genesis_block() takes 1 positional argument but 2 were given

with code looking like this

class Blockchain:
    def __init__(self):
        self.chain = [self.create_genesis_block(0)]
        self.difficulty = 4
        self.nodes = dict()
        self.replicated_nodes = dict()
        self.coin_ledger = dict()

    def create_genesis_block(self):
        return Block("Genesis Block", "0", coin)

ive tried adding other arguments but as i am new to this, i havent been able to figure it out myself properly

Asked By: jreyes2563

||

Answers:

when you use the self constructor, you need to initialize the class, try

instanse = Blockchain()
instanse.create_genesis_block()
Answered By: Roberto Espiritu

def create_genesis_block(self): doesn’t take a parameter, maybe you meant:

def create_genesis_block(self, block_num):
        return Block("Genesis Block", block_num, coin)

or

@staticmethod 
def create_genesis_block(block_num):
        return Block("Genesis Block", block_num, coin)
Answered By: Marc Ritterbusch
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.