&[u8]
).deps.storage
, and the examples below show how to save/load data to/from there with a storage key.&[u8]
suffices. People often prefer generating these keys from strings as shown in the example below.state.rs
, and then imported to contract.rs
. However, since storage keys are just constants, they could be declared anywhere in the contract.state.rs
of most secret contract templates.value
can be of any Struct type. The only condition is that this Struct must derive the Serialize and Deserialize traits from serde with the following line above its Struct declaration.may_load()
which wraps any data inside within an option. Returning None
if there is no value saved with that key, and returning Some(value)
if there is some value saved. An example function for this is:secret-toolkit
) to serde the data being saved/read on the smart contract. However, bincode2 uses floats when deserializing rust enum variants, thus, bincode2 cannot serde enum variants in cosmwasm. This is why cosmwasm uses Json serde by default, not bincode2.secret-toolkit
to serde structs that use enums. This also creates the need for for new wrapper functionsmay_load
wrapper function we discussed above.