Initialize big map

The following question has been asked on Telegram:

Hello I would like to ask how to initialize the content of a big_map in the new version of syntax.
For example, in the previous version, I wrote something like this.

addresses = sp.big_map(
        tkey = sp.TString,
        tvalue = sp.TAddress,
        l = {
           sp.string("admin"): ADMIN,
           sp.string("point"): POINT_SYSTEM
      }
)

You can initialize a big map and set its type this way:

addresses = sp.cast(sp.big_map({
    "admin": ADMIN,
    "point": POINT_SYSTEM,
}), sp.big_map[sp.string, sp.address])

If you simply want to initialize, the inference system will infer the type:

addresses = sp.big_map({
    "admin": ADMIN,
    "point": POINT_SYSTEM,
})

If you simply want to set the type with an empty big map.

addresses = sp.cast(sp.big_map(), sp.big_map[sp.string, sp.address])

Notice: sp.string("...") doesn’t exist anymore, a string is created with "..."

1 Like