TransWikia.com

error in remix IDE

Ethereum Asked by Parshvi on December 5, 2021

I am facing this type of Error in ‘remix IDE’ while connecting it to ‘[email protected]

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

2 Answers

I got the same error too.

I think the reason is: the solidity code version is not compatible with the web3 provider's(geth) version.

Here is the solution: Update the solidity code and geth client to the newest versions, or let the solidity version is compatible with the geth client's version.

Answered by mr_franklin on December 5, 2021

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.

Answered by Yahya on December 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP