Regarding the fact using String in contract is expensive, is there any alternative type in Solidity ?

The input value (Payload) I want to set is as follows :

  • use events instead storing as string or bytes
    – Badr Bellaj
    May 1 '18 at 19:41
  • @BadrBellaj Bellaj Thank you. Would you explain me a bit more how to declare such this event ? ex. event MyEvent(uint256 SQN, ....); I'm wrong ?
    – Questioner
    May 1 '18 at 19:50

you can use events to store your data as it's a cheaper storage alternative.

event payload(uint256 indexed SQN, ....);

you can use an indexed variable to use it as an index to retrieve your input. in the front-end you can use get to retrieve the events or watch to catch fired ones.

  • Thank you, but how about for "Sign" field since it contains both digit and letter ? I cannot define it as uint256 Sign, Isn't it ?
    – Questioner
    May 1 '18 at 20:42
  • no it's a string, the difference here is you're using a string in an event not as a state
    – Badr Bellaj
    May 1 '18 at 20:44
  • but as I mentioned in my question i want to avoid using string since it's expensive in contract.
    – Questioner
    May 1 '18 at 20:45
  • it's expensive if used as a variable not as a parameter for event. read this post to know more media.consensys.net/… otherwise you can store data off-chain in ipfs or other systems
    – Badr Bellaj
    May 1 '18 at 20:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.