1

Hi I'm trying to make a voting module which the user can cast votes by pressing radio button. But when I run this error comes out.

Uncaught TypeError: this._eth.sendTransaction is not a function

This is my script

    if(typeof web3 != 'undefined'){
    web3 = new Web3(web3.currentProvider);
     web3.eth.defaultAccount = web3.eth.accounts[0];}else {
      web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545")); 
 }
    web3.eth.defaultAccount = web3.eth.accounts[0];

  var SuffrageContract = new web3.eth.contract([
  {
    "constant": true,
    "inputs": [],
    "name": "getInstructor",
    "outputs": [
      {
        "name": "",
        "type": "string"
      },
      {
        "name": "",
        "type": "string"
      },
      {
        "name": "",
        "type": "string"
      },
      {
        "name": "",
        "type": "string"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  },
  {
    "constant": false,
    "inputs": [
      {
        "name": "_id",
        "type": "string"
      },
      {
        "name": "_president",
        "type": "string"
      },
      {
        "name": "_vice",
        "type": "string"
      },
      {
        "name": "_party",
        "type": "string"
      }
    ],
    "name": "setInstructor",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }

    ]);
    var Suffrage = SuffrageContract.at('0x3b2e13c156ebb392074066ee414f42c4c59b761d');
        console.log(Suffrage);


  $("#submit").click(function(){


     var president,vp,party;
     //Get President
      if($('#pres1').is(':checked')){
        president = $('#pres1').val();

      }
      else if($("#pres2").is(':checked')){
        president = $('#pres2').val();
      }  
      else if($("#pres3").is(':checked')){
        president = $('#pres3').val();
      }  
      else if($("#pres4").is(':checked')){
        president = $('#pres4').val();
      }  
      else if($("#pres5").is(':checked')){
        president = $('#pres5').val();
      }  
      else if($("#pres6").is(':checked')){
        president = $('#pres6').val();
      }  
        //Get Vice President
       if($('#vp1').is(':checked')){
        vp = $('#vp1').val();

      }
      else if($("#vp2").is(':checked')){
        vp = $('#vp2').val();
      }  
      else if($("#vp3").is(':checked')){
        vp = $('#vp3').val();
      }  
      else if($("#vp4").is(':checked')){
        vp = $('#vp4').val();
      }  
      else if($("#vp5").is(':checked')){
        vp = $('#vp5').val();
      }  
      else if($("#vp6").is(':checked')){
        vp = $('#vp6').val();
      }  

      //Get Party List
       if($('#party1').is(':checked')){
        party = $('#party1').val();

      }
      else if($("#party2").is(':checked')){
        party = $('#party2').val();
      }  
      else if($("#party3").is(':checked')){
        party = $('#party3').val();
      }  
      else if($("#party4").is(':checked')){
        party = $('#party4').val();
      }  
      else if($("#party5").is(':checked')){
        party = $('#party5').val();
      }  
      else if($("#party6").is(':checked')){
        party = $('#party6').val();
      }  
      else if($("#party7").is(':checked')){
        party = $('#party7').val();
      }  
      else if($("#party8").is(':checked')){
        party = $('#party8').val();
      }  
      else if($("#party9").is(':checked')){
        party = $('#party9').val();
      }  
      else if($("#party10").is(':checked')){
        party = $('#party10').val();
      }  
      else if($("#party11").is(':checked')){
        party = $('#party11').val();
      }  
       else if($("#party12").is(':checked')){
        party = $('#party12').val();
      }  

          Suffrage.setInstructor('sample id', president, vp, party, function(err,result){

                console.log(err,result);
            });

  });


</script>

I dont know whats wrong please help me. Any answer will be accepted and appreciated. Thank you. :)

0

What version of Web3 are you using?

If you're using the current version of Web3, then you shouldn't include the new keyword when you write the following line:

var SuffrageContract = new web3.eth.contract(...);

Instead, it should just be the following:

var SuffrageContract = web3.eth.contract(...);

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.