Introducing Infura: Connecting DApps with Ethereum Network without setting up Ethereum Nodes

Ethereum Networks

 

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, if I need it to be ready to work I’ve to wait for syncing with the network, which takes a lot of time (~ 1 hour in my case) which I can’t tolerate every time I am getting down the client or get disconnected for some network issues.
  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?

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 on which network it will run

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 from (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 like 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 which provides dApps integration with Ethereum clients. Here is an example code 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!!
Knoldus-Scala-spark-services-company

References:

  1. https://infura.io/
  2. https://web3j.readthedocs.io/en/latest/

 

Written by 

Manish Mishra is a Sr. Software Consultant, with experience of more than 7 years. His primary development technology was Java. He fell for Scala language and found it innovative and interesting language and fun to code with. He has also co-authored a journal paper titled: Economy Driven Real Time Deadline Based Scheduling. His interests include: learning cloud computing products and technologies, algorithm designing. He finds Books and literature as favorite companions in solitude. He likes stories, Spiritual Fictions and Time Traveling fictions as his favorites.

Leave a Reply

%d bloggers like this: