Search code examples
javascriptsolidityweb3js

Solidity function returns empty array to web3.js


Solidity function returns a array of string while executed on Remix as well as truffle console while it returns a empty array when called from JS

Solidity code

mapping(address => string[]) addressLink;
function getLinks(address a) public view returns (string[] memory)
  {
    return addressLink[a];
  }

JS code

contract.methods.getLinks(accounts[0]).call().then(res => {
                 console.log(res)
             });

truffle console result and expected results when called from JS

[ 'QmTiMLN8X4NE4ho5mqJ9t4bJ17JxfMHAFcg3z66f8vdUh1' ]

Result on browser console(Actual result)

[""]
0: ""
length: 1

Solution

  • There was a bug in web3.js library. Which has been closed in the latest beta release