Welcome
Getting Started
How to Guides
Application vs Blocklet
Create Blocklet
Compose Blocklets
Develop Blocklet
User and Passport
Communicate with DID Wallet
Blocklet Storage
Using Blocklet Preferences
Build blocklet for profit [deprecated]
Bundle your blocklet
Manage Blocklet Versions
Publish your blocklet to the world
Deploy your blocklet
Read/Write blockchain in blocklet
Operation and maintenance your blocklet
Reference Guides
Conceptual Guides
Frequently Asked Questions
Blocklet SDK (Browser)
The Blocklet JS SDK is the official frontend library provided to assist in the development of blocklets.
It mainly includes the following functions:
- Provide fetch and axios creation functions that can automatically update tokens.
- Provide user profile related interface requests
Initialize the instance#
import { BlockletSDK } from '@blocklet/js-sdk';
const sdk = new BlockletSDK();
User Information Example#
user.getUserPublicInfo
Get user's public information.
type UserPublicInfo = {
avatar: string;
did: string;
fullName: string;
};
const publicInfo: UserPublicInfo = await sdk.user.getUserPublicInfo(userDid: string);
user.getProfileUrl
Get user personal center address
const profileUrl = await sdk.user.getProfileUrl({did: string; locale: string});
user.logout
Log out
await sdk.user.logout();
Create an axios instance#
createAxios
This example will manage the update of sessionToken and refreshToken.
import { createAxios } from '@blocklet/js-sdk';
import type { AxiosRequestConfig, AxiosInstance } from 'axios';
type RequestParams = {
lazy?: boolean; // 是否需要将请求延迟响应
lazyTime?: number; // 延迟响应的时间,默认 300 ms
};
const api = createAxios(config?: AxiosRequestConfig, requestParams?:RequestParams)
createFetch
This instance will manage the updating of sessionToken and refreshToken.
import { createFetch } from '@blocklet/js-sdk';
type RequestParams = {
lazy?: boolean; // 是否需要将请求延迟响应
lazyTime?: number; // 延迟响应的时间,默认 300 ms
};
const api = createFetch(options?: RequestInit, requestParams?:RequestParams)