首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack智能合同

webpack智能合同
EN

Ethereum用户
提问于 2018-06-18 02:29:11
回答 1查看 81关注 0票数 0

我试图将html下拉列表中的值发送到智能契约,该值是从js函数中提取出来的,但我无法将其添加到SetVote函数中,执行就会中断。

代码语言:javascript
复制
Html:
 
            
              Dropdown button
            
            
              value1
              value2
              value3
            
          


JavaScript:

 App = {   web3Provider: null,   contracts: {},


  init: function() {

    console.log("inside init");


    return App.initWeb3();   },

  initWeb3: function() {

    console.log("inside initWeb3");

    // Is there an injected web3 instance? if (typeof web3 !== 'undefined') {   App.web3Provider = web3.currentProvider; } else {   // If no injected web3 instance is detected, fall back to Ganache   App.web3Provider = new Web3.providers.HttpProvider('http://127.0.0.1:9545'); } web3 = new Web3(App.web3Provider);  

    return App.initContract();   },

  initContract: function() {

    console.log("inside initContract");

    $.getJSON('voting.json', function(data) {
      // Get the necessary contract artifact file and instantiate it with truffle-contract
      var votingArtifact = data;
      App.contracts.voting = TruffleContract(votingArtifact);

      // Set the provider for our contract
      App.contracts.voting.setProvider(App.web3Provider);

      // Use our contract to retrieve and mark the adopted pets
     // return App.markAdopted();
    });

    return App.bindEvents();   },

bindEvents: function() {

  $(document).on('click', '.btn-res', App.GetVote); 

 //$(document).on('click', '.btn-vote', App.SetVote);

 $(".dropdown-menu a").click(function(){var vote = $(this).text(); });
   console.log("voted value",vote);
   App.SetVote(vote);

         },


SetVote: function(account) {

  var votingInstance;  
  //var vote="voteValue"

  App.contracts.voting.deployed().then(function(instance) {

    votingInstance = instance;

    return votingInstance.setVote(vote);   }).then(function() {

    // modal for successfully voting
    // open index page

  }).catch(function(e) {
    console.log("error in voting");   });

},

GetVote: function() {

   web3.eth.getAccounts(function(error, accounts) {
    if (error) {
      console.log(error);
    }

    var account = accounts[0];

    var self = this;

    var data;
    voting.deployed().then(function(instance) {
      data = instance;
      return data.getVote.call();
    }).then(function(value) {

      console.log(value);

      //table of winners
     //list of voters



    }).catch(function(e) {
      console.log(e);
      self.setStatus("Error getting balance; see log.");
    }); }); } }; $(function() {   $(window).load(function() {
    App.init();   }); });
EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-06-18 05:12:44

在我看来,setVote param帐户没有发送到contract。请更正变量,并查看是否正在调用契约方法。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/51455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档