Saludos hivers espero de todo corazón que todos esten muy contentos y felices. Un saludo especial para los programadores que dia a dia mejoran el ecosistema web3.
Para seguir ayudando en la formación de futuras estrellas de la programación en HIVE, les traigo un tutorial basico pero lleno de algo que es y deberia ser vital.
Este tutorial te guiará para implementar la autenticación de usuarios en la blockchain de Hive utilizando Hive Keychain en una aplicación React configurada con Vite y TypeScript.
npm create vite@latest hive-login-app -- --template react-ts
cd hive-login-app
npm install
npm run dev
npm install @hiveio/dhive
src/components/HiveLogin.tsx con el siguiente contenido:import React, { useState } from 'react';
declare global {
interface Window {
hive_keychain: any;
}
}
const HiveLogin: React.FC = () => {
const [username, setUsername] = useState('');
const [loggedInUser, setLoggedInUser] = useState('');
const handleLogin = () => {
if (window.hive_keychain) {
window.hive_keychain.requestSignBuffer(
username,
'Autenticación en Hive',
'Posting',
(response: any) => {
if (response.success) {
setLoggedInUser(username);
alert('¡Autenticación exitosa!');
} else {
alert('Error en la autenticación.');
}
}
);
} else {
alert('Hive Keychain no está instalado.');
}
};
return (
<div>
<h2>Iniciar sesión con Hive</h2>
<input
type="text"
placeholder="Nombre de usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<button onClick={handleLogin}>Iniciar sesión</button>
{loggedInUser && <p>Usuario autenticado: {loggedInUser}</p>}
</div>
);
};
export default HiveLogin;
src/App.tsx para incluir el componente de autenticación:import React from 'react';
import HiveLogin from './components/HiveLogin';
const App: React.FC = () => {
return (
<div>
<h1>Aplicación Hive + React</h1>
<HiveLogin />
</div>
);
};
export default App;
Inicia la aplicación con npm run dev y abre
http://localhost:5173en tu navegador. Ingresa tu nombre de usuario de Hive y haz clic en "Iniciar sesión". Se solicitará la firma a través de Hive Keychain.
Has implementado con éxito la autenticación de usuarios en Hive utilizando Hive Keychain en una aplicación React con Vite y TypeScript.
¡Claro! A continuación, te presento un documento en formato Markdown que aborda:
Una vez que has integrado la autenticación con Hive (por ejemplo, utilizando Hive Keychain), puedes expandir las funcionalidades de tu aplicación para interactuar plenamente con la blockchain. Algunas acciones posibles incluyen:
Con tus conocimientos en React, Vite, TypeScript y Hive, puedes emprender diversos proyectos. Algunas ideas incluyen:
Para más inspiración, puedes explorar Hive Projects y Awesome Hive, donde encontrarás una amplia gama de aplicaciones y herramientas desarrolladas por la comunidad.(GitHub)
Integrar Hive en el frontend de tus aplicaciones ofrece múltiples beneficios:
A continuación, se presenta una tabla con algunos de los tutoriales que has desarrollado, incluyendo enlaces a tu repositorio de GitHub:
| Título del Tutorial | Descripción breve | Enlace al repositorio | |
|---|---|---|---|
| Multiples Tutoriales | Aprende a integrar React con la blockchain de Hive. | Ver en GitHub |
Aquí tienes una tabla en formato Markdown que resume tus proyectos actuales en Hive, incluyendo una breve descripción de cada uno y enlaces a sus respectivos repositorios en GitHub:
| Proyecto | Descripción | |
|---|---|---|
| hive-sbi-onboarding | Aplicación sencilla para identificar nuevos usuarios de Hive y facilitar su incorporación al programa Hive SBI. | |
| be-hive-sql | Servidor backend que permite ejecutar consultas SQL en la blockchain de Hive, proporcionando una API segura mediante Hive Keychain y tokens JWT para acceder a datos de cuentas y transacciones. | |
| keychain-helper | Librería ligera y amigable para TypeScript y JavaScript que facilita la interacción con Hive Keychain, permitiendo realizar firmas de operaciones y logins seguros de forma sencilla en aplicaciones Web3 modernas. |
ENGLISH
Greetingshiversi sincerely hope that everyone will be very happy and happy. A special greeting for programmers that day by day improve the web ecosystem 3.
To continue to help in the formation of future programming stars in HIVE, I bring you a basic tutorial but full of something that is and should be vital.
This tutorial will guide you to implement user authentication in the Hive blockchain using Hive Keychain in a React application configured with Vite and TypeScript.
npm create vite@latest hive-login-app -- --template react-ts
cd hive-login-app
npm install
npm run dev
npm install @hiveio/dhive
src/components/HiveLogin.tsxwith the following content:import React, { useState } from 'react';
declare global {
interface Window {
hive_keychain: any;
}
}
const HiveLogin: React.FC = () => {
const [username, setUsername] = useState('');
const [loggedInUser, setLoggedInUser] = useState('');
const handleLogin = () => {
if (window.hive_keychain) {
window.hive_keychain.requestSignBuffer(
username,
'Autenticación en Hive',
'Posting',
(response: any) => {
if (response.success) {
setLoggedInUser(username);
alert('¡Autenticación exitosa!');
} else {
alert('Error en la autenticación.');
}
}
);
} else {
alert('Hive Keychain no está instalado.');
}
};
return (
<div>
<h2>Iniciar sesión con Hive</h2>
<input
type="text"
placeholder="Nombre de usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<button onClick={handleLogin}>Iniciar sesión</button>
{loggedInUser && <p>Usuario autenticado: {loggedInUser}</p>}
</div>
);
};
export default HiveLogin;
src/App.tsxto include the authentication component:import React from 'react';
import HiveLogin from './components/HiveLogin';
const App: React.FC = () => {
return (
<div>
<h1>Aplicación Hive + React</h1>
<HiveLogin />
</div>
);
};
export default App;
Start the application with npm run dev and open
http://localhost:5173in your browser. Enter your Hive user name and click "Login." The signature will be requested through Hive Keychain.
You have successfully implemented the Hive user authentication using Hive Keychain in a React with Vite and TypeScript application.
Sure! Here is a Markdown document that addresses:
Once you have integrated the Hive authentication (for example, using Hive Keychain), you can expand the functionality of your application to fully interact with the blockchain. Some possible actions include:
With your knowledge in React, Vite, TypeScript and Hive, you can undertake various projects. Some ideas include:
For more inspiration, you can exploreHive ProjectsandAwesome Hivewhere you will find a wide range of applications and tools developed by the community. (GitHub)
Integrating Hive into the front of your applications offers multiple benefits:
Below is a table with some of the tutorials you have developed, including links to your GitHub repository:
| Title of the tutorial | Short description | Link to the repository | |
|---|---|---|---|
| Multiple tutorials | Learn to integrate React with Hive's blockchain. | See in GitHub |