Wagmi
Getting Started
pnpm add wagmi [email protected] @tanstack/react-queryWAGMI Config Setup
import { http, createConfig } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
import { coinbaseWallet, injected } from "wagmi/connectors";
// Extend the global Window interface directly in this file
declare global {
interface Window {
magicEden?: {
ethereum?: {
request: (args: { method: string; params?: any[] }) => Promise<any>;
on: (event: string, handler: (...args: any[]) => void) => void;
removeAllListeners: () => void;
// Add other methods and properties as needed
};
};
}
}
// Define the Magic Eden Wallet Connector
const ME_CONNECT = injected({
target() {
const provider =
typeof window !== "undefined" ? window.magicEden?.ethereum : undefined;
return {
id: "Magic Eden",
name: "Magic Eden",
provider: provider as any, // We still use `any` here to bypass strict type checking for the provider from WAGMI
};
},
});
// Create the configuration
export const config = createConfig({
chains: [mainnet, sepolia],
connectors: [ME_CONNECT, coinbaseWallet({ appName: "Create Wagmi" })],
ssr: true,
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
});
// Declare the module to register the config type with wagmi
declare module "wagmi" {
interface Register {
config: typeof config;
}
}
Setup WAGMI Provider and QueryClient
Display Wallet Options Component
Update Imports
Display Wallet Options
Connect an active wallet
Create a Connect Wallet Component
Add Wallet Button to Page or Component
Full Page
Last updated