text: App = {
    web3Provider: null,
    contracts: {},
  
    init: function() {
      return App.initWeb3();
    },
  
    initWeb3: function() {
       // Initialize web3 and set the provider to the testRPC.
       if (typeof web3 !== 'undefined') {
         App.web3Provider = web3.currentProvider;
         web3 = new Web3(web3.currentProvider);
       } else {
       // set the provider you want from Web3.providers
        App.web3Provider = new Web3.providers.HttpProvider('http://127.0.0.1:9545');
        web3 = new Web3(App.web3Provider);
      }
  
      return App.initContract();
    },
  
    initContract: function() {
      $.getJSON('NannyToken.json', function(data) {
        // Get the necessary contract artifact file and instantiate it with truffle-contract.
        var TutorialTokenArtifact = data;
        App.contracts.TutorialToken = TruffleContract(TutorialTokenArtifact);
  
        // Set the provider for our contract.
        App.contracts.TutorialToken.setProvider(App.web3Provider);
  
        // Use our contract to retieve and mark the adopted pets.
        return App.getBalances();
      });
  
      return App.bindEvents();
    },
  
    bindEvents: function() {
      $(document).on('click', '#transferButton', App.handleTransfer);
    },
  
    handleTransfer: function(event) {
      event.preventDefault();
  
      var amount = parseInt($('#TTTransferAmount').val());
      var toAddress = $('#TTTransferAddress').val();
  
      console.log('Transfer ' + amount + ' NN to ' + toAddress);
  
      var TutorialTokenInstance;
  
      web3.eth.getAccounts(function(error, accounts) {
        if (error) {
          console.log(error);
        }
  
        var account = accounts[0];
  
        App.contracts.TutorialToken.deployed().then(function(instance) {
          TutorialTokenInstance = instance;
  
          return TutorialTokenInstance.transfer(toAddress, amount, {from: account, gas: 100000});
        }).then(function(result) {
          alert('Transfer Successful!');
          return App.getBalances();
        }).catch(function(err) {
          console.log(err.message);
        });
      });
    },
  
    getBalances: function() {
      console.log('Getting balances...');
  
      var TutorialTokenInstance;
  
      web3.eth.getAccounts(function(error, accounts) {
        if (error) {
          console.log(error);
        }
  
        var account = accounts[0];
  
        App.contracts.TutorialToken.deployed().then(function(instance) {
          TutorialTokenInstance = instance;
  
          return TutorialTokenInstance.balanceOf(account);
        }).then(function(result) {
          balance = result.c[0];
  
          $('#TTBalance').text(balance);
        }).catch(function(err) {
          console.log(err.message);
        });
      });
    }
  
  };
  
  $(function() {
    $(window).load(function() {
      App.init();
    });
  });
  