This example represents a complete project that implement the feature offered by the CartesiVM to execute arbitrary code from a smart contract. This example allows to understand the power of composability whitin Cartesi.
The main goal of this POC is to give an idea that Cartesi can be used also to execute specific code inside a more complex architecture written in solidity (or any other smart contract language).
Each application can be executed in Production and Host modes, as explained below.
In this mode, the DApp's back-end logic is executed inside a Cartesi Machine, meaning that its code is compiled to the machine's RISC-V architecture. This ensures that the computation performed by the back-end is reproducible and hence verifiable, enabling a truly trustless and decentralized execution.
After building an example as described in the previous section, you can run it in production mode by executing:
cd <example>
docker compose -f ./docker-compose.base.yml -f ./docker-compose.override.yml up
Allow some time for the infrastructure to be ready. How much will depend on your system, but eventually the container logs will only show the continuous production of empty blocks in the local blockchain, as displayed below:
rollups-examples-hardhat-1 | Mined empty block range #32 to #33
rollups-examples-hardhat-1 | Mined empty block range #32 to #34
rollups-examples-hardhat-1 | Mined empty block range #32 to #35
rollups-examples-hardhat-1 | Mined empty block range #32 to #36
The environment can be shut down with the following command:
docker compose -f ./docker-compose.base.yml -f ./docker-compose.override.yml down -v
We can use the frontend-console application to interact with the DApp. Ensure that the application has already been built before using it.
First, go to a separate terminal window and switch to the frontend-console
directory:
cd frontend-console
Then, send an input as follows:
yarn start input send --payload '{"address":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "body":"1+4"}'
In order to verify the notices generated by your inputs, run the command:
yarn start notice list
The payload of the notice should be composed with an address and a body.
The address should be formatted ad follow "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
.
The body will be the code that will be evaluated in the CartesiVM "1+4"
When executing an example, it is possible to advance time in order to simulate the passing of epochs. To do that, run:
curl --data '{"id":1337,"jsonrpc":"2.0","method":"evm_increaseTime","params":[864010]}' http://localhost:8545
https://github.com/cartesi/rollups-examples/tree/main/frontend-console