Dynamic array in Solidity












1















I a very new to Ethereum and Solidity development.



I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.



I search a lot but not able to find this simple stuff.



Thanks in advance










share|improve this question





























    1















    I a very new to Ethereum and Solidity development.



    I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.



    I search a lot but not able to find this simple stuff.



    Thanks in advance










    share|improve this question



























      1












      1








      1


      1






      I a very new to Ethereum and Solidity development.



      I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.



      I search a lot but not able to find this simple stuff.



      Thanks in advance










      share|improve this question
















      I a very new to Ethereum and Solidity development.



      I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array.



      I search a lot but not able to find this simple stuff.



      Thanks in advance







      ethereum solidity






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 31 '18 at 10:07









      saman.shahmohamadi

      374218




      374218










      asked Dec 31 '18 at 9:42









      Jay VyasJay Vyas

      1,60131638




      1,60131638
























          2 Answers
          2






          active

          oldest

          votes


















          3














          Here is my solution, you need experimental ABIEncoderV2 to return array of strings.



          pragma solidity ^0.5.2;
          pragma experimental ABIEncoderV2;

          contract Test {

          string array;

          function push(string calldata _text) external {
          array.push(_text);
          }

          function get() external view returns(string memory) {
          return array;
          }
          }





          share|improve this answer
























          • Can I test it before deploy ?

            – Jay Vyas
            Dec 31 '18 at 10:04











          • sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

            – Egor
            Dec 31 '18 at 10:08













          • Wow, amazing solution Accepted Thanks

            – Jay Vyas
            Dec 31 '18 at 10:10













          • Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

            – Egor
            Dec 31 '18 at 10:12













          • Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

            – Jay Vyas
            Dec 31 '18 at 10:46



















          2














          If, finally, you want to interact with your smart contract with tools like web3j (for java) or web3js (javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.

          In this case you should serialize your output array. Same applies if you have an input array.






          share|improve this answer


























          • such a good point

            – Egor
            Dec 31 '18 at 10:20











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985923%2fdynamic-array-in-solidity%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Here is my solution, you need experimental ABIEncoderV2 to return array of strings.



          pragma solidity ^0.5.2;
          pragma experimental ABIEncoderV2;

          contract Test {

          string array;

          function push(string calldata _text) external {
          array.push(_text);
          }

          function get() external view returns(string memory) {
          return array;
          }
          }





          share|improve this answer
























          • Can I test it before deploy ?

            – Jay Vyas
            Dec 31 '18 at 10:04











          • sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

            – Egor
            Dec 31 '18 at 10:08













          • Wow, amazing solution Accepted Thanks

            – Jay Vyas
            Dec 31 '18 at 10:10













          • Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

            – Egor
            Dec 31 '18 at 10:12













          • Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

            – Jay Vyas
            Dec 31 '18 at 10:46
















          3














          Here is my solution, you need experimental ABIEncoderV2 to return array of strings.



          pragma solidity ^0.5.2;
          pragma experimental ABIEncoderV2;

          contract Test {

          string array;

          function push(string calldata _text) external {
          array.push(_text);
          }

          function get() external view returns(string memory) {
          return array;
          }
          }





          share|improve this answer
























          • Can I test it before deploy ?

            – Jay Vyas
            Dec 31 '18 at 10:04











          • sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

            – Egor
            Dec 31 '18 at 10:08













          • Wow, amazing solution Accepted Thanks

            – Jay Vyas
            Dec 31 '18 at 10:10













          • Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

            – Egor
            Dec 31 '18 at 10:12













          • Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

            – Jay Vyas
            Dec 31 '18 at 10:46














          3












          3








          3







          Here is my solution, you need experimental ABIEncoderV2 to return array of strings.



          pragma solidity ^0.5.2;
          pragma experimental ABIEncoderV2;

          contract Test {

          string array;

          function push(string calldata _text) external {
          array.push(_text);
          }

          function get() external view returns(string memory) {
          return array;
          }
          }





          share|improve this answer













          Here is my solution, you need experimental ABIEncoderV2 to return array of strings.



          pragma solidity ^0.5.2;
          pragma experimental ABIEncoderV2;

          contract Test {

          string array;

          function push(string calldata _text) external {
          array.push(_text);
          }

          function get() external view returns(string memory) {
          return array;
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 31 '18 at 9:54









          EgorEgor

          598114




          598114













          • Can I test it before deploy ?

            – Jay Vyas
            Dec 31 '18 at 10:04











          • sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

            – Egor
            Dec 31 '18 at 10:08













          • Wow, amazing solution Accepted Thanks

            – Jay Vyas
            Dec 31 '18 at 10:10













          • Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

            – Egor
            Dec 31 '18 at 10:12













          • Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

            – Jay Vyas
            Dec 31 '18 at 10:46



















          • Can I test it before deploy ?

            – Jay Vyas
            Dec 31 '18 at 10:04











          • sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

            – Egor
            Dec 31 '18 at 10:08













          • Wow, amazing solution Accepted Thanks

            – Jay Vyas
            Dec 31 '18 at 10:10













          • Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

            – Egor
            Dec 31 '18 at 10:12













          • Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

            – Jay Vyas
            Dec 31 '18 at 10:46

















          Can I test it before deploy ?

          – Jay Vyas
          Dec 31 '18 at 10:04





          Can I test it before deploy ?

          – Jay Vyas
          Dec 31 '18 at 10:04













          sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

          – Egor
          Dec 31 '18 at 10:08







          sure, go to remix.ethereum.org, in Run tab choose Environment JavaScript VM and deploy for testing

          – Egor
          Dec 31 '18 at 10:08















          Wow, amazing solution Accepted Thanks

          – Jay Vyas
          Dec 31 '18 at 10:10







          Wow, amazing solution Accepted Thanks

          – Jay Vyas
          Dec 31 '18 at 10:10















          Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

          – Egor
          Dec 31 '18 at 10:12







          Also when you will push string in array in Remix IDE, make sure that you have quotes like "yourString"

          – Egor
          Dec 31 '18 at 10:12















          Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

          – Jay Vyas
          Dec 31 '18 at 10:46





          Warning: Experimental features are turned on. Do not use experimental features on live deployments. pragma experimental ABIEncoderV2; I am getting this error while compiling the Smart Contract

          – Jay Vyas
          Dec 31 '18 at 10:46













          2














          If, finally, you want to interact with your smart contract with tools like web3j (for java) or web3js (javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.

          In this case you should serialize your output array. Same applies if you have an input array.






          share|improve this answer


























          • such a good point

            – Egor
            Dec 31 '18 at 10:20
















          2














          If, finally, you want to interact with your smart contract with tools like web3j (for java) or web3js (javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.

          In this case you should serialize your output array. Same applies if you have an input array.






          share|improve this answer


























          • such a good point

            – Egor
            Dec 31 '18 at 10:20














          2












          2








          2







          If, finally, you want to interact with your smart contract with tools like web3j (for java) or web3js (javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.

          In this case you should serialize your output array. Same applies if you have an input array.






          share|improve this answer















          If, finally, you want to interact with your smart contract with tools like web3j (for java) or web3js (javascript) in an application, working with dynamic arrays is not going to work because of some bugs in those libraries.

          In this case you should serialize your output array. Same applies if you have an input array.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 6 at 6:20

























          answered Dec 31 '18 at 10:18









          saman.shahmohamadisaman.shahmohamadi

          374218




          374218













          • such a good point

            – Egor
            Dec 31 '18 at 10:20



















          • such a good point

            – Egor
            Dec 31 '18 at 10:20

















          such a good point

          – Egor
          Dec 31 '18 at 10:20





          such a good point

          – Egor
          Dec 31 '18 at 10:20


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985923%2fdynamic-array-in-solidity%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas