SubQuery is a fast & flexible blockchain indexing toolkit that powers hundreds of teams on blockchain networks such as Ethereum, Polkadot, Cosmos, Algorand and Avalanche. We also power NEAR and Aurora, and a number of Layer 2 chains such as Polygon, Arbitrum and Optimism.
In this article, we explore how utilising a Raspberry Pi as an indexer can present cost-effective and flexible solutions to developers seeking to enhance their projects. Discover the benefits of this compact and energy-efficient setup, which make it an excellent fit for prototyping, testing, and learning SubQuery projects, especially in scenarios where space is restricted or portability is a priority.
What is a Raspberry Pi?
The Raspberry Pi is a series of small, single-board computers developed by the Raspberry Pi Foundation with the aim of promoting computer science education and digital skills. With its compact size, affordability, and versatility, the Raspberry Pi has gained immense popularity among hobbyists, educators, and professionals alike. In the blockchain space, the Raspberry Pi has been employed for various purposes since its inception.
Why use a Raspberry Pi?
For instance, the Raspberry Pi has been used to run lightweight cryptocurrency nodes, enabling enthusiasts to participate in blockchain networks without the need for expensive hardware. Additionally, Raspberry Pi devices have been deployed in staking and mining setups for certain cryptocurrencies that don’t require significant computational power. They have even been programmed to turn an LED light when a specific transaction happens on Ethereum for example.
Here are some situations where using a Raspberry Pi as an indexer can make sense for a developer:
- Development and Testing: Developers can use a Raspberry Pi as an indexer to test and optimise their SubQuery projects in a controlled environment. It provides a cost-effective platform for experimenting with data indexing and blockchain technology without the need for expensive infrastructure.
- Limited Space or Portability: The compact form factor of the Raspberry Pi makes it suitable for projects where space is limited or portability is desired. It can be easily integrated into small-scale setups or portable devices, allowing for efficient data indexing without occupying much physical space.
- Cost-Effective Solution: The Raspberry Pi offers a cost-effective solution for developers who have budget constraints or want to minimise infrastructure costs. It allows developers to start indexing projects with minimal investment and scale up as needed in the future.
- Prototyping and Proof of Concept: When developers are in the early stages of developing an indexing project or need to demonstrate a proof of concept, the Raspberry Pi can serve as a useful tool. It provides a flexible platform for quickly building and testing the functionality of an indexer.
Embracing the Raspberry Pi as a platform for running SubQuery can reveal the impressive adaptability and lightweight nature of SubQuery. The fact that it can be efficiently operated on one of the smallest and most affordable hardware is a testament to SubQuery's accessibility and resource optimization. This compatibility not only broadens the horizons for developers who are willing to experiment with hardware servers but also emphasises the ease of setting up SubQuery for enthusiasts and members of the community.
It's important to note that while a Raspberry Pi can be a valuable tool for development and learning, it may not be suitable for production-level indexing where high performance and scalability are essential. In such cases, leveraging the infrastructure and resilience of the SubQuery Network or other robust server solutions would be more appropriate.
Setting up the project on Raspberry Pi
This has been particularly highlighted by one of our community members jim-counter. Thanks to his efforts, we now have the perfect example of SubQuery indexer being run on a Raspberry Pi. Our community member put together a full guide and broke apart the process that allowed him to deploy the indexer on the Raspberry Pi.
Our community member began by emphasising the importance of selecting the right operating system. Although Ubuntu can be installed on Raspberry Pi, they chose Raspbian, citing it as the default OS for Raspberry Pi, and also as a representative of a bigger challenge.
Using the Raspberry Pi Imaging Utility, Raspbian was loaded onto a 512GB memory card. This was followed by setting up SSH, network access, and security. With the system ready, we can updated the system packages using the following commands:
sudo apt update
sudo apt upgrade
After ensuring the system was updated, they followed the SubQuery Quick-Start documentation to install necessary dependencies like Node.js and Yarn. For instance:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt install nodejs
Following this, Docker was installed through a convenience script:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Now that Docker was installed, the SubQuery CLI was installed using npm:
sudo npm install --global @subql/cli
At this point, our member created a SubQuery project, answering a series of prompts, emphasising the importance of giving the project a meaningful name, and selecting Ethereum as the network. With the starter project pulled from SubQuery’s GitHub into a folder named raspbian-ethereum, they proceeded to install dependencies:
They also noted that the starter project targeted an older version of Docker Compose and suggested an edit in the package.json file:
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remov
This should be updated to:
"start:docker": "docker compose pull && docker compose up --remove-orphans",
"dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans",
Indexing on Raspberry Pi using Subquery
In this indexing example, the Ethereum Gravatar Project has been used to showcase the possibility of indexing on the Raspberry Pi. The instructions on the documentation article have been followed step-by-step. After running sudo yarn start:docker, the Raspberry Pi began indexing the Gravatar project.
In conclusion, the community member affirmed that the Raspberry Pi is indeed capable of running a SubQuery project effectively, but they also sensibly advised against relying on it for professional indexing; instead suggesting the use of the SubQuery Network’s robust infrastructure.
This story serves as a testament to the great spirit of the SubQuery community, and how a member’s curiosity can pave the way for others. We would like to extend our gratitude to this member for their invaluable contribution and encourage others to explore the possibilities that SubQuery offers.
SubQuery is a blockchain developer toolkit facilitating the construction of Web3 applications of the future. A SubQuery project is a complete API to organise and query data from Layer-1 chains. Currently servicing Ethereum, Polygon, BNB, NEAR, Polkadot, Avalanche, Algorand, Arbitrum, Gnosis Chain, Cosmos and Flare projects, this data-as-a-service allows developers to focus on their core use case and front-end without wasting time building a custom backend for data processing activities. In the future, the SubQuery Network intends to replicate this scalable and reliable solution in a completely decentralised manner.