Welcome to the Cartesi Chronicle Integration repository! This template is a starting point for integrating Chronicle oracles with Cartesi Rollups. In this tutorial, we'll walk you through setting up the backend and frontend for a decentralized application (dApp) that fetches data from Chronicle oracles and processes it using Cartesi Rollups.
- backend: Contains the dApp backend. The template is a simple echo written in python.
- frontend: The React-based frontend that interacts with the Cartesi Rollups via the deployed smart contract.
- contracts: Solidity smart contracts for integrating Chronicle oracles and Cartesi InputBox.
- Introduction to Cartesi
- Introduction to Chronicle
- Understanding Oracle Usage
- Deploying the Contracts
- Mounting the Frontend
- Showcase: The dApp in Action
Cartesi is a layer-2 solution that allows developers to run complex computations off-chain, leveraging a Linux environment to process data in a scalable and secure manner. By using Cartesi Rollups, you can offload heavy processing from the blockchain, ensuring that your dApps are both cost-effective and performant.
Chronicle provides decentralized oracles that deliver secure, reliable, and immutable data feeds to smart contracts. In DeFi and other blockchain-based applications, oracles are essential for fetching external data, such as asset prices or weather conditions, used within smart contracts to execute logic based on real-world information.
Before diving into the code, it's important to understand how oracles work and how they are used within smart contracts:
-
Oracle Basics: Oracles act as a bridge between off-chain data and on-chain smart contracts, fetching data from the outside world and delivering it to the blockchain tamper-proof.
-
Deploying to Sepolia: Once you've tested your integration locally, you must deploy the contracts to a public testnet like Sepolia to feed real-time data into your dApp.
So the integration happens with the usage of the contracts/OracleCartesiReader.sol contract. It is responsible to integrate all the necessary to collect the data from the Chronicle Oracle and feed the InputBox contract which is responsible for receive the dApp inputs for Cartesi Aplications.
- Open Remix: Go to Remix IDE.
- Create a New File: In Remix, create a new Solidity file (
OracleCartesiReader.sol), and paste the contract code from thecontractsfolder. - Compile the Contract: Select the appropriate Solidity compiler version (e.g., 0.8.18) and compile the contract.
- Deploy to Sepolia:
- Connect your MetaMask wallet to Sepolia.
- Deploy the contract using Remix’s Deploy & Run module.
- Make a note of the deployed contract address; you'll need it for the front end.
The contract (OracleCartesiReader.sol) is responsible for fetching data from the Chronicle oracle and sending it to Cartesi Rollups via the InputBox.
- Follow the steps above to deploy this contract using Remix or your preferred method.
- Follow the https://docs.cartesi.io/cartesi-rollups/1.5/deployment/introduction/ to deploy the code backend. You can either store the node in fly.io or run it locally. You will need it running when you run the frontend to send information.
-
Navigate to Frontend Directory:
cd frontend -
Install Frontend Dependencies:
npm install -
Run the Frontend: Start the frontend application.
npm run devThis will launch the React application that interacts with your deployed smart contract.
Once everything is set up, navigate to your front-end application in the browser. Here's what you should be able to do:
-
Submit transaction: Submit a transaction from the frontend. The front end will send a transaction to fetch the price feed from the Chronicle oracle, to the deployed smart contract.
-
Data Processing: The data is then processed by Cartesi Rollups, simulating complex off-chain computation.
-
View Results: After processing, view the results in your front end and verify that the integration between Chronicle Oracles and Cartesi Rollups functions correctly.
