1

I am facing this type of Error in 'remix IDE' while connecting it to 'web3.js@0.20.2'

Error: Failed to decode output: Error: insufficient data for uint256 type (arg="", coderType="uint256", value="0x00")

<!DOCTYPE html>
<head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./node_modules/web3/dist/web3.min.js">
    </script>
</head>

<body>
<input id="name" name="choice" type="text"> Vote: </input>
<button id="button">Submit : </button>
<h2 id="instructor"></h2>
</body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script>

    if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
        // set the provider you want from Web3.providers
        web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }

// Previous if/else statement removed for brevity

web3.eth.defaultAccount = web3.eth.accounts[0];
console.log(web3.version)
var vote= web3.eth.contract([
    {
        "constant": false,
        "inputs": [
            {
                "name": "x",
                "type": "uint256"
            }
        ],
        "name": "set",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "get",
        "outputs": [
            {
                "name": "",
                "type": "uint256"
            },
            {
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
]);

vote_add=vote.at('0x6b3c179a96c329dcf93f2d27310c77e88e651af6');

console.log(vote_add);
$("#button").click(function() {
            vote_add.set($("#name").val());
        });

vote_add.get(function(error, result){
            if(!error)
                {
                    $("#instructor").html(result[0]+' ('+result[1]+' years old)'+result[2]+result[3]+result[4]+result[5]);
                    console.log(result);
                }
            else
                console.log(error);
        });
</script>
</html>

Solidity code:-

pragma solidity ^0.5.0;
contract vote
{
    uint public c0=0;
    uint public c1=0;
    uint public c2=0;
    uint public c3=0;
    uint public c4=0;
    uint public c5=0;
    function set(uint x) public {
        if(x==0)
        {
            c0+=1;
        }
        else if(x==1)
        {
            c1+=1;
        }
        else if(x==2)
        {
            c2+=1;
        }
        else if(x==3)
        {
            c3+=1;
        }
        else if(x==4)
        {
            c4+=1;
        }
        else if(x==5)
        {
            c5+=1;
        }
        else
        {

        }
    }
    function get() public view returns(uint,uint,uint,uint,uint,uint)
    {
        return (c0,c1,c2,c3,c4,c5);
    }
}

enter image description here

  • can you provide some more details? are you trying to change the Environment in Remix like connecting with Web3 Provider or Injected Web3? – Yahya Nov 12 at 12:54
  • yes connecting to Injected web3 and using jQuery Shall i share the code ? – Parshvi Nov 12 at 12:55
  • yes, that would be great. – Yahya Nov 12 at 12:56
  • see the edited post ! thamk you so much ! – Parshvi Nov 12 at 13:01
  • see the edited code ! thank you so much ! i believe this your code ! – Parshvi Nov 12 at 13:03
0

If you face any issue while connecting with the network(let say ganache) you can try the following steps:

  1. make sure ganache is up and running(ideally on port 8545)
  2. from remix change the environment to Web3 Provider and confirm the address from the popup window.
  3. in case you want to connect through the metamask, change remix environment to Injected web3. Make sure you are connected to the right network in metamask. You can change the network by click on the top right network options and choose localhost 8545 to connect with locally running ganache. enter image description here

hope it will help.

  • Sorry not working either ! after refreshing too ! – Parshvi Nov 12 at 15:13
  • ok the last thing from my side that you can do is try this updated remix: remix.ethereum.org/… – Yahya Nov 12 at 15:44

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.