Quick Start Example
This guide will walk you through using the Bitfold AI Wallet typescript SDK in a frontend project. React is chosen here since it is popular, but it works just as well in your favorite frontend framework, whatever it may be.
Prerequisites
- Node.js (v15 or later)
- npm (v6 or later)
Create a new React project
- Open your terminal and run:
npx create-react-app ai-wallet-demo --template typescript
- Navigate to the project directory:
cd ai-wallet-demo
Install the Bitfold AI Wallet SDK
npm install ai-walletCreate the demo component
Create a new file src/components/Demo.tsx:
import React, { useState, useEffect } from 'react';import { AIWallet } from '@bitfold/wallet';
const ai = new AIWallet();
const Demo = () => { const [response, setResponse] = useState<string>('');
const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { const completion = await ai.chat.completions.create({ messages: [{ role: 'user', content: 'Hello, from Bitfold!' }], }); setResponse(completion.choices[0].message.content || ''); } catch (error) { console.error('Error:', error); setResponse('An error occurred'); } };
return ( <div> <h1>AI Wallet Demo</h1> <form onSubmit={handleSubmit}> <button type="submit">Send Request</button> </form> <div> <h2>Response:</h2> <p>{response}</p> </div> </div> );};
export default Demo;Update App.tsx
Replace the contents of src/App.tsx with:
import React from 'react';import Demo from './components/Demo;import './App.css';
function App() { return ( <div className="App"> <Demo/> </div> );}
export default App;Run the application
Start the development server:
npm startVisit http://localhost:3000 in your browser to see the demo.
🎉 Congratulations on completing the getting started guide! For more details on the capabilities of the Bitfold AI Wallet