Archive post
π Hive Keychain SDK: The React Adventure with Vite, Tailwind & Facepalms π€¦ββοΈ
β’ sagarkothari88
A fun, emoji-packed journey setting up Hive Keychain SDK in React, filled with gotchas, memes, & eventual triumph
## π Hello, Hive Community!
Welcome fellow #Hivers! As I dove into the magical world of Hive Keychain SDK integration, I hit a few snags (and had some laughs along the way). So here's my entertaining, step-by-step breakdown for getting it working smoothly in your own React project (using React + Vite + Typescript + Tailwind CSS + DaisyUI). Grab a chai, let's go! β
---
### π **Step 1: Getting the Tools**
First, head to the mystical land of:
- π [hive-keychain.com](https://hive-keychain.com)
- Find the **Resources** menu
- Summon the "Keychain SDK"

---
### π οΈ **Step 2: Install Stuff Because RTFM Is Life**
- In terminal, cast this spell: `npm install keychain-sdk`
- Import the SDK like a proper developer:
```
import { KeychainSDK } from "keychain-sdk";
```
- Create your wizard:
```
const keychain = new KeychainSDK(window);
```

---
### π₯ **Step 3: Reality Hits - Error Galore!**
Ran `npm run dev` to behold my genius at `localhost:5173`β¦ but NOPE. Got smacked by a mysterious browser error.

---
### π€ **Step 4: Summon the AI Overlords**
- AI said: "Install buffer, foolish mortal!"
- So, I blindly did: `npm install buffer`
- *Result? Still borked.*

---
### π§ββοΈ **Step 5: The Sorcererβs Config**
Next, AI bestowed arcane knowledge. I bent the knee to update my `vite.config.ts`:

```
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
export default defineConfig({
plugins: [react(), tailwindcss()],
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
process: true,
}),
NodeModulesPolyfillPlugin(),
],
},
},
resolve: {
alias: {
buffer: "buffer",
},
},
});
```
---
### β‘ **Step 6: (Re)Try Everything!**
With the config in place, I bravely ran `npm run dev`. π§ *No errors. Hope returns!*
Time for the next spell: **Check if Hive Keychain is present:**
```
import { KeychainSDK } from "keychain-sdk";
import { useEffect, useState } from "react";
const HiveLoginModal = () => {
const keychain = new KeychainSDK(window);
const [keychainAvailable, setKeychainAvailable] = useState(false);
useEffect(() => {
const check = async () => {
const isKeychainInstalled = await keychain.isKeychainInstalled();
console.log(`Do we have keychain now? ${isKeychainInstalled ? 'yes': 'no'}`);
setKeychainAvailable(isKeychainInstalled);
};
check();
}, []);
```
**BUT... it logged 'no' even with Hive Keychain installed!** π€ What dark magic is this?

---
### π€― **Step 7: Ask AI Again (Yep, Again)**

**AI says:** βDelay just a bit - Keychain needs time to show up!β
So here's the new check:
```
useEffect(() => {
const check = async () => {
console.log("We don't have keychain yet");
await new Promise((res) => setTimeout(res, 500));
const keychain = new KeychainSDK(window);
const isKeychainInstalled = await keychain.isKeychainInstalled();
console.log(`Do we have keychain now? ${isKeychainInstalled ? 'yes': 'no'}`);
setKeychainAvailable(isKeychainInstalled);
};
if (document.readyState === "complete") {
check();
} else {
window.addEventListener("load", check);
return () => window.removeEventListener("load", check);
}
}, []);
```
**BOOM!** After this, it *finally* worked. Friends, I am just getting started. More guides on the way. Hive-Keychain SDK team should totally add a React-focused pageβimagine the memes! π
---
## π **Final Words and Power-Ups**
- More power to Hive-keychain dev team! π¨βπ»π
- More power to Hive community members! π€
- More power to Hive blockchain! π
- More power to Hive! π₯
- Hive to the moon and beyond! π

---
### π Final Note
- I asked perplexity to help optimize this post to make it more readable and viewer-friendly.
- Here is the link where you can find both original content & improvements made by AI
- https://www.perplexity.ai/search/3d96d12b-d8ca-419f-92a6-093569aa96b1
---
### π My Contributions to β¦οΈ Hive Ecosystem
| Contribution | To | Hive | Ecosystem |
|--------------|----|------|-----------|
| Hive Witness Node | Hive API Node (in progress) | 3Speak Video Encoder Node Operator (highest number of nodes) | 3Speak Mobile App Developer |
| 3Speak Podcast App Developer | 3Speak Shorts App Developer | 3Speak Support & Maintenance Team | [Distriator Developer](https://distriator.com/) |
| [CheckinWithXYZ](https://checkinwith.xyz/) | [Hive Inbox](https://hive-inbox.the-hive-mobile.app/) | [HiFind](https://hifind.the-hive-mobile.app/) | [Hive Donate App](https://donate.the-hive-mobile.app/) |
| Contributed to HiveAuth Mobile App | Ecency β 3Speak Integration | Ecency β InLeo Integration | Ecency β Actifit Integration |
| [Hive Stats App](https://stats.the-hive-mobile.app/) | [Vote for Witness App](https://witness.the-hive-mobile.app/) | [HiveFlutterKit](https://hiveflutterkit.sagarkothari88.one/docs/intro) | [New 3Speak App](https://3speak.sagarkothari88.one/#/?tab=home) |
---
### π Support Back
β€οΈ **Appreciate my work? Consider supporting @threespeak & @sagarkothari88!** β€οΈ
| Vote | For | Witness |
|------|-----|---------|
| [](https://witness.the-hive-mobile.app/#/witnesses/@sagarkothari88) | [sagarkothari88](https://witness.the-hive-mobile.app/#/witnesses/@sagarkothari88) | @sagarkothari88 |
| [](https://witness.the-hive-mobile.app/#/witnesses/@threespeak) | [threespeak](https://witness.the-hive-mobile.app/#/witnesses/@threespeak) | @threespeak |
---