Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DX for storage slots deployment #3060

Open
petertonysmith94 opened this issue Aug 29, 2024 · 0 comments
Open

Improve DX for storage slots deployment #3060

petertonysmith94 opened this issue Aug 29, 2024 · 0 comments
Labels
feat Issue is a feature

Comments

@petertonysmith94
Copy link
Contributor

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"
  }
});
@petertonysmith94 petertonysmith94 added the feat Issue is a feature label Aug 29, 2024
@arboleya arboleya added the temp:notion label Sep 8, 2024 — with Linear
@arboleya arboleya added the temp-linear label Sep 8, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

No branches or pull requests

2 participants