Getting started tutorial
Getting Started with Quex
Introduction
Quex provides a protocol and infrastructure for decentralized data transfer based on confidential computing. The most simple of these for developers is data oracle, and that’s what we’ll be learning about today. In this guide, we’ll be conceptualizing, understanding and building a basic parametric emission token, which will give you some idea of how to use Quex for accessing verifiable data on-chain.
Document Structure
This tutorial is organized into the following sections:
Introduction: Provides an overview of Quex and explains what we're building.
Try it Out: Quick start instructions to deploy and run the provided example.
Let’s Create a Quex-based Contract: Step-by-step instructions to set up your environment and implement smart contracts leveraging Quex.
Prepare Environment: How to configure your development environment.
Token Emission: Detailed implementation of ERC-20 token emission logic.
Create Flow: Defines how data requests are structured and handled by Quex oracle pools.
Deploy and Run: Guide to deploying the contracts and executing the request to mint tokens.
Next Steps: Recommendations on further exploration and advanced use cases.
What Are We Building?
Try it Out
This repository also provides scripts that help you deploy the contracts and make requests to the Quex data oracle, triggering token minting. To deploy these contracts, you’ll need the private key of a wallet holding sufficient gas tokens for your chosen network. Set your private key as an environment variable for convenience:
Build and Deploy Contracts
Run the DeployTVLEmissionScript to build and deploy the ERC-20 token, the token emission contract, and to set up the data flow for verifiable Quex HTTPS responses:
You’ll need the deployed contract address for making requests. Store the deployed contract’s address as an environment variable:
Make a Request
Next, make a request using the provided script:
Check Your Balance
Now, verify your wallet balance—you should receive freshly minted TVLT tokens, equal in amount to the current TVL of the DyDx protocol!
Congratulations! You've successfully deployed your first contract that relies on confidential computing proofs to bring off-chain data to your contract. In the following sections, we'll provide a detailed explanation of what's happening under the hood of our contracts. This will give you insights and ideas for building your own Quex-based smart contracts.
Let’s Create a Quex-based Contract!
Prepare Environment
We’ll also use the ERC-20 implementation from OpenZeppelin and Quex libraries to simplify our development:
Token emission
Next, let's create a new contract ParametricToken.sol
in src folder with the following code:
As you can see, this is a standard ERC-20 token with one modification: only the contract owner can mint new tokens. In our scenario, ownership of this token contract will belong to another contract.
Let’s create that contract, TVLEmission.sol
, next:
Let’s briefly summarize what’s happening here:
The contract imports and inherits from
QuexRequestManager
, which simplifies interactions with Quex oracle pools and performs the necessary response verification.The
processResponse
method is implemented as a callback, which securely processes responses from the Quex oracle. It includes a cooldown period to limit request frequency and uses theverifyResponse
modifier to protect against oracle manipulation attacks.
At this point, we should make a side note regarding Quex architecture. Although Quex supports classic pull- and push-based data oracles, under the hood, all of them rely on callback mechanics. In our example, we use the fastest and most cost-efficient callback scenario, particularly useful when you need to process data directly upon receiving it.
However, though we've defined a processResponse
function to verify proofs and process responses, we haven't yet defined the data flow—the exact HTTPS request the oracle pool should perform and the necessary supporting information. We'll cover this in the next section.
Create Flow
To achieve this, create a setUpFlow()
function as follows and invoke it from the constructor:
Let's go through the setUpFlow()
method step by step. We'll use the FlowBuilder
helper here, which simplifies flow registration by asking us to define only the necessary fields.
Finally, we need to define what happens when the response is ready. We do this using three fields: the oracle pool's address (consumer
), the callback function (callback
) to handle the incoming data, and a gasLimit
for executing the callback. After defining these parameters, we call createFlow()
to register our flow in the Quex registry, and store the returned identifier via setFlowId()
for verifying incoming data later.
Deploy and Run
That's it!
Next Steps
Congratulations on deploying your very first contract that relies on data secured by confidential computing proofs! You can explore further by visiting other sections of our documentation to learn how to build more complex examples and create the next generation of DApps connected to real-world data.
Last updated