Guest User

Javascript

a guest
Oct 13th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. App = {
  2.   web3Provider: null,
  3.   contracts: {},
  4.   account: 0x0,
  5.  
  6.   init: function() {
  7.     return App.initWeb3();
  8.   },
  9.  
  10.   initWeb3: function() {
  11.  
  12.     if (typeof web3 !== 'undefined') {
  13.       App.web3Provider = web3.currentProvider;
  14.     } else {
  15.  
  16.       App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
  17.     }
  18.     web3 = new Web3(App.web3Provider);
  19.     App.displayAccountInfo();
  20.     return App.initContract();
  21.   },
  22.  
  23.   displayAccountInfo: function(){
  24.     web3.eth.getCoinbase(function(err, account){
  25.       if(err === null){
  26.         App.account = account;
  27.         $('#accountId').text(account);
  28.       }
  29.     });
  30.     return App.initContract();
  31.   },
  32.  
  33.   initContract: function() {
  34.     $.getJSON('Voting.json', function(votingArtifact) {
  35.  
  36.       App.contracts.Voting = TruffleContract(votingArtifact);
  37.  
  38.       App.contracts.Voting.setProvider(App.web3Provider);
  39.  
  40.       return App.reloadVoters();
  41.     });
  42.   },
  43.  
  44.   reloadVoters: function() {
  45.    
  46.     App.displayAccountInfo();
  47.  
  48.   }
  49. };
  50.  
  51. $(function() {
  52.   $(window).load(function() {
  53.     App.init();
  54.   });
  55. });
Add Comment
Please, Sign In to add comment