This DApp shows how to parse ERC-20 deposits sent by the ERC-20 Portal, which is where all legitimate ERC-20 deposits come from, and how to issue vouchers so the amount deposited can be withdrawn later on.
A deposit must have a payload, whose format is defined at the ERC-20 Portal contract, which is part of the Cartesi Rollups contract.
Any input that either does not come from the Portal or is malformed will be rejected.
After the deposit is properly parsed, the application issues a voucher to return the amount back to the depositor ("I don't want your money!"). This voucher can then be executed to withdraw the amount from the Portal and recover the assets.
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, perform a deposit of some SimpleERC20
tokens as follows:
yarn start erc20 deposit --amount 100
Contract
SimpleERC20
is provided by thecommon-contracts
project and is deployed automatically to the localhost network.
In order to verify the notices generated by your inputs, run the command:
yarn start notice list
The payload of the notice should be something like this:
"Deposit received from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266; ERC-20: 0xa513e6e4b8f2a923d98304ec87f64353c4d5c853; Amount: 100"
In order to check the voucher generated for the deposit, execute the following command:
yarn start voucher list
The voucher may be executed to return the funds to the depositor by following the instructions available at Validating notices and executing vouchers.
This DApp's back-end is written in Python, so to run it in your machine you need to have python3
installed.
In order to start the back-end, run the following commands in a dedicated terminal:
cd erc20/
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
ROLLUP_HTTP_SERVER_URL="http://127.0.0.1:5004" python3 erc20.py
The final command will effectively run the back-end and send corresponding outputs to port 5004
.
It can optionally be configured in an IDE to allow interactive debugging using features like breakpoints.
You can also use a tool like entr to restart the back-end automatically when the code changes. For example:
ls *.py | ROLLUP_HTTP_SERVER_URL="http://127.0.0.1:5004" entr -r python3 erc20.py
After the back-end successfully starts, it should print an output like the following:
INFO:__main__:HTTP rollup_server url is http://127.0.0.1:5004
INFO:__main__:Sending finish
After that, you can interact with the application normally as explained above.
Deploying DApps to a testnet and running corresponding validator nodes are described in the main README.
However, for this DApp the command to run the validator node needs to be slightly different because of the additional configuration for common-contracts
, which is used in the local development environment.
As such, for this DApp the final command to run the node should specify the testnet-specific docker compose override, as follows:
DAPP_NAME=erc20 docker compose --env-file ../env.<network> -f ../docker-compose-testnet.yml -f ./docker-compose-testnet.override.yml up
In the case of Sepolia, the command would be:
DAPP_NAME=erc20 docker compose --env-file ../env.sepolia -f ../docker-compose-testnet.yml -f ./docker-compose-testnet.override.yml up