I am increasing the value at a particular index in Solidity but it is giving me bad instruction error.

Can anyone tell me what I am missing here?

Please check the sample contract for reference:

pragma solidity >0.6.0;

contract abs{
    uint256[] public amounts;
    function contractParams(uint256 index, uint256 val) external{
        amounts[index] = amounts[index] + val;

If the element index is out of range from arrays length. It will revert.
To push value to array, use amounts.push(x)

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.