Docs

Discover how Phala's AI Agent Contract offers the essential tools to develop and profit from intelligent applications.

Explore Now

Airstack Starter Kit: Build Data-Driven dApps with The Ultimate Web3 API

2024-02-01

Overview

In the era of Web2, data-driven applications have become the cornerstone of digital experiences, harnessing vast amounts of user data to deliver personalized content, targeted advertising, and streamlined services. These applications rely on centralized databases that collect, store, and process information, enabling businesses to make informed decisions and offer enhanced user experiences. However, this centralized model comes with a significant caveat: the businesses behind Web2 applications retain ownership and control over the user data they collect, raising concerns about privacy, data portability, and the potential for misuse of personal information.

As we pivot towards the decentralized paradigm of Web3, the focus shifts to dApps (decentralized applications) that leverage the transparency and immutability of blockchain technology. In this new landscape, the challenge lies in effectively indexing and utilizing off-chain data to maintain the same level of personalization and efficiency that Web2 applications provided. By bridging the gap between on-chain activities and the rich context of off-chain data, Web3 dApps are poised to redefine the data ecosystem, but attaining meaningful data through this process is not all sunshine and rainbows. Jason Goldberg, Founder at Airstack, mentions these difficulties and how Airstack takes aim at the problem: “Building in Web3 can feel a bit like assembling a jigsaw puzzle, only to realize half the pieces are scattered across different tables. It is immensely time consuming and expensive to spin up and maintain. Even basic infrastructure developers need to create cross-chain or cross-protocol apps. That's the painkiller we've built at Airstack - the fastest and easiest way to compose Web3 data. Because data availability doesn't mean anything if it's not easily accessible by the devs who need it most.

Building in Web3 can feel a bit like assembling a jigsaw puzzle, only to realize half the pieces are scattered across different tables. It is immensely time consuming and expensive to spin up and maintain. Even basic infrastructure developers need to create cross-chain or cross-protocol apps. That's the painkiller we've built at Airstack - the fastest and easiest way to compose Web3 data. Because data availability doesn't mean anything if it's not easily accessible by the devs who need it most.” - Jason Goldberg, Founder at Airstack

Today, we are proud to announce the Airstack Starter Kit. Now Airstack’s unique capabilities to produce meaningful abstractions for any users’ on-chain graph can be combined with Phala’s Phat Contract to enable devs to build Web3 dApps tailored specifically for their target users.

Airstack Starter Kit

The Airstack Starter Kit allows for users to request data from Airstack’s API to compute a trust/risk score and send to an on-chain consumer contract. However, the code is minimal and can be forked for any customizations based on the developer’s requirements.

How It Works

The user journey can be visualized in the diagram above. Alice requests a “trust score” about Eve to the consumer contract on the EVM chain and the action request is added to the request queue. The Phat Contract poll() the queue and pop() the new action request off the queue to compute the trust score for Eve. Once the data is retrieved from Airstack’s API, the score is computed based on the scoring criteria and the result is sent back to the consumer contract on the EVM chain.

What is Being Deployed?

This deployment will only deploy the left side of the diagram above that is in the green box labeled Phala Network. The “Phat Contract 2.0” program will be deployed to Phala Network and will be configured to connect to the Consumer Contract deployed on the EVM chain.

Note: that the Consumer Contract will require the developer to deploy this manually until support for EVM Contract deployment from the Bricks UI is supported. See “Requirements Before Deployment” before deploying your Airstack Phat Contract.

Requirements Before Deployment

There are a couple steps to complete before deploying the Airstack Template.

  • Create a Phat Contract 2.0 Profile
    • Generate and fund an EVM account for the target chain you plan to deploy your Consumer Contract to
  • Deploy the Consumer Contract (The right side of the diagram above) on an EVM chain that will connect to the deployed Phat Contract
  • (Optional) Create API Key from Airstack. See how to get an API Key here. By default a rate-limited key is provided with no guarantee of service if limit is exhausted.

Deploying The Consumer Contract

Clone the Airstack Phat Contract repo.

git clone [email protected]:Phala-Network/airstack-phat-contract.git

Install dependencies after cd into the directory.

npm install

Configure your .env file with necessary information then deploy your Consumer Contract to the destination chain (this example deploys to Polygon Mumbai Testnet). Make sure to save the Consumer Contract address to set later in the deployed Airstack template.

npm run test-deploy
# Deploying...
#
# 🎉 Your Consumer Contract has been deployed, check it out here: https://mumbai.polygonscan.com/address/0x10FA409109E073C15b77A8352cB6A89C12CD1605
#
# You also need to set up the consumer contract address in your .env file:
#
# MUMBAI_CONSUMER_CONTRACT_ADDRESS=0x10FA409109E073C15b77A8352cB6A89C12CD1605
#
# Configuring...
# Done
# ✨  Done in 8.20s.

Setting Secrets Before Deployment

If you chose to get an API key from Airstack then you will add this in your secrets box when configuring and deploying your Airstack Phat Contract.

Example:

{
	"apiUrl": "https://api.airstack.xyz/gql", 
	"apiKey": "3a41775a358a4cb99ca9a29c1f6fc486"
}

After Deploying The Airstack Template

After you deploy the Airstack Phat Contract, there will be a final step to set the ATTESTOR_ROLE in the Consumer Contract. This can be done by setting the MUMBAI_PHALA_ORACLE_ATTESTOR in your .env file to the attestor address in the deployed Airstack Phat Contract dashboard. Next you will execute the command.

npm run test-set-attestor

Run a Test Request

See your deployed Airstack Phat Contract work in action with a test request().

npm run test-push-request

Features and Benefits

With the ability to bring Airstack’s data on-chain with customized logic performed on the data, developers can now securely connect their indexed data to their web3 dApps. There are many features and benefits that can be built. For example:

  • Web3 Social
    • Spam Filter
    • Recommendation Engine
    • Trust Score
    • Web3 Social Actions based on data from Airstack’s API
  • Token Gating
  • On-chain Data-Driven Airdrops
  • Airstack Abstractions as dApps
  • Web3 Marketing Technology, etc.

Resources

About Phala

Phala Network is a decentralized cloud that offers secure and scalable computing for Web3.

With Phat Contracts, an innovative programming model enabling trustless off-chain computation, developers can create new Web3 use cases.

Get the latest Phala Content Straight To Your Inbox.