9

I want to connect to the Ropsten test-net:

    // Is there is an injected web3 instance?
    if (typeof web3 !== 'undefined') {
      App.web3Provider = web3.currentProvider;
      web3 = new Web3(web3.currentProvider);
    } else {
      // If no injected web3 instance is detected, fallback to the TestRPC.
      App.web3Provider = new web3.providers.HttpProvider('http://localhost:8545');
      web3 = new Web3(App.web3Provider);
    }

I have http://localhost:8545 in this code. How do I connect to Ropsten instead of http://localhost:8545?

12

You can either run a local node and specify your chain using --chain ropsten when starting geth/parity and connect to localhost once sync is completed or you can connect to infura.io:

var web3 = new Web3(new Web3.providers.HttpProvider(
    'https://ropsten.infura.io/v3/[infura_project_id]'
));
  • geth --testnet --chain ropsten --rpc Got this error: Incorrect Usage. flag provided but not defined: -chain – Muhammad Shahzad Apr 18 '18 at 17:01
  • 1
    @MuhammadShahzad try omitting --testnet – d9ngle Apr 18 '18 at 19:00
2

In addition to Infura, you can choose other third-party node services such as QuikNode and Alchemy.

1

For get infura links, please use : enter link description here

1

You can also install metamask, which will inject web3 into the javascript runtime environment (assuming you are running this in the browser). From metamask, you can then select the chain/network as shown:

Metamask dropdown

  • For using this approach wee should run webpage on local server. – Stepan Poperechnyi May 30 at 8:49

Your Answer

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

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