Solidity – Resolving ValueError: Gas Estimation Failed ‘Execution Reverted’ in Python

pythonrevertsolidity

I get this error when trying to my deploy .sol contract: "ValueError: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually. "

Any help would be welcomed. Thank you. The account has a balance: account balance: 97946875117500000000

I deploy with this line of code : convert = converter.deploy({"from": account})

My code:

pragma solidity >=0.7.6 <0.9.0;

contract converter {

    struct rprices {
        uint256 _epochId;
        uint256[2] _ftsoIndices;
        uint256[2] _prices;
        uint256[2] _random;
    }
    rprices[] public rprice;

    constructor() {
        converter1();
    }

    function converter1()
        public
        returns (
            uint256,
            uint256[2] memory,
            uint256[2] memory,
            uint256[2] memory
        )
    {
        rprice.push(
            rprices(
                2342,
                [
                    2323423445345345345345343423423223234234453453453453453434234232,
                    22342323423445345343453453534534534342342322343545345345345345345323423342342
                ],
                [
                    22342323423445345343453453534534534342342322343545345345345345345323423342342,
                    22342323423445345343453453534534534342342322343545345345345345345323423342342
                ],
                [
                    22342323423445345343453453534534534342342322343545345345345345345323423342342,
                    22342323423445345343453453534534534342342322343545345345345345345323423342342
                ]
            )
        );

        return (
            rprice[2]._epochId,
            rprice[2]._ftsoIndices,
            rprice[2]._prices,
            rprice[2]._random
        );
    }
}

enter image description here

Best Answer

I don't know about the exact logic of your smart contract but the revert is caused by accessing an element out of bound from your rprice array. When you deploy the contract, at the beginning rprice has 0 element, and after rprice.push(... in the function converter1 (), rprice now has 1 element. So the fix is at the return statement of converter1:

function converter1() 
  ... 
  ...
  ...

   return (
        rprice[0]._epochId,
        rprice[0]._ftsoIndices,
        rprice[0]._prices,
        rprice[0]._random
    );

Because rprice has only 1 element, you must access it with index 0 (rprice[0]).