When using hashmaps in Vyper, can we initialize it directly with more than one value?

I am currently looping over a separate list of addresses in the constructor.

allowedAdmins: HashMap[address, bool]
allowedAdminsList: address[3] = [0xADD1E55E11, 0xADD2E55E22, 0xADD3E55E33]

def __init__():
    for _admin in self.allowedAdminsList:
        self.allowedAdmins[_admin] = True

But is it possible to just initialize it in a single line if possible. Something like

allowedAdmins: HashMap[address, bool] = [(0xADD1E55E11, True),
                                         (0xADD2E55E22, True),
                                         (0xADD3E55E33, True)]

1 Answer 1


It isn't possible to initialize storage variables in vyper. In this case you can initialize in __init__() function the hashmap and when you try to deploy the smart contract for the first time this function'll initialize the hashmap with your values.

The documentation say this:

For storage variables (declared in the module scope), an initial value cannot be set

More information here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.