0

What's the possible workaround for passing an array of strings (not supported by solidity at current time). I am using an array of struct that is state variable to a contract.

pragma solidity ^0.4.23;
contract Person {
struct edu {
string title;
string institute;
string date;
string details;
}
edu[] public education;
constructor (string[] title, string[] institute, string[] date, string[] 
details                         
) public {
for (uint i=0; i<title.length; i++)
edu memory newEdu = edu({
title : title[i],
institute : institute[i],
date : date[i],
details : details[i]
});
}
}
0

A workaround can be to use the new abi encoder. You need to use an alternative library like ethers.js because web3 didn't support it yet.

The old school solution I've used is to past is to use a byte array with all strings concatenated, first byte is the length and follow the string data.

If you are fancy you can use RLP encoding on the byte array to support other types of data, you will be doing your own encoding/decoding.

| improve this answer | |
  • The new abi encoder is not for production right now( in beta). Would you like to share some code example with 2nd approach. 3rd approach seems promising. – mbn May 22 '18 at 8:46
  • I recently found this RLP library github.com/FourthState/plasma-mvp-rootchain/blob/master/…, you can give it a try. – Ismael May 22 '18 at 12:55
  • I have been trying hard but its not working for me its too much buggy (the Library you mentioned). :( – mbn May 25 '18 at 16:00

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.