0

I am curently working on a solidity project along with a web3js client. I made this procedure in my contract, ddployed it in my testrpc and made a client request using web3js.

The problem is in the response, I expected a simple array of uint like [1,2,3] but got a strange response that even if it holds the desired response it is still not the one i needed.

here is the response :

[…]
   0: {…}
       c: Array [ 12355678 ]
       e: 7
       s: 1
   __proto__: Object { abs: another/P.abs(), absoluteValue:   another/P.abs(), ceil: another/P.ceil(), … }
   length: 1
   __proto__: Array []

here is the solidity function :

function getAllClientsOfABank(bytes32 BankName) returns(uint[]) {
    uint[] memory Clientss = new uint[](Banks[BankName].numberOfClients);

    for(uint i = 0; i < Banks[BankName].numberOfClients; i++) {
        Clientss[i]=Banks[BankName].Clients[i].cin;

    }
    return Clientss;
}

Note : cin is a uint type / Banks is a mapping of strings and BankStruct / Clients is a mapping of uint and ClientStruct

**Web3JS Client Call **

 contractInstance.getAllClientsOfABank.call('BAN556',{gas:3000000}).then(
     data => {
          console.log(data);
              }
 )
0

You get the response by pulling from c.

Unfortunately, for arrays, you have to map them together.

So if you're expecting [1, 2, 3, 4, 5], then you'd have to do something like this:

let arr = data.map(res => res.c[0])

If the array has arrays, then:

let arr = result.map(res => res.map(res => res.c[0]))

...and so forth.

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.