0.1.1 • Published 9 months ago

@mugen-builders/client v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

Cartesi Client

A typescript package that abstracts the complexity of the interaction with a Cartesi Rollups DApp.

Table of Contents

Build

npm install
npm run build
npm link

Import it locally

cd \<path_to_my_project\>
npm link cartesi-client

In your code

import { advanceInput } from "cartesi-client";

Input Functions

Advance

Functions in this subsection trigger an advance state in the Cartesi DApp. The return type of the functions depends on the value of the optional parameter sync.

syncreturn valuereturn description
true{notices: Array\, reports: Array\, vouchers: Array\}An object containing the notices, reports, and vouchers generated by the input.
falseContractReceiptThe layer-1 confirmation of the input (web3 transaction receipt).

advanceInput

Sends a generic input (payload) to the Cartesi DApp.

ParameterRequiredTypeDefault
clienttrueSigner-
dappAddresstruestring-
payloadtruestring-
options.syncfalsebooleantrue
options.cartessiNodeUrlfalsestringhttp://localhost:8080
options.inputBoxAddressfalsestring0x59b22D57D4f067708AB0c00552767405926dc768

advanceEtherDeposit

Sends a deposit of amount ETHERs to the Cartesi DApp.

ParameterRequiredTypeDefault
clienttrueSigner-
dappAddresstruestring-
amounttruenumber-
options.syncfalsebooleantrue
options.cartessiNodeUrlfalsestringhttp://localhost:8080
options.etherPortalAddressfalsestring0xFfdbe43d4c855BF7e0f105c400A50857f53AB044

advanceERC20Deposit

Sends a deposit of amount ERC20 tokens to the Cartesi DApp.

ParameterRequiredTypeDefault
clienttrueSigner-
dappAddresstruestring-
tokenAddresstruestring-
amounttruenumber-
options.syncfalsebooleantrue
options.cartessiNodeUrlfalsestringhttp://localhost:8080
options.erc20PortalAddressfalsestring0x9C21AEb2093C32DDbC53eEF24B873BDCd1aDa1DB

advanceERC721Deposit

Deposit the ERC721 token with address tokenAddress and id tokenId to the Cartesi DApp.

ParameterRequiredTypeDefault
clienttrueSigner-
dappAddresstruestring-
tokenAddresstruestring-
tokenIdtruenumber-
options.syncfalsebooleantrue
options.cartessiNodeUrlfalsestringhttp://localhost:8080
options.erc721PortalAddressfalsestring0x237F8DD094C0e47f4236f12b4Fa01d6Dae89fb87

advanceDAppRelay

Sends the dapp address to the Cartesi DApp.

ParameterRequiredTypeDefault
clienttrueSigner-
dappAddresstruestring-
options.syncfalsebooleantrue
options.cartessiNodeUrlfalsestringhttp://localhost:8080
options.dappRelayAddressfalsestring0xF5DE34d6BbC0446E2a45719E718efEbaaE179daE

Inspect

inspect

Sends an inspect to a Cartesi Node with input payload

ParameterRequiredTypeDefault
cartesiNodeUrltruestring-
payloadtruestring-
options.aggregatefalsebooleanfalse
options.decodeTofalsestringutf-8

Output Functions

Vouchers

getVouchers

Queries Cartesi Node's GraphQL server for vouchers.

ParameterRequiredTypeDefault
urltruestring-
inputIndexfalsenumberundefined

getVoucher

Queries Cartesi Node's GraphQL server looking for a specific voucher.

ParameterRequiredTypeDefault
urltruestring-
voucherIndextruenumber-
inputIndextruenumber-

getUnexecutedVouchers

Retrieve all vouchers not executed.

ParameterRequiredTypeDefault
signOrProvidertrueSigner|Provider-
dappAddresstruestring-
cartesiNodeUrlfalsestringhttp://localhost:8080

getVouchersReady

Retrieve all vouchers ready to be executed.

ParameterRequiredTypeDefault
signOrProvidertrueSigner|Provider-
dappAddresstruestring-
cartesiNodeUrlfalsestringhttp://localhost:8080

executeVoucher

Execute a voucher given its inputIndex and voucherIndex.

ParameterRequiredTypeDefault
signertrueSigner-
dappAddresstruestring-
inputIndextruenumber-
voucherIndextruenumber-
cartesiNodeUrlfalsestringhttp://localhost:8080

Notices

getNotices

Queries Cartesi Node's GraphQL server for notices.

ParameterRequiredTypeDefault
urltruestring-
inputIndexfalsenumberundefined

getNotice

Queries Cartesi Node's GraphQL server looking for a specific notice.

ParameterRequiredTypeDefault
urltruestring-
inputIndextruenumber-
noticeIndexfalsenumber0

Reports

getReports

Queries Cartesi Node's GraphQL server for reports.

ParameterRequiredTypeDefault
urltruestring-
inputIndexfalsenumberundefined

getReport

Queries Cartesi Node's GraphQL server looking for a specific report.

ParameterRequiredTypeDefault
urltruestring-
inputIndextruenumber-
reportIndexfalsenumber0

Run package Tests

  1. Run the test backend in one of the terminals
cd backend
sunodo build
sunodo run
  1. Open a new terminal to deploy the ERC721 contract and mint the NFT used for tests
export MNEMONIC="test test test test test test test test test test test junk"
export RPC_URL="http://localhost:8545"
export PUBLIC_KEY="0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"
export ERC721_ADDRESS="0xc6e7DF5E7b4f2A278906862b61205850344D4e7d"
cd backend/contracts
forge build
forge create --rpc-url "${RPC_URL}" --mnemonic "${MNEMONIC}" --json src/simpleERC721.sol:SimpleERC721
cast send --mnemonic "${MNEMONIC}" --rpc-url "${RPC_URL}" ${ERC721_ADDRESS} "mintTo(address)" ${PUBLIC_KEY}
  1. Go Back to cartesi-client root dir and run the tests
cd ../../
npm run test
0.1.2-rc1.0

9 months ago

0.1.1

12 months ago

0.1.0

12 months ago