Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ Welcome to the **Cartesi Chronicle Integration** repository! This template is a
2. **Introduction to Chronicle**
3. **Understanding Oracle Usage**
4. **Deploying the Contracts**
5. **Setting Up the Backend**
6. **Mounting the Frontend**
7. **Showcase: The dApp in Action**
5. **Mounting the Frontend**
6. **Showcase: The dApp in Action**

----------

Expand All @@ -51,7 +50,8 @@ Before diving into the code, it's important to understand how oracles work and h

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.

![chronicle](https://github.com/user-attachments/assets/a97f8e91-6b18-4f2e-9b02-4596cc8a68a0)
![chronicle (1)](https://github.com/user-attachments/assets/16f65e77-d50f-4acd-bc76-ab914ca255de)



## 4. Deploying the Contracts
Expand All @@ -73,7 +73,7 @@ The contract (`OracleCartesiReader.sol`) is responsible for fetching data from t
- 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.

## 6. Mounting the Frontend
## 5. Mounting the Frontend

1. **Navigate to Frontend Directory:**

Expand All @@ -83,22 +83,18 @@ The contract (`OracleCartesiReader.sol`) is responsible for fetching data from t

`npm install`

3. **Update Contract Address:**

- In your frontend code, locate the part where the contract address is defined.
- Replace the placeholder address with the actual address of the deployed `OracleCartesiReader` contract on Sepolia.
4. **Run the Frontend:** Start the frontend application.
3. **Run the Frontend:** Start the frontend application.

`npm run dev`

This will launch the React application that interacts with your deployed smart contract.


## 7. Showcase: The dApp in Action
## 6. Showcase: The dApp in Action

Once everything is set up, navigate to your front-end application in the browser. Here's what you should be able to do:

- **Submit Data:** Enter a string in the input field and submit it. The front end will send this string, along with data fetched from the Chronicle oracle, to the deployed smart contract.
- **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.

Expand Down
11 changes: 11 additions & 0 deletions backend-V1.5/backend-javascript/---Dockerfile.fly
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20-bookworm-slim

WORKDIR /app
COPY package.json yarn.lock ./
RUN corepack enable && yarn install --frozen-lockfile

COPY . .
RUN yarn build

EXPOSE 8080
CMD ["yarn", "start"]
File renamed without changes.
4 changes: 4 additions & 0 deletions backend-V1.5/backend-javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cartesi
/dist
/node_modules
/guide.txt
48 changes: 48 additions & 0 deletions backend-V1.5/backend-javascript/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# syntax=docker.io/docker/dockerfile:1

# build stage: includes resources necessary for installing dependencies

# Here the image's platform does not necessarily have to be riscv64.
# If any needed dependencies rely on native binaries, you must use
# a riscv64 image such as cartesi/node:20-jammy for the build stage,
# to ensure that the appropriate binaries will be generated.
FROM node:20.16.0-bookworm AS build-stage

WORKDIR /opt/cartesi/dapp
COPY . .
RUN yarn install && yarn build

# runtime stage: produces final image that will be executed

# Here the image's platform MUST be linux/riscv64.
# Give preference to small base images, which lead to better start-up
# performance when loading the Cartesi Machine.
FROM --platform=linux/riscv64 cartesi/node:20.16.0-jammy-slim

ARG MACHINE_EMULATOR_TOOLS_VERSION=0.14.1
ADD https://github.com/cartesi/machine-emulator-tools/releases/download/v${MACHINE_EMULATOR_TOOLS_VERSION}/machine-emulator-tools-v${MACHINE_EMULATOR_TOOLS_VERSION}.deb /
RUN dpkg -i /machine-emulator-tools-v${MACHINE_EMULATOR_TOOLS_VERSION}.deb \
&& rm /machine-emulator-tools-v${MACHINE_EMULATOR_TOOLS_VERSION}.deb

LABEL io.cartesi.rollups.sdk_version=0.9.0
LABEL io.cartesi.rollups.ram_size=128Mi

ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get update
apt-get install -y --no-install-recommends \
busybox-static=1:1.30.1-7ubuntu3
rm -rf /var/lib/apt/lists/* /var/log/* /var/cache/*
useradd --create-home --user-group dapp
EOF

ENV PATH="/opt/cartesi/bin:${PATH}"

WORKDIR /opt/cartesi/dapp
COPY --from=build-stage /opt/cartesi/dapp/dist .

ENV ROLLUP_HTTP_SERVER_URL="http://127.0.0.1:5004"

ENTRYPOINT ["rollup-init"]
CMD ["node", "index.js"]
4 changes: 4 additions & 0 deletions backend-V1.5/backend-javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# JavaScript DApp Template

This is a template for JavaScript Cartesi DApps. It uses node to execute the backend application.
The application entrypoint is the `src/index.js` file. It is bundled with [esbuild](https://esbuild.github.io), but any bundler can be used.
35 changes: 35 additions & 0 deletions backend-V1.5/backend-javascript/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
app = "chainlink2"

[build]
image = "registry.fly.io/chainlink2"

[http_service]
internal_port = 10000
force_https = true

[http_service.concurrency]
type = "requests"
soft_limit = 200
hard_limit = 250

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "5s"
path = "/healthz"

[[vm]]
size = "shared-cpu-1x"
memory = "2gb"

[env]
CARTESI_BLOCKCHAIN_FINALITY_OFFSET = "1"
CARTESI_BLOCKCHAIN_ID = "11155111"
CARTESI_CONTRACTS_APPLICATION_ADDRESS = "0x469459C134101c14B76B347BE2ca33a69c77a127"
CARTESI_CONTRACTS_AUTHORITY_ADDRESS = "0x56A3EBabEE3a284f33FAa809291b3207b57e6fDf"
CARTESI_CONTRACTS_HISTORY_ADDRESS = "0x0E97C1f8E04CC4236328A1BD0918318cbd6f56aF"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS = "0x59b22D57D4f067708AB0c00552767405926dc768"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER = "3963384"
CARTESI_EPOCH_LENGTH = "7200"

19 changes: 19 additions & 0 deletions backend-V1.5/backend-javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "my-dapp",
"version": "0.1.0",
"description": "JS DApp",
"dependencies": {
"ethers": "^6.7.1"
},
"devDependencies": {
"esbuild": "^0.19.2"
},
"scripts": {
"build": "esbuild ./src/index.js --bundle --outfile=dist/index.js --platform=node --target=node20",
"start": "ROLLUP_HTTP_SERVER_URL=\"http://127.0.0.1:5004\" node src/index.js"
},
"keywords": [
"cartesi"
],
"license": "MIT"
}
87 changes: 87 additions & 0 deletions backend-V1.5/backend-javascript/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// XXX even though ethers is not used in the code below, it's very likely
// it will be used by any DApp, so we are already including it here
const { ethers } = require("ethers");


let last_price = 0;
const rollup_server = process.env.ROLLUP_HTTP_SERVER_URL;
console.log("HTTP rollup_server url is " + rollup_server);

async function handle_advance(data) {
console.log("Received advance request data " + JSON.stringify(data));
try {
last_price = data.payload;
console.log("New price is " + last_price);
const response = await createNotice(data);
console.log(`Notice created successfully: ${JSON.stringify(data)}. Return code is: ${response.status}`);
return "accept";
} catch (error) {
console.log(`Notice was not created: ${error}`);
return "reject";
}
}

async function handle_inspect(data) {
console.log("Received inspect request data " + JSON.stringify(data));
const response = await createReport(last_price);
return "accept";
}

async function createNotice(data) {
try {
const response = await fetch(rollup_server + '/notice', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ payload: data.payload })
});
return response;
} catch (error) {
throw error;
}
}

async function createReport(data) {
try {
const response = await fetch(rollup_server + '/report', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ payload: data })
});
return response;
} catch (error) {
throw error;
}
}

var handlers = {
advance_state: handle_advance,
inspect_state: handle_inspect,
};

var finish = { status: "accept" };

(async () => {
while (true) {
const finish_req = await fetch(rollup_server + "/finish", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ status: "accept" }),
});

console.log("Received finish status " + finish_req.status);

if (finish_req.status == 202) {
console.log("No pending rollup request, trying again");
} else {
const rollup_req = await finish_req.json();
var handler = handlers[rollup_req["request_type"]];
finish["status"] = await handler(rollup_req["data"]);
}
}
})();
Loading