avatarid-js-sdk
v1.0.8
Published
LIFEFORM AvatarID SDK
Downloads
5
Readme
AvatarID API接入说明
简介
AvatarID是由 Lifeform 提供的一套去中心化的自定义头像协议,用户可以通过持有的NFT(无论是721还是1155)自定义自己的专属WEB3头像。
AvatarID API 由 Lifeform 提供给第三方项目的集成API,只需要几行代码就可以在自己的WEB3应用里实现用户的自定义头像功能。
协议地址
bsc 测试网
0xA4fC79e00BdD38722A7fA236d766B4f3f671bF09
bsc 主网
0x905De1Ac381b330c2C187cea0f1685E85a844390
接口说明
1.设置用户自定义头像
/**
* set AvatarId
* @collect avatar's contract address
* @tokenId avatar id
* @addr owner address
* */
async setAvatar
调用示例
const web3 = new Web3(ethereum)
const AvatarIdSDK = new AvatarId(web3)
// collect可默认传空
AvatarIdSDK.setAvatar('',token_id,owner_address)
2.重制用户自定义头像
/**
* reset AvatarId
* @addr owner address
* @collect avatar's contract address
* */
async resetAvatar
调用示例
const web3 = new Web3(ethereum)
const AvatarIdSDK = new AvatarId(web3)
// collect可默认传空
AvatarIdSDK.resetAvatar(owner_address,'')
3.取得用户可用的自定义头像
/**
* get avatar list
* @collect avatar's contract address
* @addr owner address
* @page select a page, start at 0
* @size page size
* */
async getAvatarList
调用示例
const web3 = new Web3(ethereum)
const AvatarIdSDK = new AvatarId(web3)
// collect可默认传空
AvatarIdSDK.getAvatarList('',owner_address,page_num,page_size)
返回示例
[
{
image:'xxx',
token_id:'xxx'
},
{
image:'xxx',
token_id:'xxx'
}
]
4.查看当前用户自定义头像的详情
/**
* get AvatarId details
* @collect avatar's contract address
* @addr owner address
* */
async getStakeAvatarDetails
调用示例
const web3 = new Web3(ethereum)
const AvatarIdSDK = new AvatarId(web3)
// collect可默认传空
AvatarIdSDK.getStakeAvatarDetails('',owner_address)
返回示例
{
image:'xxx',
token_id:'xxx' //如果是默认头像 则返回-1
}
5.授权Avatar资产权限
/**
* approve avatar
* @collect avatar's contract address
* @addr owner address
* @type collect type
* */
async approve
调用示例
const web3 = new Web3(ethereum)
const AvatarIdSDK = new AvatarId(web3)
// collect可默认传空
AvatarIdSDK.approve('',owner_address,collect_type)
接入说明
安装api
npm i avatarid-js-sdk
引入api代码
import AvatarId from 'avatarid-js-sdk'
初始化api,需要先创建provider,然后构造avatarid 实例
const web3 = new Web3(ethereum) const AvatarIdSDK = new AvatarId(web3)
getAvatarList可以获得用户持有的avata nft 列表
getStakeAvatarDetails可以查看当前自定义头像详情,如果用户没设置过,会有默认头像
如果需用支持用户自定义头像,需要做资产合约的approve接口就行授权操作。授权通过后,通过调用setAvatar,进行头像设置,也可以引导用户到Lifeform官网的设置页面就行设置,https://www.lifeform.cc/avatarid
如果用户希望取消该功能,只需要执行resetAvatar接口就可以完成,并返回用户质押的资产。
如果需要支持项目方自己的NFT作为自定义头像,请发邮件到:[email protected]