Welcome to the Singularity Web SDK Boilerplate User Guide! This document will provide step-by-step instructions on setting up, configuring, and using the boilerplate project to integrate with SingularityNET services.
Before you begin, ensure you have the Node.js (v18 or higher)
installed on your machine
If you don't have Node.js installed, you can follow the official installation instructions provided by Node.js:
Go to the official Node.js website: Node.js Download. Follow the instructions for your specific operating system (Windows, macOS, or Linux). These instructions will guide you through the process of downloading and installing the latest version of Node.js, including npm, the Node.js package manager.
After installation, verify that Node.js was installed correctly by running the following command in your terminal:
node -v
Ensure that the version displayed is v18 or higher.
Follow these steps to set up the project:
- Clone the repository and navigate to the directory:
git clone https://github.com/singnet/Web-JS-SDK-Boilerplate
cd Web-JS-SDK-Boilerplate
- Copy the .env.example file to .env and update the values as necessary:
cp .env.example .env
- Configure environment variables
The project requires certain environment variables to be set in the .env
file. Below is a list of the required variables and their descriptions:
Variable Name | Description | Where to Get It |
---|---|---|
REACT_APP_ENV |
Specifies the environment (development or production ). |
Set this manually. |
REACT_APP_ALCHEMY_API_KEY |
API key for accessing Alchemy services. | Alchemy API Keys |
REACT_APP_PARTICLE_AUTH_PROJECT_ID |
Project ID for Particle authentication. | Particle Network |
REACT_APP_PARTICLE_AUTH_CLIENT_KEY |
Client key for Particle authentication. | Particle Network |
REACT_APP_PARTICLE_AUTH_APP_ID |
Application ID for Particle authentication. | Particle Network |
REACT_APP_NETWORK |
Specifies the blockchain network to connect to (mainnet or sepolia ). |
Set this manually. |
REACT_APP_INFURA_PROJECT_ID |
Project ID for accessing Infura services. | Infura |
REACT_APP_WALLET_CONNECT_PROJECT_ID |
Project ID for Wallet Connect integration. | Wallet Connect |
- Install the required dependencies:
npm install
- Start the development server:
npm start
After setting up, you can run the project on localhost:3000
to see it in action. The project comes pre-configured with two example services: one for the Ethereum Mainnet and one for the Sepolia Testnet. You can connect your wallet and send a message to the example service to see how it works.
To interact with your own SingularityNET services, you need to compile the .proto
files from your service to JavaScript files
Follow the steps mentioned in the official documentation to generate js
stubs from .proto
definitions. Additionally, provide the namespace_prefix
flag to the generator.
protoc ^
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--js_out=import_style=commonjs,binary,namespace_prefix=[package name]_[org id]_[service]:. --ts_out=service=grpc-web:. \
[proto file name].proto
protoc ^
--plugin=protoc-gen-ts=%cd%/node_modules/.bin/protoc-gen-ts.cmd ^ --js_out=import_style=commonjs,binary,namespace_prefix=[package name]_[org id]_[service]:. --ts_out=service=grpc-web:. ^
[proto file name].proto
After that you need to place them in the src/ExampleService/assets
folder to use it in your service component.
To configure the project to work with your service, you need to specify the orgId
and serviceId
in the src/config/service.ts
file. There are two configurations: one for mainnet and one for sepolia testnet.
- Open the
src/config/service.ts
file. - Update the
orgId
andserviceId
values to match your desired SingularityNET service. orgId: "your-organization-id", serviceId: "your-service-id"
The ExampleService/TestExampleService
component provides a user interface for interacting with your service on the Mainnet/Sepolia network.
- change
runService
function: Send a request to your service with the user-provided text and handle the response. Replace the service call and response handling in therunService
function with the appropriate calls to your own service as defined in the protobuf files.
import { example } from './assets/mainnet/summary_pb_service';
async function runService(text) {
const invokeOptions = {
request: { text: text },
host: 'https://your-service-host',
};
try {
const response = await clientSDK.unary(
example.TextSummary.summary,
invokeOptions
);
newChat('bot', response.getText());
} catch (error) {
console.error('Error running service:', error);
}
}
- use
newChat
funtion to display messages: When you want to display messages from a user or a service in the chat, simply call the newChat function, providing the sender and the message.
newChat('user', "This is a user's message.");
newChat('bot', "This is a bot's response.");