description | sidebar_position |
---|---|
Ethereum quickstart guide |
2 |
import Banner from '@site/src/components/Banner'
This quickstart guide will help you set up and make calls on the Ethereum network using the Infura endpoints.
Don't have an Infura account? Sign up for our free plan and start using the Ethereum network!Ensure you have an API key with the Ethereum network enabled.
Run the following command in your terminal, replacing <YOUR-API-KEY>
with your actual Infura API key:
curl https://mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1}'
:::note
In Windows Powershell, quotations in curl
commands can behave differently than expected. We recommend using Postman on Windows systems.
:::
Call the JSON-RPC methods using Postman.
Click Run in Postman to fork the collection and make requests.
:::info
Set the correct variables for your API key and network before running requests.
:::
In these examples, you'll use npm as your package manager.
-
In your project folder, install the
node-fetch
package using npm::npm i node-fetch
-
Create your JavaScript file and copy the following code:
Replace
<YOUR-API-KEY>
with your actual Infura API key.import fetch from "node-fetch" fetch("https://mainnet.infura.io.infura.io/v3/<YOUR-API-KEY>", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", method: "eth_blockNumber", params: [], id: 1, }), }) .then((response) => response.json()) .then((data) => { console.log(data) }) .catch((error) => { console.error(error) })
-
Run the code using the following command:
node index.js
-
In your project folder, install the
axios
package using npm:npm i axios
-
Create your JavaScript file and copy the following code:
Replace
<YOUR-API-KEY>
with your actual Infura API key.const axios = require("axios") axios .post("https://mainnet.infura.io.infura.io/v3/<YOUR-API-KEY>", { jsonrpc: "2.0", method: "eth_blockNumber", params: [], id: 1, }) .then((response) => { console.log(response.data) }) .catch((error) => { console.error(error) })
-
Run the code using the following command:
node index.js
-
In your project folder, install the
ethers
package using npm:npm install ethers
-
Create your JavaScript file and copy the following code:
Replace
<YOUR-API-KEY>
with your actual Infura API key.const ethers = require("ethers") const provider = new ethers.providers.JsonRpcProvider( "https://mainnet.infura.io.infura.io/v3/<YOUR-API-KEY>" ) provider .getBlockNumber() .then((blockNumber) => { console.log(blockNumber) }) .catch((error) => { console.error(error) })
-
Run the code using the following command:
node index.js
-
In your project folder, install the latest version of the web3.js library
-
Create your JavaScript file and copy the following code:
Replace
<YOUR-API-KEY>
with your actual Infura API key.var { Web3 } = require("web3") var provider = "https://mainnet.infura.io/v3/<YOUR-API-KEY>" var web3Provider = new Web3.providers.HttpProvider(provider) var web3 = new Web3(web3Provider) web3.eth.getBlockNumber().then((result) => { console.log("Latest Ethereum Block is ", result) })
-
Run the code using the following command:
node index.js
-
In your project folder, install the
requests
library:pip install requests
-
Create your Python file and copy the following code:
Replace
<YOUR-API-KEY>
with your actual Infura API key.import requests import json url = "https://mainnet.infura.io/v3/<YOUR-API-KEY>" payload = { "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1 } headers = {'content-type': 'application/json'} response = requests.post(url, data=json.dumps(payload), headers=headers).json() print(response)
-
Run the code using the following command:
python index.py
Now that you have successfully made a call to the Ethereum network, you can explore more functionalities and APIs provided by Infura. Here are some suggestions:
-
Explore other Ethereum APIs: Infura supports a wide range of APIs. You can find more information in the JSON-RPC API method documentation.
-
Try out different networks: Infura supports multiple networks including Arbitrum, Linea, Polygon, Optimism, and more.
-
Monitor your usage: Monitor your usage on the MetaMask Developer dashboard to ensure you're not hitting your rate limits.
Remember, the Infura community is here to help. If you have any questions or run into any issues, check out the Infura community for help and answers to common questions.