Skip to content

Wallet Abstraction

Overview

The WalletAbstraction application is a robust example that demonstrates handling deposits, withdrawals, and balance inspections for Ether, ERC20, ERC721, and ERC1155 tokens using the Crabrolls framework. This document details the application’s usage, including how to send JSON-based inputs and inspect outputs. You can find the source code in the CrabRolls repository.

Usage

The application allows you to interact with various token standards by sending JSON-encoded messages. These can be executed using the send command from the Cartesi CLI tool. Below are examples for different operations.

Depositing new assets

To make deposits into the application, use the cartesi CLI to send a asset deposit to the respective portal. Send this input using the send command and provide the data of deposit:

Terminal
cartesi send ether --amount 8

Ether Operations

Withdrawing Ether

To withdraw all Ether from the sender’s account, use the following JSON input:

Template
{
"kind": "ether",
"metadata": {}
}

Send this input using the send command:

Terminal
cartesi send generic --input='{
"kind": "ether",
"metadata": {}
}'

Now you can view the voucher in the Cartesi Explorer and execute the withdrawal.

Inspecting Ether Balance

To inspect the Ether balance of a specific address, use the following JSON input:

Template
{
"kind": "ether",
"metadata": {
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}

Send this input using the curl command to inspect the application:

Terminal
curl 'http://localhost:8080/inspect' \
-H 'Content-Type: application/json' \
-d \ '{
"kind": "ether",
"metadata": {
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}' \
| jq

Example of the response:

Response
{
"exception_payload": "0x",
"processed_input_count": 1,
"reports": [
{
"payload": "0x31303030303030303030303030303030303030"
}
],
"status": "Accepted"
}

Using the command cast from foundry you can decode the response payload 0x30:

Terminal
cast to-ascii 0x31303030303030303030303030303030303030

Returning in this case the balance of the address 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef.

Response
1000000000000000000

The value of 1000000000000000000 is equivalent to 1 Ether of balance, you can use the cast from-wei to convert the value to Ether.

Terminal
cast from-wei 1000000000000000000

Returning the value of 1 Ether.

Response
1.000000000000000000

ERC20 Operations

Withdrawing ERC20 Tokens

To withdraw ERC20 tokens from the sender’s account, use the following JSON input:

Template
{
"kind": "erc20",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}

Send this input using the send command:

Terminal
cartesi send generic --input='{
"kind": "erc20",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}'

Now you can view the voucher in the Cartesi Explorer and execute the withdrawal.

Inspecting ERC20 Balance

To inspect the ERC20 balance of a specific address, use the following JSON input:

Template
{
"kind": "erc20",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}

Send this input using the curl command to inspect the application:

Terminal
curl 'http://localhost:8080/inspect' \
-H 'Content-Type: application/json' \
-d \ '{
"kind": "erc20",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
}' \
| jq

Example of the response:

Response
{
"exception_payload": "0x",
"processed_input_count": 1,
"reports": [
{
"payload": "0x31303030303030303030303030303030303030"
}
],
"status": "Accepted"
}

Using the cast command from foundry, decode the response payload:

Terminal
cast to-ascii 0x31303030303030303030303030303030303030

Returning the balance of the address:

Response
1000000000000000000

ERC721 Operations

Withdrawing ERC721 Tokens

To withdraw an ERC721 token from the sender’s account, use the following JSON input:

Template
{
"kind": "erc721",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 144
}
}

Send this input using the send command:

Terminal
cartesi send generic --input='{
"kind": "erc721",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 144
}
}'

Now you can view the voucher in the Cartesi Explorer and execute the withdrawal.

Inspecting ERC721 Ownership

To inspect the ownership of an ERC721 token, use the following JSON input:

Template
{
"kind": "erc721",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 144
}
}

Send this input using the curl command to inspect the application:

Terminal
curl 'http://localhost:8080/inspect' \
-H 'Content-Type: application/json' \
-d \ '{
"kind": "erc721",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 144
}
}' \
| jq

Example of the response:

Response
{
"exception_payload": "0x",
"processed_input_count": 1,
"reports": [
{
"payload": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
],
"status": "Accepted"
}

The payload field contains the address of the token owner.

ERC1155 Operations

Withdrawing ERC1155 Tokens

To withdraw an ERC1155 token from the sender’s account, use the following JSON input:

Template
{
"kind": "erc1155",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"ids": [256]
}
}

Send this input using the send command:

Terminal
cartesi send generic --input='{
"kind": "erc1155",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": [256]
}
}'

Now you can view the voucher in the Cartesi Explorer and execute the withdrawal.

Inspecting ERC1155 Balance

To inspect the balance of a specific ERC1155 token ID, use the following JSON input:

Template
{
"kind": "erc1155",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 256
}
}

Send this input using the curl command to inspect the application:

Terminal
curl 'http://localhost:8080/inspect' \
-H 'Content-Type: application/json' \
-d \ '{
"kind": "erc1155",
"metadata": {
"token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"id": 256
}
}' \
| jq

Example of the response:

Response
{
"exception_payload": "0x",
"processed_input_count": 1,
"reports": [
{
"payload": "0x3130"
}
],
"status": "Accepted"
}

Using the cast command from foundry, decode the response payload:

Terminal
cast to-ascii 0x3130

Returning the balance of the token ID:

Response
10

The value 10 indicates the balance of the token ID 256 for the specified address.