I need to set initial values for storage at deployment time using the rust sdk.
How can I derive the key for a specific storage slot?
I need to set initial values for storage at deployment time using the rust sdk.
How can I derive the key for a specific storage slot?
Hey @svimes you can the key for a specific storage slot inside your Sway project under the directory out/debug/my-contract-storage_slots.json
after you have built your project.
For example
contract;
storage {
secret_number: u64 = 777
}
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
forc build
out/debug/my-contract-storage_slots.json
you can see something like[
{
"key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed",
"value": "0000000000000309000000000000000000000000000000000000000000000000"
}
]
Hope this helps!
Thanks, I was aware of the storage_slots.json.
Unfortunately, I was looking for a way to do it programmatically.
With multiple variables sometimes spanning over multiple slots, doing this manually is messy, it also isn’t the most sustainable.
This is currently being worked on here Storage name based slots and namespaces. by esdrubal · Pull Request #6064 · FuelLabs/sway · GitHub. After it is merged and released we can plan on having a helper in the sdk.