{{announcement.body}}
{{announcement.title}}

Introducing Infura: Connecting DApps With Ethereum Without Setting up Ethereum Nodes

DZone 's Guide to

Introducing Infura: Connecting DApps With Ethereum Without Setting up Ethereum Nodes

Want to learn more about how we can connect DApps with Ethereum without having to set up nodes? Check out this tutorial to learn how in Java.

· Security Zone ·
Free Resource

If you’ve been working on decentralized applications based on Ethereum, you might have come across setting up the Local Ethereum Node or your own private Ethereum node to test your application. In my case, setting up Ethereum nodes and connecting DApps with it has been a problem for me for the following reasons:

  1. If I use any of the Ethereum clients (geth or parity) to connect to networks or I need it to be ready to work, I have to wait for syncing with the network, which approximately one hour, in my case.
  2. Sometimes, I am disappointed even after syncing with the network, it takes a lot of time to see my transaction receipts.

While scanning through the GitHub page of web3j, I came across Infura, which provides Ethreum networks as a Service to connect with the main or test networks with just a click.

What Is Infura?

Infura is a platform as a service for Ethereum networks. Using Infura, you can connect to Ethereum Test or Main networks by exposing an URL.

When to Use Infura?

1. If you want to connect your DApp with any of the Ethereum networks (test or Main) without setting the Ethereum Network

2. If you want to focus only on the application features for a while without having to care about which network it will run on

Steps to Use Infura to Connect With Ethereum

  1. Visit https://infura.io/ and click “GET STARTED FOR FREE” and that will lead you to sign up page. Complete the signup and a dashboard will appear.
  2. Click on “CREATE NEW PROJECT” and provide a name. It will create a project like below:Screenshot from 2018-10-05 12-17-10
  3. As you can see in the side panel, there is a dropdown called ENDPOINT, which is there to choose between different kinds of public network available on Infura.
  4. To get the testnet endpoint, choose one of the testnets (ROPSTEN, RINKEBY, KOVAN) as per your use case. Since I’ve got an account on Ropsten, I chose “ROPSTEN.”
  5. Select the endpoint URL displayed after you select a network in the dropdown as highlighted below: Screenshot from 2018-10-05 12-23-19

Once you have the URL, you can create a client using web3j to interact with the network. Web3j is a reactive and functional API that provides DApps integration with Ethereum clients. Here is an example  in Scala where you can create an HTTP web3j client:

Web3j web3 = Web3j.build(new HttpService("https://rinkeby.infura.io/"));
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
System.out.println(web3ClientVersion.getWeb3ClientVersion());


The above code snippet is a simple example of creating a web3j client in Java. In the coming blogs, I will be discussing how we can use web3j with Scala and Play to create a simple DApp. If you are feeling curious, you can visit https://github.com/knoldus/play-ether-scala for a quick reference. Thanks for reading! Stay tuned!!

References:

  1. https://infura.io/
  2. https://web3j.readthedocs.io/en/latest/
Topics:
ethereum ,security ,blockchain ,dlt ,distributed ledger technology ,tutorial ,webj3 ,dapps ,infura

Published at DZone with permission of Manish Mishra , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}