I am trying to integrate for loop in my smartcontract for adding details to a struct.

I have implemented for loop using frontend by calling the function in smartcontract one by one.

 struct details {
    string[] value;
mapping (uint=>details) Details;
function add(uint id,string valuetosubmit){

As I have mentioned,I am calling the function add one by one inside a for loop.

I have to move the for loop inside the smart contract.How can it be implemented? Any samples for reference? Which is the best method to follow? What will be difference in Gas Consumption?

  • Do you really need the dynamically-sized string type? This would be much easier if you expose some sort of limit on the string length, for example 32 characters. Then you could use a bytes32[] in your new function. – Jesbus Oct 5 '17 at 7:51
  • @JesseBusman I have to use dynamic string... – Christa Oct 5 '17 at 10:25

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.