starknet.js
starknet.js copied to clipboard
[Proposal] storage vars abstraction for Cairo1 contracts
How to retrieve storage for complex data types: Complex mapping - https://docs.starknet.io/documentation/architecture_and_concepts/Contracts/contract-storage/
After resolving this, we could implement class for retreating complex storage vars, by using ABI, and than on top of that implement it in Contract vars so that one can do:
// simple - can be implemented now
mycontract.status;
mycontract.balance;
// complex - need to decode retreaving part, create request from ABI structure
mycontract.users[0].name;
To calculate the storage addresses, we need the name of the elements in the storage, and their types. Can we find these data in .sierra or in .casm?
They are indirectly specified if used in methods. (We can check with SW about extending ABI) But even if they are not part of the ABI, we can presume the user knows the storage vars and build queries for him.
I made some tests : it works for litterals (including u256), legacyMap, structs, if the user provides the name of the element. Array and enums not supported in Storage (cairo v2.0.0). Remain one major problem : how the user will provide to Starknet.js the way to deserialize complex elements? It could be a type that is not described in the abi.
I think that we can have :
const content:AllowArray<string>=await myContract.getStorage(varName,nbFeltToRead);
nbFeltToRead is optional.
Then the user has to deserialize the output.
I think it will be difficult to have something more refined...
Hi, is there anyone working on this?
Hi, is there anyone working on this?
Hello, I have started to work on it, but it has not been yet decided the exact scope of this job.