INTEGRATION

Using wagmi

Reading Ivy contracts with wagmi in React applications.


If you use React, wagmi lets you read Ivy contracts through hooks.

#Configuration

import {http, createConfig} from "wagmi";
import {defineChain} from "viem";

const kaia = defineChain({
  id: 8217,
  name: "Kaia",
  nativeCurrency: {decimals: 18, name: "Kaia", symbol: "KAIA"},
  rpcUrls: {default: {http: ["https://public-en.node.kaia.io"]}},
});

export const config = createConfig({
  chains: [kaia],
  transports: {[kaia.id]: http()},
});

#Read hook

import {useReadContract} from "wagmi";

const IVY_REGISTRY = "0x43522E0aB410246C014359B7F5c55F7a196dddFc";

function ProfileBadge({wallet}: {wallet: `0x${string}`}) {
  const {data: ivyId} = useReadContract({
    address: IVY_REGISTRY,
    abi: [{
      type:"function", name:"ivyIdOf", stateMutability:"view",
      inputs:[{name:"wallet", type:"address"}], outputs:[{type:"uint256"}],
    }],
    functionName: "ivyIdOf",
    args: [wallet],
  });

  if (!ivyId || ivyId === 0n) return <span>No Ivy account</span>;
  return <span>ivyId: {ivyId.toString()}</span>;
}

To send transactions, use the useWriteContract hook with the arguments shown on the viem page.

Takıldığın bir yer mi var?

Teknik destek, entegrasyon ve ortaklık için ekibe ulaş: info@ivy.live

Using wagmi · Ivy Developers · Ivy