Quickstart
Get started to build on Pragma
You can get started with Pragma in just a few minutes. This guide will walk you through the process of consuming data from Pragma’s oracle network. Here is a simple contract allowing a user to retrieve the price of an asset, using the Pragma Oracle.
Add Pragma as a dependency to your scarb/snforge project
Overview of the contract
Let’s break down the code above:
Firstly, we defined the interface of our contract. The interface is a set of functions that can be called by other contracts. In this case, we have only one function, get_asset_price
, which takes as input the asset id of the asset we want to retrieve the price of, and returns the price of the asset. The asset id is a felt252, and can be converted from a string using the felt252
conversion. The asset id is used to identify the data feed we want to retrieve (for example BTC/USD).
Then comes the contract itself:
This is the general form of a starknet contract, you can learn more about the way to build a Starknet contract here. The notable point here is among the imports:
This line imports the dispatcher corresponding to the oracle contract interface and its associated trait. The dispatcher enables the invocation of interface-defined functions. For deeper insights into the dispatcher and its trait, consult the cairo book.
Allows the imports of the required structures/enums for executing the function call. These three are the main structures/enums used in most functions of the Pragma oracle contract. The AggregationMode
enum is used to specify the aggregation mode of the data, the DataType
enum is used to specify the type of data to be retrieved, and the PragmaPricesResponse
structure is used to store the response to the function call.
We deploying the contract, you will have to specify the oracle contract address and the summary stats contract address. The summary stats is a contract providing computational feeds (TWAP, Yield Curve, Realized Volatility, …). In the provided example we will not use the summary stats contract. The oracle address can be found here. The previous contract is a simple contract, allowing a user to retrieve the price of an asset. You can play with a more complete example and deploy using Remix.
Working with Remix
Activate the Starknet Plugin
To begin with, you will have to activate the Starknet plugin:
Compile the Code
Once the Starknet plugin is activated, the Starknet icon should appear on the left side of the screen. You will then need to compile the code:
Interact with the Contract
Once deployed, you can interact with the contract:
🎉 Congratulations! You have used Pragma!
Was this page helpful?