๐Ÿš€ Hive Keychain SDK: The React Adventure with Vite, Tailwind & Facepalms ๐Ÿคฆโ€โ™‚๏ธ

in HiveDevs โ€ข 4 days ago

๐Ÿ‘‹ 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:

Open Hive-keychain.com


๐Ÿ› ๏ธ 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);
    

npm install


๐Ÿ’ฅ 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.

Browser buffer errors


๐Ÿค– Step 4: Summon the AI Overlords

  • AI said: "Install buffer, foolish mortal!"
  • So, I blindly did: npm install buffer
  • Result? Still borked.

install buffer


๐Ÿง™โ€โ™‚๏ธ Step 5: The Sorcererโ€™s Config

Next, AI bestowed arcane knowledge. I bent the knee to update my vite.config.ts:

confusion configs meme

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?

confusion meme


๐Ÿคฏ Step 7: Ask AI Again (Yep, Again)

AI Conversation screenshot

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! ๐ŸŒ•

Hive to the moon and beyond


๐Ÿ“ Final Note


๐Ÿš€ My Contributions to โ™ฆ๏ธ Hive Ecosystem

ContributionToHiveEcosystem
Hive Witness NodeHive API Node (in progress)3Speak Video Encoder Node Operator (highest number of nodes)3Speak Mobile App Developer
3Speak Podcast App Developer3Speak Shorts App Developer3Speak Support & Maintenance TeamDistriator Developer
CheckinWithXYZHive InboxHiFindHive Donate App
Contributed to HiveAuth Mobile AppEcency โ†” 3Speak IntegrationEcency โ†” InLeo IntegrationEcency โ†” Actifit Integration
Hive Stats AppVote for Witness AppHiveFlutterKitNew 3Speak App

๐Ÿ™Œ Support Back

โค๏ธ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! โค๏ธ


Sort: ย 

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.

image.png

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)

You made more than 11000 comments.
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.