If you don't want to set up a full node for you decentralized application, then this is the recipe for you. INFURA provides an infrastructure for Ethereum and you can make use of it for free.
Saving time and money with INFURA
How to do it...
- Go to the INFURA signup page (https://infura.io/signup) and enter your name and email.
- Once you acknowledge the terms and conditions and have signed up, you will receive an email from INFURA with the providers for each network.
- For each network, you will receive an endpoint and an API key:
- Main Ethereum network: https://mainnet.infura.io/<api-key>
- Test Ethereum network (Ropsten): https://ropsten.infura.io/<api-key>
- Test Ethereum network (Rinkeby): https://rinkeby.infura.io/<api-key>
- Test Ethereum network (INFURAnet): https://infuranet.infura.io/<api-key>
You can interact with the providers just like you do with your local node. You can use JSON RPC, Web3JS, or even the REST API provided by INFURA to interact with the nodes.
-
Get the current block number with JSON RPC using cURL:
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' "https://mainnet.infura.io/<your-api-key>"
This will return the current block number, as follows:
{"jsonrpc":"2.0","id":1,"result":"0x512bab"}
- INFURA also provides an easy-to-use REST API interface for JSON RPC commands. You can use the JSON RPC methods as the path to get the result:
https://api.infura.io/v1/jsonrpc/mainnet/eth_blockNumber?token=<your-api-key>
- To use INFURA with your web3js application, you can set the endpoints as HTTP providers:
web3 = new Web3(new Web3.providers.HttpProvider ("https://mainnet.infura.io/<your_api_key>"));
There's more...
INFURA also provides support for IPFS and you can use their server as a gateway:
- IPFS Gateway: https://ipfs.infura.io
- IPFS RPC: https://ipfs.infura.io:5001