TL;DR This GitHub repository is all you need.
Solidity is still in development and that’s why it still lacks in a lot of features that a good programming language should have. One of the features which solidity is missing is that it cannot return or take multi-dimensional arrays as input. Well, that does not seem important but when we talk about strings, we realize that they are just arbitrary-length byte array(i.e.
byte). So when you create a string array, you are creating a two-dimensional byte array(i.e.
byte). This is where we all get stuck. Kinda like a trap…
That’s enough of talking, let’s get to work. The easiest and the most efficient way to get over this problem is to serialize the strings in the array(converting the strings in the array into byte form) and send all of them in one go. After we receive the string array in the byte form we can either pass the byte array as input to another solidity function or send it to user-end(node.js api) where we will de-serialize it back to the string array. Let’s see how it works.
Step 1: Serialize & De-serialize using solidity
You will get some output like this (for
Now, pass this bytes buffer into
getString()and you will get your strings back!
Putting the above byte output in the js function we get the following output.
Voila, you successfully got your array back!
This was just about the strings. You can do a lot of stuff using Seriality.
Learned something? Click the 👏 to say “thanks!” and help others find this article.
Hold down the clap button if you liked the content! It helps me gain exposure .
Want to learn more? Checkout my previous articles.
Experts are suggesting quantum computing may render blockchain obsolete. As the tech giants such as Google and IBM are…hackernoon.com
The only blockchain which has blocktime of less than a second: 0.5 sec!hackernoon.com
A complete comparison of the two scaling methods.hackernoon.com
IPFS Private Storage Network Seriesmedium.com
The whole world is going through the blockchain revolution. But wait…is this really what we dreamed of? Present…medium.com