Open
Description
Summary
Currently, to deploy a contract with storage slots we use key/value pairs that is generated from Sway. This is very cumbersome for the end user to be able to decipher which storage they are initialising.
For example:
// ...
storage {
var1: u64 = 0,
}
// ...
const { waitForResult } = await factory.deploy({
storageSlots: [
{
"key": "fb8482ba5872da7519bf6b1d15e5deb86d892c4594c5129783b8f90858579331",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
}
]
});
Solution
We can calculate the keys for storage slots using the following computation (ref):
sha256("storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>")
This should allow us to pass in an object to the storage slots and dynamically build out the storage slots which will be passed to the contract:
const { waitForResult } = await factory.deploy({
storageSlots: {
var1: "0000000000000000000000000000000000000000000000000000000000000000"
}
});