-
+
+
setAmount2(e.target.value)}
+ value={tokenId}
+ onChange={(e) => setTokenId(e.target.value)}
placeholder="1"
- step="0.000001"
+ step="1"
min="0"
+ style={styles.input}
/>
-
-
- {isPending &&
Transaction pending...
}
+ {isPending && (
+
+
+
Transaction pending...
+
+ )}
{isSuccess && data && (
-
-
Batch sent successfully!
-
Batch ID: {data.id}
+
+
â
+
Batch sent successfully!
+
Batch ID: {data.id}
)}
- {error &&
Error: {error.message}
}
+ {error && (
+
+ â ī¸
+ {error.message}
+
+ )}
);
}
+const styles = {
+ title: {
+ fontSize: "1.5rem",
+ fontWeight: "600",
+ color: "#1f2937",
+ margin: "0 0 0.5rem 0",
+ } as React.CSSProperties,
+ description: {
+ color: "#6b7280",
+ marginBottom: "2rem",
+ fontSize: "0.95rem",
+ } as React.CSSProperties,
+ form: {
+ display: "flex",
+ flexDirection: "column",
+ gap: "1.5rem",
+ } as React.CSSProperties,
+ inputGroup: {
+ display: "flex",
+ flexDirection: "column",
+ gap: "0.5rem",
+ } as React.CSSProperties,
+ label: {
+ fontWeight: "500",
+ color: "#374151",
+ fontSize: "0.875rem",
+ } as React.CSSProperties,
+ input: {
+ padding: "0.75rem 1rem",
+ border: "2px solid #e5e7eb",
+ borderRadius: "8px",
+ fontSize: "1rem",
+ transition: "all 0.2s",
+ outline: "none",
+ width: "100%",
+ boxSizing: "border-box",
+ } as React.CSSProperties,
+ infoBox: {
+ display: "flex",
+ alignItems: "center",
+ gap: "0.75rem",
+ padding: "1rem",
+ backgroundColor: "#eff6ff",
+ borderRadius: "8px",
+ fontSize: "0.875rem",
+ color: "#1e40af",
+ } as React.CSSProperties,
+ infoIcon: {
+ fontSize: "1.25rem",
+ } as React.CSSProperties,
+ checkboxGroup: {
+ display: "flex",
+ alignItems: "center",
+ padding: "1rem",
+ backgroundColor: "#f9fafb",
+ borderRadius: "8px",
+ } as React.CSSProperties,
+ checkboxLabel: {
+ display: "flex",
+ alignItems: "center",
+ gap: "0.75rem",
+ cursor: "pointer",
+ fontSize: "0.95rem",
+ color: "#374151",
+ } as React.CSSProperties,
+ checkbox: {
+ width: "1.25rem",
+ height: "1.25rem",
+ cursor: "pointer",
+ } as React.CSSProperties,
+ button: {
+ width: "100%",
+ padding: "1rem",
+ backgroundColor: "#667eea",
+ color: "white",
+ border: "none",
+ borderRadius: "8px",
+ fontSize: "1rem",
+ fontWeight: "600",
+ cursor: "pointer",
+ transition: "all 0.2s",
+ marginTop: "0.5rem",
+ } as React.CSSProperties,
+ buttonDisabled: {
+ backgroundColor: "#9ca3af",
+ cursor: "not-allowed",
+ opacity: 0.6,
+ } as React.CSSProperties,
+ statusBox: {
+ marginTop: "1.5rem",
+ padding: "1.5rem",
+ backgroundColor: "#dbeafe",
+ borderRadius: "8px",
+ textAlign: "center",
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: "1rem",
+ } as React.CSSProperties,
+ spinner: {
+ width: "24px",
+ height: "24px",
+ border: "3px solid #60a5fa",
+ borderTop: "3px solid transparent",
+ borderRadius: "50%",
+ animation: "spin 1s linear infinite",
+ } as React.CSSProperties,
+ statusText: {
+ color: "#1e40af",
+ fontWeight: "500",
+ margin: 0,
+ } as React.CSSProperties,
+ successBox: {
+ marginTop: "1.5rem",
+ padding: "1.5rem",
+ backgroundColor: "#d1fae5",
+ borderRadius: "8px",
+ textAlign: "center",
+ } as React.CSSProperties,
+ successIcon: {
+ display: "inline-block",
+ width: "48px",
+ height: "48px",
+ backgroundColor: "#10b981",
+ color: "white",
+ borderRadius: "50%",
+ lineHeight: "48px",
+ fontSize: "24px",
+ fontWeight: "bold",
+ marginBottom: "0.75rem",
+ } as React.CSSProperties,
+ successTitle: {
+ color: "#065f46",
+ fontWeight: "600",
+ margin: "0 0 0.5rem 0",
+ fontSize: "1.1rem",
+ } as React.CSSProperties,
+ successId: {
+ color: "#047857",
+ fontSize: "0.875rem",
+ margin: 0,
+ wordBreak: "break-all",
+ } as React.CSSProperties,
+ errorBox: {
+ marginTop: "1.5rem",
+ padding: "1rem",
+ backgroundColor: "#fee2e2",
+ borderRadius: "8px",
+ color: "#991b1b",
+ display: "flex",
+ alignItems: "center",
+ gap: "0.75rem",
+ } as React.CSSProperties,
+ errorIcon: {
+ fontSize: "1.25rem",
+ } as React.CSSProperties,
+};
+
diff --git a/base-account/base-account-wagmi-template/src/components/SignInWithBase.tsx b/base-account/base-account-wagmi-template/src/components/SignInWithBase.tsx
index bd423b74..9e19632a 100644
--- a/base-account/base-account-wagmi-template/src/components/SignInWithBase.tsx
+++ b/base-account/base-account-wagmi-template/src/components/SignInWithBase.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Connector } from "wagmi";
+import { Connector, useConnect } from "wagmi";
import { SignInWithBaseButton } from "@base-org/account-ui/react";
import { useState } from "react";
@@ -10,63 +10,71 @@ interface SignInWithBaseProps {
export function SignInWithBase({ connector }: SignInWithBaseProps) {
const [verificationResult, setVerificationResult] = useState
("");
+ const { connect } = useConnect();
async function handleBaseAccountConnect() {
- const provider = await connector.getProvider();
- if (provider) {
- try {
- // Generate a fresh nonce (this will be overwritten with the backend nonce)
- const clientNonce =
- Math.random().toString(36).substring(2, 15) +
- Math.random().toString(36).substring(2, 15);
- console.log("clientNonce", clientNonce);
- // Connect with SIWE to get signature, message, and address
- const accounts = await (provider as any).request({
- method: "wallet_connect",
- params: [
- {
- version: "1",
- capabilities: {
- signInWithEthereum: {
- nonce: clientNonce,
- chainId: "0x2105", // Base Mainnet - 8453
- },
+ try {
+ const provider = await connector.getProvider();
+ if (!provider) {
+ console.error("No provider");
+ return;
+ }
+
+ // Generate a fresh nonce (this will be overwritten with the backend nonce)
+ const clientNonce =
+ Math.random().toString(36).substring(2, 15) +
+ Math.random().toString(36).substring(2, 15);
+ console.log("clientNonce", clientNonce);
+
+ // Connect with SIWE to get signature, message, and address
+ // This wallet_connect request will trigger the connection AND update wagmi's state
+ const accounts = await (provider as any).request({
+ method: "wallet_connect",
+ params: [
+ {
+ version: "1",
+ capabilities: {
+ signInWithEthereum: {
+ nonce: clientNonce,
+ chainId: "0x2105", // Base Mainnet - 8453
},
},
- ],
- });
+ },
+ ],
+ });
+
+ // After successful wallet_connect, explicitly connect through wagmi to update state
+ connect({ connector });
- const walletAddress = accounts.accounts[0].address;
- const signature =
- accounts.accounts[0].capabilities.signInWithEthereum.signature;
- const message =
- accounts.accounts[0].capabilities.signInWithEthereum.message;
- // Verify the signature on the backend
- const verifyResponse = await fetch("/api/auth/verify", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- address: walletAddress,
- message,
- signature,
- }),
- });
+ const walletAddress = accounts.accounts[0].address;
+ const signature =
+ accounts.accounts[0].capabilities.signInWithEthereum.signature;
+ const message =
+ accounts.accounts[0].capabilities.signInWithEthereum.message;
+
+ // Verify the signature on the backend
+ const verifyResponse = await fetch("/api/auth/verify", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ address: walletAddress,
+ message,
+ signature,
+ }),
+ });
- const result = await verifyResponse.json();
+ const result = await verifyResponse.json();
- if (result.success) {
- setVerificationResult(`Verified! Address: ${result.address}`);
- } else {
- setVerificationResult(`Verification failed: ${result.error}`);
- }
- } catch (err) {
- console.error("Error:", err);
- setVerificationResult(
- `Error: ${err instanceof Error ? err.message : "Unknown error"}`
- );
+ if (result.success) {
+ setVerificationResult(`Verified! Address: ${result.address}`);
+ } else {
+ setVerificationResult(`Verification failed: ${result.error}`);
}
- } else {
- console.error("No provider");
+ } catch (err) {
+ console.error("Error:", err);
+ setVerificationResult(
+ `Error: ${err instanceof Error ? err.message : "Unknown error"}`
+ );
}
}
@@ -76,7 +84,7 @@ export function SignInWithBase({ connector }: SignInWithBaseProps) {
diff --git a/base-account/base-account-wagmi-template/src/wagmi.ts b/base-account/base-account-wagmi-template/src/wagmi.ts
index 5eda7cfb..5f129f5d 100644
--- a/base-account/base-account-wagmi-template/src/wagmi.ts
+++ b/base-account/base-account-wagmi-template/src/wagmi.ts
@@ -17,8 +17,8 @@ export function getConfig() {
}),
ssr: true,
transports: {
- [base.id]: http(),
[baseSepolia.id]: http(),
+ [base.id]: http(),
},
});
}