Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0xbojack/fhevm-nextjs
Next.js adapter for FHEVM SDK with built-in client-side directives
Next.js adapter for FHEVM SDK with built-in 'use client' directives. This package provides the same React hooks as @0xbojack/fhevm-react, but automatically handles client-side rendering for Next.js applications.
In Next.js, FHEVM operations require client-side execution. With @0xbojack/fhevm-react, you need to manually add 'use client' to every component:
// ❌ With @0xbojack/fhevm-react - requires manual 'use client'
'use client'
import { useFhevm } from '@0xbojack/fhevm-react'
export default function MyComponent() {
const { instance } = useFhevm()
return <div>...</div>
}
With @0xbojack/fhevm-nextjs, the 'use client' directive is already included:
// ✅ With @0xbojack/fhevm-nextjs - no manual directive needed!
import { useFhevm } from '@0xbojack/fhevm-nextjs'
export default function MyComponent() {
const { instance } = useFhevm()
return <div>...</div>
}
npm install @0xbojack/fhevm-nextjs ethers
# or
pnpm add @0xbojack/fhevm-nextjs ethers
# or
yarn add @0xbojack/fhevm-nextjs ethers
// app/providers.tsx
import { FhevmProvider } from '@0xbojack/fhevm-nextjs'
import { ReactNode } from 'react'
export function Providers({ children }: { children: ReactNode }) {
return (
<FhevmProvider config={{ storage: /* your storage */ }}>
{children}
</FhevmProvider>
)
}
// 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>
)
}
// app/page.tsx (or any component)
import { useFhevm, useEncrypt, useDecrypt } from '@0xbojack/fhevm-nextjs'
import { useEffect } from 'react'
import { BrowserProvider } from 'ethers'
export default function EncryptPage() {
const { instance, status, init } = useFhevm()
const { encrypt, isEncrypting } = useEncrypt()
const { decrypt, isDecrypting, results } = useDecrypt()
useEffect(() => {
async function initFhevm() {
if (typeof window !== 'undefined' && window.ethereum) {
const provider = new BrowserProvider(window.ethereum)
await init({ provider })
}
}
initFhevm()
}, [init])
const handleEncrypt = async () => {
if (!instance) return
const encrypted = await encrypt({
value: 42,
type: 'euint32',
contractAddress: '0x...',
userAddress: '0x...',
})
console.log('Encrypted:', encrypted)
}
return (
<div>
<h1>FHEVM Encryption</h1>
<p>Status: {status}</p>
<button onClick={handleEncrypt} disabled={isEncrypting || status !== 'ready'}>
{isEncrypting ? 'Encrypting...' : 'Encrypt Value'}
</button>
</div>
)
}
This package re-exports all hooks and types from @0xbojack/fhevm-react and @0xbojack/fhevm-core:
useFhevm() - Initialize and manage FHEVM instanceuseEncrypt() - Encrypt data for on-chain computationuseDecrypt() - Decrypt encrypted dataFhevmProvider - Context provider for FHEVM instanceAll TypeScript types from core and react packages are available:
import type {
// Core types
FhevmConfig,
FhevmStatus,
EncryptedType,
EncryptParams,
DecryptRequest,
// React hook types
UseFhevmResult,
UseEncryptResult,
UseDecryptResult,
} from '@0xbojack/fhevm-nextjs'
// app/providers.tsx
'use client'
import { FhevmProvider } from '@0xbojack/fhevm-nextjs'
import { IndexedDBStorage } from '@0xbojack/fhevm-core/storage'
import { WagmiProvider } from 'wagmi'
import { RainbowKitProvider } from '@rainbow-me/rainbowkit'
import { config } from './wagmi'
export function Providers({ children }: { children: React.ReactNode }) {
return (
<WagmiProvider config={config}>
<RainbowKitProvider>
<FhevmProvider config={{ storage: new IndexedDBStorage() }}>
{children}
</FhevmProvider>
</RainbowKitProvider>
</WagmiProvider>
)
}
// app/page.tsx
import { useFhevm, useEncrypt } from '@0xbojack/fhevm-nextjs'
import { useAccount, useWalletClient } from 'wagmi'
import { useEffect } from 'react'
export default function Home() {
const { address } = useAccount()
const { data: walletClient } = useWalletClient()
const { instance, status, init } = useFhevm()
const { encrypt } = useEncrypt()
useEffect(() => {
if (walletClient) {
init({ provider: walletClient })
}
}, [walletClient, init])
return (
<div>
<h1>FHEVM + Next.js</h1>
<p>Status: {status}</p>
<p>Connected: {address}</p>
</div>
)
}
// pages/_app.tsx
import type { AppProps } from 'next/app'
import { FhevmProvider } from '@0xbojack/fhevm-nextjs'
import { IndexedDBStorage } from '@0xbojack/fhevm-core/storage'
export default function App({ Component, pageProps }: AppProps) {
return (
<FhevmProvider config={{ storage: new IndexedDBStorage() }}>
<Component {...pageProps} />
</FhevmProvider>
)
}
// pages/index.tsx
import { useFhevm, useEncrypt } from '@0xbojack/fhevm-nextjs'
import { useEffect } from 'react'
import { BrowserProvider } from 'ethers'
export default function Home() {
const { instance, status, init } = useFhevm()
useEffect(() => {
if (typeof window !== 'undefined' && window.ethereum) {
const provider = new BrowserProvider(window.ethereum)
init({ provider })
}
}, [init])
return (
<div>
<h1>FHEVM Next.js</h1>
<p>Status: {status}</p>
</div>
)
}
| Feature | @0xbojack/fhevm-react | @0xbojack/fhevm-nextjs |
|---|---|---|
| Framework | React (CRA, Vite) | Next.js (App/Pages Router) |
'use client' directive | ❌ Manual required | ✅ Built-in |
| SSR Support | N/A | ✅ Handles client-side automatically |
| API | Identical | Identical |
| Bundle Size | Lighter (no Next.js deps) | Slightly larger |
@0xbojack/fhevm-nextjs: Building a Next.js application@0xbojack/fhevm-react: Building with Create React App, Vite, or other React frameworks@0xbojack/fhevm-core: Framework-agnostic usage (Node.js, vanilla JS)Make sure you're initializing FHEVM only on the client side:
useEffect(() => {
if (typeof window !== 'undefined') {
// Initialize FHEVM here
}
}, [])
If you see hydration mismatches, ensure FHEVM operations happen after hydration:
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
if (!mounted) return null
return <YourComponent />
See full working examples in our monorepo:
@0xbojack/fhevm-core - Framework-agnostic core library@0xbojack/fhevm-react - React hooks (requires manual 'use client')@0xbojack/fhevm-vue - Vue 3 composablesBSD-3-Clause-Clear
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@0xbojack/fhevm-reactEnvironment{
"local_name": "@0xbojack/fhevm-react",
"alias": false,
"peer_metadata": null
} | ^0.2.2 | runtime |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^22.7.5 | development |
@types/reactEnvironment{
"local_name": "@types/react",
"alias": false,
"peer_metadata": null
} | ^18.3.18 | development |
nextEnvironment{
"local_name": "next",
"alias": false,
"peer_metadata": null
} | ^15.0.0 | development |
reactEnvironment{
"local_name": "react",
"alias": false,
"peer_metadata": null
} | ^18.3.1 | development |
tsupEnvironment{
"local_name": "tsup",
"alias": false,
"peer_metadata": null
} | ^8.5.0 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.9.2 | development |
nextEnvironment{
"local_name": "next",
"alias": false,
"peer_metadata": null
} | ^14.0.0 || ^15.0.0 | peer |
reactEnvironment{
"local_name": "react",
"alias": false,
"peer_metadata": null
} | ^18.0.0 || ^19.0.0 | peer |
ethersEnvironment{
"local_name": "ethers",
"alias": false,
"peer_metadata": null
} | ^6.13.7 | peer |
Source distribution
{
"integrity": "sha512-vUeQcmIdnvUqVvfdpu1P9KhnIjBHKZWCdpYVeUcuNowrwm3WpIEosSEI85Fgtev3LMwj6xETKcng6/rg8AsZsg==",
"shasum": "75dc04aca8c6d883b0e7722cba80c4307563e0d3",
"tarball": "https://registry.npmjs.org/@0xbojack/fhevm-nextjs/-/fhevm-nextjs-0.2.2.tgz",
"fileCount": 8,
"unpackedSize": 13131,
"signatures": [
{
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
"sig": "MEUCIQCyfiC7zvXJD0VmeErS/pRn+86thbZCG4gAUoPl5xlV0wIgOnqTG1O5ms1hF5aB60z8MpkiCh/h4y4n7/m9Mse0HtE="
}
]
}Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:ea51da51ce8bb7fe685712542d22a3c97e04dd7784d41ffbcb968e40c7ab992b