1.1.7 • Published 4 years ago

dappbirds-js-sdk v1.1.7

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

该文档的目的是让开发者可以快速接入 dappbirds-js-sdk,主要包括以下内容:

  • 相关环境介绍
  • SDK 文件介绍及加载方式
  • SDK 初始化
  • SDK 关键方法描述
  • 错误码列表及释义
  • 资源下载

相关环境描述

注意:体验线上或线下 Demo,需要切换到钱包对应的网络(TEST_NET, MAIN_NET)


SDK 文件介绍及加载方式

  • SDK文件:

    • index.min.js
    • index.html Demo 页面
  • 加载方式:

    • index.min.js 复制到项目中,通过 script 加载即可
    • 或直接引入 DAppbirds 提供的 CDN URL加载 //dapp.cdn.static.mmzhuli.com/static/dappbirds-js-sdk/index.min.js?t=1568794420
    • 或通过 npm 引入 npm install dappbirds-js-sdk import { DappBirdsEngin } from 'dappbirds-js-sdk'

SDK 初始化

  • 引入 SDK js 文件
  • 参考以下代码进行接入

    const enginConfig = {
      chain_type: 7,
      test_mode: false
    };
    DappBirdsEngin.init(enginConfig).then((DappBirdsSDK) => {
      const config = {
        app_id: 1,
        contract_address: '',
        silent_login: 1,
        chain_sign_txt: '',
        invite_code: ''
      };
      const dappBirdsInstance = DappBirdsSDK.init(config);
      // TODO
    }).catch((ex) => {
      console.error(ex);
    });
  • enginConfig 参数:

    参数名描述是否必填约束
    chain_type公链类型EOS:2,NEO:5,本体:7,BOS:9,IOST:10,维基:12,EOSC:14,ThunderCore:16,NULS:18
    test_mode是否测试环境默认为:false,测试时可置为 true

    上线前需将 test_mode 参数设置为 false, 或删除此参数,切记!

  • config 参数:

    参数名描述是否必填约束
    app_id应用app_id由平台分配
    contract_address链上合约地址由平台分配
    silent_login是否静默登录静默登录, 设置1可以不验证签名登录 (须后台先配置参数)
    chain_sign_txt签名字符串链上签名时的字符串
    invite_code邀请码邀请者的标识

SDK 关键方法描述

  • sign(config) 用户签名
  • checkOpenId(openid) 检测openid是否有效
  • getAddress() 用户钱包地址
  • getOpenId() 用户唯一标识
  • getBalance() 钱包账户余额方法(公链上余额)
  • sendTransaction(config) 发送交易

sign

const config = { flag_chain: 0 };
// 游戏第一次打开调用
dappBirdsInstance.sign(config).then(signData => {
  console.log(signData);
}).catch(ex => {
  console.error(ex);
});

config 参数:

参数名描述是否必填约束
flag_chain是否开启链上签名默认不开启, 1:开启链上签名

返回值 signData 描述

名称描述
openid用户 openid,需要将 openid 本地缓存,下次进入游戏需要用 checkOpenId(openid) 检测是否有效
_timestampunix时间戳
_signature签名串

checkOpenId

// 在有缓存 openid 的情况下调用,如果进入 catch,则说明 openid 无效(需要清空当前本地的登录标识,及页面展示的相关用户数据),然后按照签名需求重新调用 sign 方法
dappBirdsInstance.checkOpenId(openid).then(() => {
  console.log('success');
}).catch(ex => {
  console.error(ex);
});

getAddress

// 获取用户钱包地址
const address = dappBirdsInstance.getAddress();

getOpenId

// 获取用户唯一标识
const openid = dappBirdsInstance.getOpenId();

getBalance

// 获取用户钱包余额
dappBirdsInstance.getBalance().then(balance => {
  console.log(balance);
}).catch(ex => {
  console.error(ex);
});

sendTransaction

// 发送支付交易
const config = {
  amount: 1,
  order_no: '',
  _timestamp: 12312,
  _signature: ''
};
dappBirdsInstance.sendTransaction(config).then(data => {
  // 交易结果
  console.log(data);
}).catch(ex => {
  console.error(ex);
});

config 参数:

参数名描述是否必填约束
amount交易金额大于0
order_no订单号每次提交不可重复,字母数字组合,长度不超过36位
_timestamp下单后返回的 _timestamp
_signature下单后返回的 _signature

返回值 data 描述:

名称描述
order_no订单号
txid交易流水号

SDK 错误码列表及释义

所有catchError对象示例:

{
  code: '错误码',
  msg: '错误描述信息',
  desc: '详细描述信息或一些辅助查错信息'
}

错误码描述:

描述
1配置参数错误
2接口请求出错
3非自定义 throw 出错,逻辑异常
10001钱包环境检测失败,未安装
10002钱包环境初始化失败,未开锁
10003用户没有授权
10004用户取消操作,比如 sign 取消,sendTransaction 取消
10005用户 openid 校验失败,请重新调用 sign 签名, 比如 sendTransaction 方法
10006用户还没有创建钱包
10007钱包地址还没有激活
10008用户余额不足

资源下载

SDK下载

钱包下载

官方钱包下载

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago