Skip to content

Commit 12cb732

Browse files
committed
docs(fix) squashed fixup commits here
1 parent 13a7f77 commit 12cb732

File tree

9 files changed

+160
-162
lines changed

9 files changed

+160
-162
lines changed

cartesi-rollups_versioned_docs/version-2.0/api-reference/backend/vouchers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ emit_voucher("mint(address)", "0x784f0c076CC55EAD0a585a9A13e57c467c91Dc3a", ["ad
5454
<pre><code>
5555

5656
```javascript
57-
import { stringToHex, encodeFunctionData, erc20Abi } from "viem";
57+
import { stringToHex, encodeFunctionData, erc20Abi, zeroHash } from "viem";
5858

5959
async function handle_advance(data) {
6060
console.log("Received advance request data " + JSON.stringify(data));
@@ -70,7 +70,7 @@ async function handle_advance(data) {
7070
let voucher = {
7171
destination: erc20Token,
7272
payload: call,
73-
value: '0x',
73+
value: zeroHash,
7474
};
7575

7676
await emitVoucher(voucher);

cartesi-rollups_versioned_docs/version-2.0/development/asset-handling.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,96 @@ The application’s off-chain layer often requires knowledge of its address to f
5252

5353
By calling [`relayDAppAddress()`](../api-reference/json-rpc/relays/relays.md), function of the `DAppAddressRelay` contract, it adds the dApp’s address as a new input for the Cartesi dApp to process. Next, the off-chain machine uses this address to generate a voucher for execution at the [`executeVoucher()`](../api-reference/json-rpc/application.md/#executevoucher) function of the `CartesiDApp` contract.
5454

55+
Below is a sample JavaScript code with the implementations to transfer tokens to whoever calls the application, notice that the `const call` variable is an encoded function data containing the token contract ABI, function name and also arguments like recipient and amount, while the actual `voucher` structure itself contains a destination (erc20 token contract where the transfer execution should occur), the payload (encoded function data in `call`) and finally a value field which is initialized to `0` meaning no Ether is intended to be sent alongside this transfer request.
56+
57+
```javascript
58+
import { stringToHex, encodeFunctionData, erc20Abi, hexToString, zeroHash } from "viem";
59+
60+
const rollup_server = process.env.ROLLUP_HTTP_SERVER_URL;
61+
console.log("HTTP rollup_server url is " + rollup_server);
62+
63+
async function handle_advance(data) {
64+
console.log("Received advance request data " + JSON.stringify(data));
65+
66+
const sender = data["metadata"]["msg_sender"];
67+
const payload = hexToString(data.payload);
68+
const erc20Token = "0x784f0c076CC55EAD0a585a9A13e57c467c91Dc3a"; // Sample ERC20 token address
69+
70+
const call = encodeFunctionData({
71+
abi: erc20Abi,
72+
functionName: "transfer",
73+
args: [sender, BigInt(10)],
74+
});
75+
76+
let voucher = {
77+
destination: erc20Token,
78+
payload: call,
79+
value: zeroHash,
80+
};
81+
82+
await emitVoucher(voucher);
83+
return "accept";
84+
}
85+
86+
const emitVoucher = async (voucher) => {
87+
try {
88+
await fetch(rollup_server + "/voucher", {
89+
method: "POST",
90+
headers: {
91+
"Content-Type": "application/json",
92+
},
93+
body: JSON.stringify(voucher),
94+
});
95+
} catch (error) {
96+
//Do something when there is an error
97+
}
98+
};
99+
```
100+
55101
### Withdrawing Ether
56102

57103
To execute Ether withdrawal it is important to emit a voucher with the necessary details as regarding whom you intend to send the Ether to and also the amount to send, nevertheless since the Application contract Executes vouchers by making a [safeCall](https://github.com/cartesi/rollups-contracts/blob/cb52d00ededd2da9f8bf7757710301dccb7d536d/src/library/LibAddress.sol#L18C14-L18C22) to the destination, passing a value (Ether amount to send along with the call) and a payload (function signature to call), it's acceptable to leave the payload section empty if you do not intend to call any functions in the destination address while sending just the specified value of Ether to the destination address. If you intend to call a payable function and also send Ether along, you can add a function signature matching the payable function you intend to call to the payload field.
58104

105+
Below is another sample JavaScript code, this time the voucher structure has been modified to send ether to an address instead of calling a function in a smart contract, notice there is no `encodedFunctionData`, so the payload section is initialized to zeroHash.
106+
107+
```javascript
108+
import { stringToHex, encodeFunctionData, erc20Abi, hexToString, zeroHash, parseEther } from "viem";
109+
110+
const rollup_server = process.env.ROLLUP_HTTP_SERVER_URL;
111+
console.log("HTTP rollup_server url is " + rollup_server);
112+
113+
async function handle_advance(data) {
114+
console.log("Received advance request data " + JSON.stringify(data));
115+
116+
const sender = data["metadata"]["msg_sender"];
117+
const payload = hexToString(data.payload);
118+
119+
120+
let voucher = {
121+
destination: sender,
122+
payload: zeroHash,
123+
value: numberToHex(BigInt(parseEther("1"))).slice(2),
124+
};
125+
126+
await emitVoucher(voucher);
127+
return "accept";
128+
}
129+
130+
const emitVoucher = async (voucher) => {
131+
try {
132+
await fetch(rollup_server + "/voucher", {
133+
method: "POST",
134+
headers: {
135+
"Content-Type": "application/json",
136+
},
137+
body: JSON.stringify(voucher),
138+
});
139+
} catch (error) {
140+
//Do something when there is an error
141+
}
142+
};
143+
```
144+
59145
:::note epoch length
60146
By default, Cartesi nodes close one epoch every 7200 blocks. You can [manually set the epoch length](./cli-commands.md/#run) to facilitate quicker asset-handling methods.
61147
:::

cartesi-rollups_versioned_docs/version-2.0/development/building-and-running-an-application.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

cartesi-rollups_versioned_docs/version-2.0/development/creating-an-application.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Cartesi CLI has templates for the following languages – `cpp`, `cpp-low-level`
3535
:::note Libraries for simplifying development
3636
We have high-level framework and alternative templates that simplify development and enhances input management, providing a smoother and more efficient experience.
3737
For Go use Rollmelette, for Rust use Crabrolls, for Python use python-Cartesi and for Typescript/Javascrips use Deroll.
38+
Visit this [page](../resources/community-tools.md) to learn more about these and other available tools.
3839
:::
3940

4041
## Implementing your application Logic
@@ -61,7 +62,7 @@ Below is a sample application that has been modified to include the logic to sim
6162

6263
```javascript
6364

64-
import { stringToHex, encodeFunctionData, erc20Abi, hexToString } from "viem";
65+
import { stringToHex, encodeFunctionData, erc20Abi, hexToString, zeroHash } from "viem";
6566

6667
const rollup_server = process.env.ROLLUP_HTTP_SERVER_URL;
6768
console.log("HTTP rollup_server url is " + rollup_server);
@@ -85,7 +86,7 @@ async function handle_advance(data) {
8586
let voucher = {
8687
destination: erc20Token,
8788
payload: call,
88-
value: '0x',
89+
value: zeroHash,
8990
};
9091

9192
await emitVoucher(voucher);

cartesi-rollups_versioned_docs/version-2.0/development/running-an-application.md

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,98 @@ resources:
66
title: CartesiScan
77
---
88

9-
Running your application creates a docker container containing all required services, and exposes your application node on port `6751`, then an anvil network specific to your application on port `6751/anvil`. The node also logs all outputs received by your backend.
9+
Running an application locally mimics the process of deploying an application to production on a testnet or mainnet environment. When working locally, your application’s smart contracts are deployed to an Anvil network, which acts as a local Ethereum environment. The main difference is that your application node runs on your own machine using Docker, rather than on a remote server. Running an application involves two main phases: first, you build your application, and then you deploy it to your local development network (devnet). This process allows you to test and debug your application in an environment that closely resembles the real blockchain, making it easier to catch issues early and ensure a smooth deployment to production later.
1010

11-
Here are the prerequisites to run the node:
11+
## Building the application
1212

13-
- Docker Engine must be active.
14-
- Cartesi machine snapshot successfully built with `cartesi build`.
13+
“Building” in this context compiles your application into RISC-V architecture, this architecture enables computation done by your application to be reproducible and verifiable. While "Running" encompasses the process of publishing your application to your local node running on docker and also deploying the necessary contracts for your application to a local Anvil devnet.
1514

16-
To start the node, run:
15+
With the Docker engine running, CD into your application and build by running:
1716

1817
```shell
19-
cartesi run
18+
cartesi build
2019
```
2120

22-
Response:
21+
The successful execution of this step will log this in your terminal:
2322

2423
```shell
25-
[+] Pulling 4/0
26-
✔ proxy Skipped - Image is already present locally 0.0s
27-
✔ database Skipped - Image is already present locally 0.0s
28-
✔ rollups-node Skipped - Image is already present locally 0.0s
29-
✔ anvil Skipped - Image is already present locally 0.0s
30-
✔ demo-application starting at http://127.0.0.1:6751
31-
✔ anvil service ready at http://127.0.0.1:6751/anvil
32-
✔ rpc service ready at http://127.0.0.1:6751/rpc
33-
✔ inspect service ready at http://127.0.0.1:6751/inspect/demo-application
34-
✔ demo-application machine hash is 0xa3ca2e40420f3c2424ca95549b6c16fd9b11c27d76b8ef9ae9bf78cde36829fc
35-
✔ demo-application contract deployed at 0xa083af219355288722234c47d4c8469ca9af6605
36-
(l) View logs (b) Build and redeploy (q) Quit
37-
```
38-
39-
This command runs your backend compiled to RISC-V and packages it as a Cartesi machine. It is therefore important that after every code update, the application needs to be rebuilt then the run command executed again, the Cartesi CLI makes this process very easy and all you need do is hit the `<b>` button on your keyboard to trigger a rebuild and run command.
40-
41-
:::troubleshoot troubleshooting common errors
42-
43-
#### Error: Depth Too High
4424

45-
```shell
46-
Attaching to 2bd74695-prompt-1, 2bd74695-validator-1
47-
2bd74695-validator-1 | Error: DepthTooHigh { depth: 2, latest: 1 }
48-
2bd74695-validator-1 | Error: DepthTooHigh { depth: 2, latest: 1 }
25+
.
26+
/ \
27+
/ \
28+
\---/---\ /----\
29+
\ X \
30+
\----/ \---/---\
31+
\ / CARTESI
32+
\ / MACHINE
33+
'
34+
35+
[INFO rollup_http_server] starting http dispatcher service...
36+
[INFO rollup_http_server::http_service] starting http dispatcher http service!
37+
[INFO actix_server::builder] starting 1 workers
38+
[INFO actix_server::server] Actix runtime found; starting in Actix runtime
39+
[INFO rollup_http_server::dapp_process] starting dapp: dapp
40+
Sending finish
41+
42+
Manual yield rx-accepted (1) (0x000020 data)
43+
Cycles: 69709199
44+
69709199: 9e0420c0fda1a5dc9256b3f9783b09f207e5222a88429e91629cc2e495282b35
45+
Storing machine: please wait
4946
```
5047
51-
This indicates that the node is reading blocks too far behind the current blockchain state.
48+
### Memory
5249
53-
#### Solution
50+
To change the default memory size for the Cartesi Machine, you can personalize it by adding a specific label in your Dockerfile.
5451
55-
Create or modify a `.cartesi.env` file in your project directory and set:
52+
The line below lets you define the memory size in megabytes (MB):
5653
57-
```shell
58-
TX_DEFAULT_CONFIRMATIONS=1
54+
```dockerfile
55+
LABEL io.cartesi.rollups.ram_size=128Mi
5956
```
6057
61-
This adjustment should align the node's block reading with the blockchain's current state.
62-
58+
:::note environment variables
59+
You can create a `.cartesi.env` in the project's root and override any variable controlling the rollups-node.
6360
:::
6461

65-
### Overview of Node Services
62+
## Deploying the application to devnet
6663

67-
The `cartesi run` command activates several services essential for node operation: some of these services are not activated by default and can be activated by adding them to the `--service` flag when starting your application. The below command starts your application with all available services:
64+
Running the deployment command compiles your application and publishes it to the node running in the devnet environment. It also deploys the required authority and application contracts to the local Anvil network.
6865

69-
```shell
70-
cartesi run --services explorer,graphql,bundler,paymaster,passkey
71-
```
66+
You can deploy multiple applications to this environment. For each application, you can either create a new authority contract or link it to an existing one.
7267

73-
Each of these services runs independently and can be activated or deactivated at will by simply including or removing them from the list of services while running your application. Below is a breakdown of these services and their default URL's.
68+
Prerequisites for Deployment
69+
Before deploying your application, ensure the following:
7470

75-
- **Anvil Chain**: Runs a local blockchain available at `http://localhost:6751/anvil`.
71+
- Docker Engine is active.
72+
- The Devnet environment is running.
73+
- A Cartesi machine snapshot has been successfully built using `cartesi build`.
7674

77-
- **GraphQL Playground**: An interactive IDE at `http://localhost:6751/graphql` for exploring the GraphQL server.
75+
Once these prerequisites are met, proceed to deploy your application by running:
7876

79-
- **Explorer**: Monitors Rollups application activity and manages transactions via `http://localhost:6751/explorer`.
77+
```shell
78+
cartesi deploy
79+
```
8080

81-
- **Inspect**: A diagnostic tool accessible at `http://localhost:6751/inspect/<app_name>` to inspect the node’s state.
81+
This command compiles your backend to RISC-V, packages it as a Cartesi machine, then publishes it to the node running on the devnet.
8282

83-
- **Bundler**: A server accessible at `http://localhost:6751/bundler/rpc` to enable account abstraction by providing an alternative mempool for receiving and bundling user operations.
83+
During deployment, you'll have to specify:
8484
85-
- **Paymaster**: An account abstraction implementation that works hand in hand with the bundler to sponsor gas fees for transactions handled by the bundler, available at `http://localhost:6751/paymaster`.
85+
- Private key or Mnemonic to fund the deployment.
86+
- The authority owner address.
87+
- The application owner address.
88+
- An application name (making it easier to identify your application instead of relying on the contract address).
8689
87-
- **Passkey**: Runs a local passkey server, that enables account generation and interaction with application without a traditional wallet, available at `http://localhost:6751/passkey`
90+
Once the deployment is complete, you should have logs similar to the following:
8891
89-
:::note Testing tools
90-
[NoNodo](https://github.com/Calindra/nonodo) is a Cartesi Rollups testing tool that works with host machine applications, eliminating the need for Docker or RISC-V compilation.
91-
:::
92+
```shell
93+
✔ Cartesi machine template hash 0x9e0420c0fda1a5dc9256b3f9783b09f207e5222a88429e91629cc2e495282b35
94+
✔ Wallet Mnemonic
95+
✔ Mnemonic test test test test test test test test test test test junk
96+
✔ Account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 9994.000195973381758124 ETH
97+
✔ Authority Owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
98+
✔ Application Owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
99+
✔ Application 0x1Db6DdECF18095847f7099cfAc43A2671326d21c
100+
✔ Machine snapshot /var/lib/cartesi-rollups-node/snapshots/0x9e0420c0fda1a5dc9256b3f9783b09f207e5222a88429e91629cc2e495282b35/
101+
✔ Application Name counter
102+
✔ Registration counter
103+
```

0 commit comments

Comments
 (0)