Making a Dapp, getting an error: setProvider is not defined?

272 views Asked by At

I`m working on this course on udemy and after googleing and trying all the potential solutions and getting no feedback from the instructor of this course I ended up on stack :)

I˙m doing frontend for an Dapp, after checking for metamask after I load up my web site and setting up the accounts, I`m trying to set a provider for my smart contracts instances to use them later for deploying and interacting with them :

My app.js file:

import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract'

// Import our contract artifacts and turn them into usable abstractions.
import exchange_artifacts from '../../build/contracts/Exchange.json'
import token_artifacts from '../../build/contracts/FixedSupplyToken.json'


var accounts;
var account;

var ExchangeContract = contract(exchange_artifacts);
var TokenContract = contract(token_artifacts);

window.App = {
  start: function() {
   //bootstrap everything
   
   

**ExchangeContract = setProvider(web3.currentProvider); // getting a setProvider not defined error 
TokenContract = setProvider(web3.currentProvider); // getting a setProvider not defined error**

    
},

Metamask check in app.js:

window.addEventListener('load', function() {
    return new Promise((resolve, reject) => {
        if(typeof window.ethereum !== 'undefined') {
          const web3 = new Web3(window.ethereum);
          
          console.log("my metamask version");

          window.web3 = new Web3(web3.currentProvider);
          

          window.ethereum.enable()
            .then(() => {
              resolve(
                new Web3(window.ethereum)
                
              );
            })
            .catch(e => {
              reject(e);
            });
            
          return;
        }
        if(typeof window.web3 !== 'undefined') {
            
          return resolve(
            new Web3(window.web3.currentProvider)
          );
        }
        
        resolve(new Web3('http://localhost:9545'));
      }),

enter image description here

0

There are 0 answers