Quickstart
Get end-to-end encrypted chat working in your app in under 5 minutes.
Prerequisites
1. Get an API key
Sign up at encra.dev/signup — free during beta, no credit card needed.
After signing in, go to Dashboard → Create key. Copy the full JWT token when it appears — it's only shown once.
⚠ Save your key
.env immediately.2. Install
# React projects
npm install @encra/react
# Node.js, Svelte, Vue, vanilla JS
npm install @encra/client
# Low-level crypto primitives only
npm install @encra/core
# Or use the setup wizard (auto-detects your framework)
npx encra init3. Add to your React app
Add your API key to your environment variables:
NEXT_PUBLIC_ENCRA_API_KEY=your_api_key_hereThen use the hook in your component:
import { useE2EChat } from '@encra/react'
export default function Chat({ currentUserId, recipientId }) {
const { messages, isReady, sendMessage, error } = useE2EChat({
apiKey: process.env.NEXT_PUBLIC_ENCRA_API_KEY!,
userId: currentUserId,
// serverUrl is optional — defaults to Encra managed server
})
if (error) return <p>Connection error: {error.message}</p>
return (
<div>
<div className="messages">
{messages.map((msg, i) => (
<div key={i} className={msg.from === currentUserId ? 'sent' : 'received'}>
<strong>{msg.from}</strong>: {msg.text}
</div>
))}
</div>
<button
disabled={!isReady}
onClick={() => sendMessage(recipientId, 'Hello!')}
>
{isReady ? 'Send' : 'Connecting...'}
</button>
</div>
)
}💡 What happens under the hood
3b. Node.js / plain JS / other frameworks
For non-React projects — Node.js, Svelte, Vue, vanilla JS — use @encra/client. It has the same features as @encra/react but with an event-emitter API instead of hooks.
npm install @encra/clientimport { EncraClient } from '@encra/client'
const client = new EncraClient({
apiKey: process.env.ENCRA_API_KEY!,
userId: 'alice',
})
client.on('ready', () => console.log('connected'))
client.on('message', (msg) => console.log(msg.from, msg.text))
client.on('error', (err) => console.error(err))
await client.connect()
// Send an encrypted message
await client.sendMessage('bob', 'Hello Bob!')
// Clean up
client.disconnect()💡 Full API
4. Test it
Open your app in two browser tabs. In tab 1, copy the user ID shown after connecting. In tab 2, paste it as the recipient and send a message. You should see the message arrive in tab 1 — and if you open DevTools → Network, you'll see the server only receives encrypted blobs.
💡 Try the live playground