0

I have deployed 2 contracts on Fantom that were running on Rinkeby. Worked really well. However, when I run my Dapp using "yarn dev", I get nothing. It cannot connect to the blockchain.

So my question is do I need to do anything special? Is it the localhost port that I need to change to be 8545 or something else instead of 3000?

Here is the code where I connect to MetaMask:

window.addEventListener('load', function() {

    window.ethereum.enable();

    // Checking if Web3 has been injected by the browser (Mist/MetaMask)
    if (typeof web3 !== 'undefined') {
        // Use Mist/MetaMask's provider
        web3js = new Web3(web3.currentProvider);
    } else {
        // Handle the case where the user doesn't have Metamask installed
        // Probably show them a message prompting them to install Metamask
        // set the provider you want from Web3.providers
        web3js = new Web3.providers.HttpProvider("http://localhost:3000");

    }

    web3js.eth.defaultAccount = web3js.eth.accounts[0];

    // Now you can start your app & access web3 freely:
    startApp()
  })

I appreciate any help you can give me...

Thank-you!

1
  • We do need more information and code? how did you connect to rinkeby previously with your DAPP?
    – Majd TL
    Commented Oct 19, 2021 at 11:00

1 Answer 1

1

I was able to solve my issue my using the following code to set the provider:

web3js = new Web3.providers.HttpProvider("http://rpc.fantom.network/");

The complete code snippet now looks like this:

   window.addEventListener('load', function() {
   
   window.ethereum.enable();

    // Checking if Web3 has been injected by the browser (Mist/MetaMask)
    if (typeof web3 !== 'undefined') {
        // Use Mist/MetaMask's provider
        web3js = new Web3(web3.currentProvider);
    } else {
        // Handle the case where the user doesn't have Metamask installed
        // Probably show them a message prompting them to install Metamask
        // set the provider you want from Web3.providers
        web3js = new Web3.providers.HttpProvider("http://rpc.fantom.network/");

    }

    web3js.eth.defaultAccount = web3js.eth.accounts[0];

    // Now you can start your app & access web3 freely:
    startApp()
  })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.