Coder Social home page Coder Social logo

cartesify's Introduction

Cartesify

Introduction

Cartesify is a powerful web3 client that allows you to interact with the Cartesi Machine. It enables you to send transactions, query data, and seamlessly interact with your backend using a REST-like approach.

Getting Started

The easiest way to get started with Cartesify is by simply cloning the template from: cartesify-template.

Installation

To use our web3 client, follow these simple installation steps:

npm install @calindra/cartesify

Pay attention: @calindra/cartesify is intended to be used with @calindra/cartesify-backend

Usage

  1. Import and configure the Web3 library into your project:

    import { Cartesify } from "@calindra/cartesify";
    
    const CARTESI_INSPECT_ENDPOINT="http://localhost:8080/inspect";
    
    // replace with the content of your dapp address (it could be found on dapp.json)
    const DAPP_ADDRESS="0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C";
    
    const fetch = Cartesify.createFetch({
       dappAddress: '0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C',
       endpoints: {
          graphQL: new URL("http://localhost:8080/graphql"),
          inspect: new URL("http://localhost:8080/inspect"),
       },
    })
  2. Connect to MetaMask and get the signer:

    import { ethers } from "ethers";
    
    async function getSigner() {
       try {
          await window.ethereum.request({ method: "eth_requestAccounts" })
          const provider = new ethers.providers.Web3Provider(
             window.ethereum
          );
          return provider.getSigner();
       } catch (error) {
          console.log(error);
          alert("Connecting to metamask failed.");
       }
    }
  3. Start interacting with the Cartesi Machine:

    const response = await fetch("http://127.0.0.1:8383/echo", {
       method: "POST",
       headers: {
             "Content-Type": "application/json",
       },
       body: JSON.stringify({ any: 'body' }),
       signer, // <- the signer
    })
    console.log(response.ok) // will print true
    const json = await response.json();
    console.log(json) // will print the backend response as json

cartesify's People

Contributors

fabiooshiro avatar sandhilt avatar

Stargazers

energyER6 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.