1

I have a structure data with double mapping for storing and fetching details. Here is the code :

struct data {
    uint a;
    uint b;
}
mapping(address => mapping(bytes11 => data[])) testidmapping;

Used storevalues() function to store and getvalues() to fetch the values

function storevalues(address owner,bytes11 id,uint a,uint b) public{
testidmapping[owner][id].push(data(a,b));
}

function getvalues(address owner,bytes11 id) view returns (uint a){
  data storage k = testidmapping[owner][id];
  return (k.a);

}

Is this the possible way of double mapping for fetching and storing details? But I am getting this error:

BigNumber() is not a number: (id is printing)

Help will be appreciated...

4
  • 1
    The error that you're describing sounds like an off-chain error (e.g., Javascript), but there is no off-chain code in your question. Commented Sep 25, 2018 at 13:31
  • Also, what is data(a,b) in function storevalues? Variables a and b are not defined anywhere! Commented Sep 25, 2018 at 13:32
  • Thank You...I just edited the code, passing the a and b values from javascript. Basically I don't know how to fetching the values from double mapping from a structure?
    – lekshmi
    Commented Sep 25, 2018 at 13:35
  • You did not refer to my first comment though. Commented Sep 25, 2018 at 13:51

1 Answer 1

2

As you intended to access an attribute of an arraydata[] you shall provide an index. You might also need a length of an array data so that you can write a loop in backend code to retrieve all the a's stored in an array data.

Refer the following function -

function getValuesAtIndex(address owner,bytes11 id,uint dataindex) view returns (uint a){

  return (testidmapping[owner][id][dataindex].a);

}

function getDataLength(address owner,bytes11 id)view returns(uint){

  return (testidmapping[owner][id].length);    
}

Hope it helps! Let me know if any further clarification is required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.