๐ 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
- 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 |
CheckinWithXYZ | Hive Inbox | HiFind | Hive Donate App |
Contributed to HiveAuth Mobile App | Ecency โ 3Speak Integration | Ecency โ InLeo Integration | Ecency โ Actifit Integration |
Hive Stats App | Vote for Witness App | HiveFlutterKit | New 3Speak App |
๐ Support Back
โค๏ธ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! โค๏ธ
Vote | For | Witness |
---|---|---|
sagarkothari88 | @sagarkothari88 | |
threespeak | @threespeak |
This post has been manually curated by @bhattg from Indiaunited community. Join us on our Discord Server.
Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.
Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.
100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @bhattg by upvoting this comment and support the community by voting the posts made by @indiaunited..
This post received an extra 7.51% vote for delegating HP / holding IUC tokens.
Congratulations @sagarkothari88! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 12000 comments.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Hi can you please say who to sold the @letusbuyhive account to ๐๐พ
Right now it looks like you are the owner
This is good. It's Informative, educative and innovative.