starknet.js icon indicating copy to clipboard operation
starknet.js copied to clipboard

[Proposal] storage vars abstraction for Cairo1 contracts

Open tabaktoni opened this issue 2 years ago • 6 comments

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;

tabaktoni avatar Jun 14 '23 12:06 tabaktoni

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?

PhilippeR26 avatar Jul 06 '23 19:07 PhilippeR26

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.

tabaktoni avatar Jul 13 '23 07:07 tabaktoni

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.

PhilippeR26 avatar Jul 14 '23 19:07 PhilippeR26

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...

PhilippeR26 avatar Jul 15 '23 13:07 PhilippeR26

Hi, is there anyone working on this?

WiseMrMusa avatar Feb 19 '24 19:02 WiseMrMusa

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.

PhilippeR26 avatar Feb 19 '24 19:02 PhilippeR26