Code Monkey home page Code Monkey logo

cartesi-client's Introduction

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.

sync return value return description
true {notices: Array<Notice>, reports: Array<Report>, vouchers: Array<Voucher>} An object containing the notices, reports, and vouchers generated by the input.
false ContractReceipt The layer-1 confirmation of the input (web3 transaction receipt).

advanceInput

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

Parameter Required Type Default
client true Signer -
dappAddress true string -
payload true string -
options.sync false boolean true
options.cartessiNodeUrl false string http://localhost:8080
options.inputBoxAddress false string 0x59b22D57D4f067708AB0c00552767405926dc768

advanceEtherDeposit

Sends a deposit of amount ETHERs to the Cartesi DApp.

Parameter Required Type Default
client true Signer -
dappAddress true string -
amount true number -
options.sync false boolean true
options.cartessiNodeUrl false string http://localhost:8080
options.etherPortalAddress false string 0xFfdbe43d4c855BF7e0f105c400A50857f53AB044

advanceERC20Deposit

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

Parameter Required Type Default
client true Signer -
dappAddress true string -
tokenAddress true string -
amount true number -
options.sync false boolean true
options.cartessiNodeUrl false string http://localhost:8080
options.erc20PortalAddress false string 0x9C21AEb2093C32DDbC53eEF24B873BDCd1aDa1DB

advanceERC721Deposit

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

Parameter Required Type Default
client true Signer -
dappAddress true string -
tokenAddress true string -
tokenId true number -
options.sync false boolean true
options.cartessiNodeUrl false string http://localhost:8080
options.erc721PortalAddress false string 0x237F8DD094C0e47f4236f12b4Fa01d6Dae89fb87

advanceDAppRelay

Sends the dapp address to the Cartesi DApp.

Parameter Required Type Default
client true Signer -
dappAddress true string -
options.sync false boolean true
options.cartessiNodeUrl false string http://localhost:8080
options.dappRelayAddress false string 0xF5DE34d6BbC0446E2a45719E718efEbaaE179daE

Inspect

inspect

Sends an inspect to a Cartesi Node with input payload

Parameter Required Type Default
cartesiNodeUrl true string -
payload true string -
options.aggregate false boolean false
options.decodeTo false string utf-8

Output Functions

Vouchers

getVouchers

Queries Cartesi Node's GraphQL server for vouchers.

Parameter Required Type Default
url true string -
inputIndex false number undefined

getVoucher

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

Parameter Required Type Default
url true string -
voucherIndex true number -
inputIndex true number -

getUnexecutedVouchers

Retrieve all vouchers not executed.

Parameter Required Type Default
signOrProvider true Signer|Provider -
dappAddress true string -
cartesiNodeUrl false string http://localhost:8080

getVouchersReady

Retrieve all vouchers ready to be executed.

Parameter Required Type Default
signOrProvider true Signer|Provider -
dappAddress true string -
cartesiNodeUrl false string http://localhost:8080

executeVoucher

Execute a voucher given its inputIndex and voucherIndex.

Parameter Required Type Default
signer true Signer -
dappAddress true string -
inputIndex true number -
voucherIndex true number -
cartesiNodeUrl false string http://localhost:8080

Notices

getNotices

Queries Cartesi Node's GraphQL server for notices.

Parameter Required Type Default
url true string -
inputIndex false number undefined

getNotice

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

Parameter Required Type Default
url true string -
inputIndex true number -
noticeIndex false number 0

Reports

getReports

Queries Cartesi Node's GraphQL server for reports.

Parameter Required Type Default
url true string -
inputIndex false number undefined

getReport

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

Parameter Required Type Default
url true string -
inputIndex true number -
reportIndex false number 0

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

cartesi-client's People

Contributors

arthuravianna avatar lynoferraz avatar felipefg avatar

Stargazers

VishnuE17 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.