0

I'm currently writing a smart contract that is supposed to store some data for an address, more or less in the form of an "attribute" as implemented in EiP-1056. Contrary to EiP-1056 very flexible attribute mapping, I want/need a specific set of attributes to be set. Let's assume it is an attribute "a" of type "string" and an attribute "b" of type uint8.

I don`t want to allow only one to be set or none to be set. And I only want to retrieve them together using ONE function. Question is how to store them. I see the following options:

  1. Create a mapping for each, i.e. mapping (address => string) a; and mapping (address => uint8) b; and have a retrieval function, such as function x(address i) returns(string, uint8) {}. Advantage: types are automatically checked. Disadvantage: Possibly more overhead in the smart contract (?)

  2. Store a plain serialized JSONObject containing both values, e.g. {"a":"xxx","b":5}. Advantage: plain and simple. Disadvantage: No control of the contents of the object.

  3. Put everything in a Struct, e.g. struct data{string a; uint8 b;}. Advantage: Clear structure of data. Disadvantage: Cannot be returned in one piece.

What would be the preferred way to go here? Any other options that might be useful here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.