Skip to main content

Getting Started

Requirements

graz requires react@>=17 due to using function components and hooks and the new JSX transform.

Installation

Install graz

# using npm
npm install graz

# using yarn
yarn add graz

# using pnpm
pnpm add graz

Install peer dependencies

To avoid version mismatch we decided to make these packages as peer dependencies:

# using npm
npm install @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long

# using yarn
yarn add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long

# using pnpm
pnpm add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long

Quick start

1. Wrap app with <GrazProvider />

import { GrazProvider } from "graz";

function App() {
return (
<GrazProvider>
<Wallet />
</GrazProvider>
);
}

2. Configure grazOptions

import { ChainInfo } from "@keplr-wallet/types";
import { GrazProvider } from "graz";

const cosmoshub: ChainInfo = {
chainId: "cosmoshub-4",
chainName: "Cosmos Hub",
//... rest of cosmoshub ChainInfo
};

function App() {
return (
<GrazProvider
grazOptions={{
chains: [cosmoshub],
}}
>
<Wallet />
</GrazProvider>
);
}

3. You're good to go!

Use hooks! Every component inside the GrazProvider is now set up to use the graz hooks.

import { useAccount, useConnect, useDisconnect } from "graz";

function Wallet() {
const { connect, status } = useConnect();
const { data: account, isConnected } = useAccount();
const { disconnect } = useDisconnect();

function handleConnect() {
return isConnected ? disconnect() : connect();
}

return (
<div>
{account ? `Connected to ${account.bech32Address}` : status}
<button onClick={handleConnect}>{isConnected ? "Disconnect" : "Connect"}</button>
</div>
);
}