前端集成 .bit
dotbit.js
dotbit.js 是一个 npm 包,封装了对于 indexer 的 JSON-RPC 的调用。
Dapp 只需集成该 SDK,并调用对应的接口(数据由 .bit das-account-indexer),即获得所需的数据。
注意,应用在得到用户设置的数据的值后,要对其值的有效性进行校验
依赖
使用该 SDK 需要依赖 das-account-indexer 所提供的 JSON-RPC 服务。
我们推荐开发者自建 .bit Indexer,但是开发者可以在开发阶段使用官方的 .bit Indexer 服务来做开发、测试,详见:
使用示例
// For ES Module
import { createInstance } from 'dotbit'
const dotbit = createInstance()
// Get the account info of a .bit account
dotbit.records("jeffx.bit").then(console.log)
输出
[
{
key: 'address.polygon',
label: 'Usually',
value: '0xB2bE2887A26f44555835EEaCC47d65B88b6B42c2',
ttl: '300',
type: 'address',
subtype: 'polygon'
},
{
key: 'profile.discord',
label: 'Discord Username',
value: 'west.bit#8906',
ttl: '300',
type: 'profile',
subtype: 'discord'
},
]