I am stuck on this little problem in my chat app smart contract(this is only the faulty piece of code)
contract ChatApp {
struct user{
bool acceptReq;
uint nreq;
address[] requests;
address[] friends;
}
mapping(address => user) _users;
function sendreq(address friend) public returns(string memory){
//_users[friend].requests[_users[friend].nreq]=msg.sender;
_users[friend].requests[0]=msg.sender;
return "this function has been executed properly";
}
}
The problem that I'm facing is that when I execute the function sendreq()
, the IDE throws this error
VM error: invalid opcode. invalid opcode
I think that the problem is somewhere in the mapping but I can't find it. Can you guys help me?