Using Infura with web3j¶
When you sign up to the service you are provided with a token you can use to connect to the relevant Ethereum network:
Main Ethereum Network:
Test Ethereum Network (Rinkeby):
Test Ethereum Network (Kovan):
Test Ethereum Network (Ropsten):
For obtaining ether to use in these networks, you can refer to Ethereum testnets
The web3j infura module provides an Infura HTTP client (InfuraHttpService) which provides support for the Infura specific Infura-Ethereum-Preferred-Client header. This allows you to specify whether you want a Geth or Parity client to respond to your request. You can create the client just like the regular HTTPClient:
Web3j web3 = Web3j.build(new HttpService("https://rinkeby.infura.io/<your-token>")); Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send(); System.out.println(web3ClientVersion.getWeb3ClientVersion());
If you want to test a number of the JSON-RPC calls against Infura, update the integration test CoreIT with your Infura URL & run it.
For further information, refer to the Infura docs.
In order to transact with Infura nodes, you will need to create and sign transactions offline before sending them, as Infura nodes have no visibility of your encrypted Ethereum key files, which are required to unlock accounts via the Personal Geth/Parity admin commands.