Skip to content

Introducing OpenZeppelin Subgraphs

We are thrilled to announce that OpenZeppelin Contracts will be integrating The Graph’s subgraphs, combining two of the most important building blocks of the open economy. Introducing OpenZeppelin Subgraphs, a powerful library for easily building modular dense subgraphs. This new library simplifies building efficient subgraphs by supporting some of the most popular modules in our contracts library. 

Subgraphs form the bedrock querying layer for DeFi, NFT and DAO applications, indexing on-chain information and leveraging an ocean of data that was previously unavailable. Since launching in 2019, The Graph has surpassed over 25 billion monthly queries on its hosted service, thanks to adoption by Uniswap, Synthetix, Gnosis, Balancer, AAVE, and many other high-profile projects. Together through OpenZeppelin’s Contracts, subgraphs will be introduced to the next generation of smart contract developers building innovative decentralized applications. 

To learn more, check out the documentation and sign up for our event on July 28th where Hadrien Croubois, OpenZeppelin Smart Contracts Engineer, and Nader Dabit, Edge & Node Developer Advocate, will go in-depth on the new developer tooling. 

Subgraphs Explained

Subgraphs enable developers to build discoverable APIs by pulling data indexed from Ethereum and other blockchains. The Graph learns what and how to index data based on subgraph descriptions, known as the subgraph manifest. The subgraph description defines the smart contracts of interest for a subgraph, the events in those contracts to pay attention to, and how to map event data to data that The Graph will store in its database.

The diagram below gives more detail about the flow of data once a subgraph manifest has been deployed.

Subgraphs make it possible for dapps to be truly decentralized by relying on The Graph Network and open source subgraphs for indexing on-chain data. Instead of building proprietary, centralized servers, dapps can limit their back-end work by simply integrating subgraphs (APIs).

Whether you’re building a DeFi protocol or an NFT marketplace, a subgraph – or many subgraphs – can be used to efficiently retrieve data like trade volumes, NFT pricing, DAO votes and more. Best of all, subgraphs are open source so anyone can build on top of a protocol’s API. This enables faster development, greater innovation and collaboration between peers and reduced costs. If you truly believe in your subgraph, you can also curate it so you can earn a portion of query fees as a result of others using that subgraph. By being Curators on their subgraphs, developers can benefit from the network effects of their hard work!

With subgraphs integrated with OpenZeppelin Contracts, building on Ethereum has never been easier!

Supported Modules

OpenZeppelin Contracts will support subgraphs in the following modules:

  • AccessControl
  • ERC20
  • ERC721
  • ERC1155
  • ERC1967upgrade
  • Ownable
  • Pausable
  • Timelock

We plan to add support for the following modules:

  • ERC20votes
  • ERC777

Get Started

Install from npm for local development: 

  • npm install @openzeppelin/contracts
  • npm install @openzeppelin/subgraphs

For each module the library provides: 

  • A schema of the corresponding entities 
  • A datasource template that listen to events 
  • Indexing logic in assembly script

The subgraph can be assembled manually or using the graph-compile tool as part of the @amxx/graphprotocol-utils package. Simply describe your application using a config.json file then generate your custom schema and manifest with all modules enabled. To get started building modular subgraphs with OpenZeppelin Contracts, head over to our official documentation page and visit the Github repository

Learn More

To learn more on how to get started using OpenZeppelin Subgraphs visit the official documentation page. Be sure to sign up for our joint webinar in collaboration with The Graph on “Indexing Your App’s Activity with OpenZeppelin Subgraphs & The Graph” July 28th, 12:00 PM PST / 7PM UTC. If you plan to attend EthCC, check out Hadrien Croubois’ speech “Efficient data query through dense subgraphs” on July 20th in the Sorbonne room.

Learn more about OpenZeppelin Contracts: openzeppelin.com/contracts

See the documentation: docs.openzeppelin.com/contracts

Sign up for a free OpenZeppelin Defender account: https://defender.openzeppelin.com/

Join the Community