> For the complete documentation index, see [llms.txt](https://whitepaper.litho.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.litho.ai/docs/developers/examples/wagmi-example.md).

# wagmi + Next.js example

Goal: connect a wallet, show the connected user's LITHO balance, and call a LEP-100 `transfer` from a Next.js 14 app — using the Lithosphere SDK's network registry and ABIs.

## Install

```bash
pnpm add @lithosphere/sdk wagmi viem @tanstack/react-query
```

`@lithosphere/sdk` re-exports the `NETWORKS` registry and `LEP100_ABI` you need; no other Lithosphere packages required.

## Configure wagmi

Set up a single `wagmi.ts` module so every page reuses the same config.

```ts
// app/wagmi.ts
'use client';

import { http, createConfig } from 'wagmi';
import { injected } from 'wagmi/connectors';
import { defineChain } from 'viem';
import { NETWORKS } from '@lithosphere/sdk';

const net = NETWORKS.mainnet;

export const lithosphere = defineChain({
  id: net.chainId,
  name: 'Lithosphere',
  nativeCurrency: {
    name: net.currency.name,
    symbol: net.currency.symbol,
    decimals: net.currency.decimals,
  },
  rpcUrls: {
    default: { http: [net.rpcUrl] },
  },
  blockExplorers: {
    default: { name: 'Makalu Explorer', url: net.explorerUrl ?? '' },
  },
});

export const config = createConfig({
  chains: [lithosphere],
  connectors: [injected()],
  transports: {
    [lithosphere.id]: http(),
  },
});
```

## Wrap the app

```tsx
// app/providers.tsx
'use client';

import { WagmiProvider } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { config } from './wagmi';
import { ReactNode } from 'react';

const queryClient = new QueryClient();

export function Providers({ children }: { children: ReactNode }) {
  return (
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
    </WagmiProvider>
  );
}
```

```tsx
// app/layout.tsx
import { Providers } from './providers';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}
```

## Balance + Transfer page

```tsx
// app/page.tsx
'use client';

import { useAccount, useBalance, useConnect, useDisconnect, useWriteContract } from 'wagmi';
import { injected } from 'wagmi/connectors';
import { parseUnits } from 'viem';
import { LEP100_ABI } from '@lithosphere/sdk';

const TOKEN_ADDR = '0xreplace-with-your-token-contract...' as const;

export default function Home() {
  const { address, isConnected } = useAccount();
  const { connect } = useConnect();
  const { disconnect } = useDisconnect();
  const { data: bal } = useBalance({ address });
  const { writeContract, isPending } = useWriteContract();

  if (!isConnected) {
    return (
      <button onClick={() => connect({ connector: injected() })}>
        Connect wallet
      </button>
    );
  }

  return (
    <main style={{ padding: 24 }}>
      <p>
        Connected as <code>{address}</code>{' '}
        <button onClick={() => disconnect()}>Disconnect</button>
      </p>
      <p>
        Balance: {bal?.formatted ?? '…'} {bal?.symbol}
      </p>
      <button
        disabled={isPending}
        onClick={() =>
          writeContract({
            address: TOKEN_ADDR,
            abi: LEP100_ABI,
            functionName: 'transfer',
            args: ['0xrecipient...', parseUnits('1', 18)],
          })
        }
      >
        {isPending ? 'Sending…' : 'Send 1 token'}
      </button>
    </main>
  );
}
```

## Run it

```bash
pnpm dev
```

Open <http://localhost:3000>, click **Connect wallet**, switch your wallet to Lithosphere (chain ID 700777, RPC `https://rpc.litho.ai`), then click **Send**.

## Notes

* `NETWORKS.mainnet` is the live testnet today — there is no separate mainnet chain yet. See [chain-parameters.md](/docs/network/chain-parameters.md).
* For typed inference on `writeContract`, the `as const` re-assertion shown above is not strictly required — wagmi/viem accept `LEP100_ABI` as-is — but adding it gives narrower types in your IDE.
* If you need a server-side read client (e.g. in a Next.js Route Handler), use `new LithoClient('mainnet')` from `@lithosphere/sdk` directly. See the [ethers example](/docs/developers/examples/ethers-example.md) for the Node-side pattern.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://whitepaper.litho.ai/docs/developers/examples/wagmi-example.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
