Normal function showing error asking to make it Payable

Below is the prograame in solidity I wrote which assigns value to elements of an array.

pragma solidity 0.8.16 ;
 contract arr
      uint i = 0 ;
     people[] public person ;

     struct people
         uint256 num ;
         string name ;

     function plus(string memory naam , uint256 nu) public
       person[i].num = nu ;
       person[i].name = naam ;
        i++ ;


Instead of push function I want to put values like this . While compilation and deploying no error comes however when I call this function then this error shows :-

It reads:-

The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.

I want to know what I am doing wrong , and why is it asking me to make the function payable.

Thank You

Make sure you are not passing any wei on remix settings

This error occurs when you are transferring an amount/value with your request but your function is not payable.
To prevent the error you should not send any wei/eth/bnb with your request. As you did not provide the information on how you called this smart contracts function we can’t tell you exactly how to fix it.

1 Like

I am not transferring any ether with the transaction. I simply deployed the contract using remix , and then passed the value using remix only.

I am not passing any wei.

this errors happens because i is not defined. Your array has the length 0 which means that you cannot set i. try using

person.push(people(nu, naam));