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:
cartesi send ether --amount 8cartesi send erc20 --token 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef --amount 10cartesi send erc721 --token 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef --tokenId 0Currently the cartesi send does not support ERC1155 deposits, so you can use the cartesi explorer to send the deposit, so you need to run the application using the cartesi run from Cartesi CLI command and then use the explorer to send the deposit.
Ether Operations
Withdrawing Ether
To withdraw all Ether from the sender’s account, use the following JSON input:
{ "kind": "ether", "metadata": {}}Send this input using the send command:
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:
{ "kind": "ether", "metadata": { "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }}Send this input using the curl command to inspect the application:
curl 'http://localhost:8080/inspect' \ -H 'Content-Type: application/json' \ -d \ '{ "kind": "ether", "metadata": { "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } }' \ | jqExample of the 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:
cast to-ascii 0x31303030303030303030303030303030303030Returning in this case the balance of the address 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef.
1000000000000000000The value of 1000000000000000000 is equivalent to 1 Ether of balance, you can use the cast from-wei to convert the value to Ether.
cast from-wei 1000000000000000000Returning the value of 1 Ether.
1.000000000000000000ERC20 Operations
Withdrawing ERC20 Tokens
To withdraw ERC20 tokens from the sender’s account, use the following JSON input:
{ "kind": "erc20", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }}Send this input using the send command:
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:
{ "kind": "erc20", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }}Send this input using the curl command to inspect the application:
curl 'http://localhost:8080/inspect' \ -H 'Content-Type: application/json' \ -d \ '{ "kind": "erc20", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } }' \ | jqExample of the response:
{ "exception_payload": "0x", "processed_input_count": 1, "reports": [ { "payload": "0x31303030303030303030303030303030303030" } ], "status": "Accepted"}Using the cast command from foundry, decode the response payload:
cast to-ascii 0x31303030303030303030303030303030303030Returning the balance of the address:
1000000000000000000ERC721 Operations
Withdrawing ERC721 Tokens
To withdraw an ERC721 token from the sender’s account, use the following JSON input:
{ "kind": "erc721", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "id": 144 }}Send this input using the send command:
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:
{ "kind": "erc721", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "id": 144 }}Send this input using the curl command to inspect the application:
curl 'http://localhost:8080/inspect' \ -H 'Content-Type: application/json' \ -d \ '{ "kind": "erc721", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "id": 144 } }' \ | jqExample of the 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:
{ "kind": "erc1155", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "ids": [256] }}Send this input using the send command:
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:
{ "kind": "erc1155", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "id": 256 }}Send this input using the curl command to inspect the application:
curl 'http://localhost:8080/inspect' \ -H 'Content-Type: application/json' \ -d \ '{ "kind": "erc1155", "metadata": { "token": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "address": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", "id": 256 } }' \ | jqExample of the response:
{ "exception_payload": "0x", "processed_input_count": 1, "reports": [ { "payload": "0x3130" } ], "status": "Accepted"}Using the cast command from foundry, decode the response payload:
cast to-ascii 0x3130Returning the balance of the token ID:
10The value 10 indicates the balance of the token ID 256 for the specified address.