Skip to content
Logo

Introduction

This provides React hooks for Cartesi rollups smart contracts operations, as generated by Wagmi CLI, and also hooks for CartesiPublicClient L2 actions.

Installation

Add the library to your existing React project.

Setup

Next setup a TanStack Query provider and a CartesiProvider provider in your application root.

import { CartesiProvider } from "@cartesi/wagmi";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
 
// Create a query client
const queryClient = new QueryClient();
 
function App() {
  return (
    // Provide the client to your App
    <QueryClientProvider client={queryClient}>
      <CartesiProvider rpcUrl="http://127.0.0.1:6751/rpc">
        <Home />
      </CartesiProvider>
    </QueryClientProvider>
  )
}

Hooks

Find below an example of fetching the applications of a Cartesi rollups node.

import { useApplications } from "@cartesi/wagmi";
 
function Home() {
  const { data, isLoading, error } = useApplications();
 
  return (
    <div>
      ...
    </div>
  )
}