This project demonstrates a comparison between two methods for retrieving data from the Ethereum blockchain. The first method utilizes The Graph, a decentralized protocol for indexing and querying blockchain data. The second method interacts directly with the blockchain using ethers.js. We'll explore how The Graph makes data retrieval more efficient and developer-friendly.
- Prerequisites
- How to setup project
- Code Comparison
- Why The Graph?
- Benefits of The Graph
- Contributing
- License
Just a gist on these topics would be nice.
- React
- The Graph
- Ether.js
Please follow the instructions in the usingGraph and usingNormalBlockchain directories for individual setup steps.
Tip: To compare data retrieval speed between the two methods:
- Start both applications on different ports, e.g., http://localhost:5173/ and http://localhost:5174/.
- Open the browser console.
- Click the "Click for info" button in both applications.
- Observe the time taken. You'll notice that using The Graph fetches more data in less than 3 seconds, while using the normal blockchain method takes nearly 6 seconds for the same data retrieval, showing a significant difference in time efficiency.
- For larger data, The Graph's efficiency becomes even more apparent
- You could observe the difference in given images below.
- Using NORMAL BLOCKCHAIN method
- Using THE GRAPH method
-
TIP:- I have provided the Smart Contract code file and the Contract address anyone could copy and paste on remix.ide and perform write operations on the smart contract and fetch data from both the methods to see the time taken to retrieve data from both the methods and which one is better.
-
IMPORTANT NOTE: Please please select environment as Injected web3 and Mumbai test network in Metamask wallet because the smart contract is deployed on Mumbai testnet.
like shown in the image
-
File:
App.js
in thewith-graph
directory -
This method utilizes The Graph to retrieve data from the Ethereum blockchain.
-
Benefits:
- Significantly reduces data retrieval time.
- Simplifies data querying with GraphQL.
- Allows for efficient storage and organization of blockchain data.
-
To test, click the "Click for info" button to retrieve and display data from the blockchain using The Graph.
-
File:
App.js
in thewith-normal
directory -
This method interacts directly with the blockchain using ethers.js.
-
Cons:
- Data retrieval may be slow for complex operations.
- Requires direct interaction with Ethereum using Metamask.
-
To test, click the "Click to connect" button to connect your Ethereum wallet, and then click "Click for info" to retrieve and display data from the blockchain directly.
The Ethereum blockchain stores vast amounts of data, making it challenging to query and retrieve specific information efficiently. The Graph addresses these challenges by providing a decentralized protocol for indexing and querying blockchain data. It simplifies data retrieval and querying, making it a preferred choice for developers.
-
Faster Data Retrieval: Using The Graph significantly reduces the time required to retrieve data from the Ethereum blockchain, enhancing user experience.
-
GraphQL Querying: The Graph allows developers to use GraphQL to retrieve specific data, making it easy to search for and organize information.
-
Efficient Data Storage: The Graph efficiently indexes and stores blockchain data, ensuring it's readily available when needed.
Contributions are welcome! If you have suggestions, improvements, or would like to add more data retrieval methods for comparison, feel free to open an issue or a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.