0
Uncaught (in promise) ReferenceError: TruffleContract is not defined   
    at Object.loadContract (app.js:55)     
    at async Object.load (app.js:8)

here is my code of app.js file

App = { 
  loading: false, 
  contracts: {}, 

  load: async () => { 
    await App.loadWeb3() 
    await App.loadAccount()  
    await App.loadContract()  
    //await App.render()  
  },  

   // https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8    
    loadWeb3: async () => {  
    if (typeof web3 !== 'undefined') {  
      App.web3Provider = web3.currentProvider  
      web3 = new Web3(web3.currentProvider)  
    } else {  
      window.alert("Please connect to Metamask.")  
    }  
    // Modern dapp browsers...  
    if (window.ethereum) {            
      window.web3 = new Web3(ethereum)   
      try {                                
        await ethereum.enable()    
        web3.eth.sendTransaction({/* ... */})  
      } catch (error) {  
        // User denied account access...  
      }  
    }  
    // Legacy dapp browsers...  
    else if (window.web3) {    
      App.web3Provider = web3.currentProvider      
      window.web3 = new Web3(web3.currentProvider) 
      // Acccounts always exposed          
      web3.eth.sendTransaction({/* ... */})      
    }         
    // Non-dapp browsers...    
    else {      
      console.log('Non-Ethereum browser detected. You should consider trying MetaMask!')    
    }    
  },    

  loadAccount: async () => {         
    // Set the current blockchain account   
    App.account = web3.eth.accounts[0]   
  },    

  loadContract: async () => {     
    // Create a JavaScript version of the smart contract  

    const logiblock = await $.getJSON('LogiBlock.json')     
    console.log(logiblock)   
    App.contracts.LogiBlock = TruffleContract(logiblock)   
    console.log(App.contracts.LogiBlock)    
    App.contracts.LogiBlock.setProvider(App.web3Provider)    

    // Hydrate the smart contract with values from the blockchain  
    App.logiblock = await App.contracts.LogiBlock.deployed()   
  },  
  • @goodvibration can you please help me – user51361 Mar 16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.