0.2.14 • Published 12 months ago

dauth2ton v0.2.14

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

封装toncnnect的调用

提供接口

  1. 获取sdk支持的钱包信息

getWallets = (): Promise<Wallet[]>

interface Wallet{
    name: string //钱包名字
    type: WalletType //钱包支持的类型
}


enum WalletType {
    desktop = 1,
    mobile = 2,
    extension = 4
}
  1. 设置当前钱包
setCurrentWallet = (wallet:Wallet):WalletUrlInfo

interface WalletUrlInfo{
    url: string //链接钱包的链接
    iconUrl: string//钱包的图标链接
}
  1. 打开当前钱包
open = (openType:WalletType):void

//因为一个钱包支持多种打开方式,所以需要指定当前打开类型
  1. 断开钱包链接
 close = () :void
  1. 查询钱包余额
queryWalletBalance = async(): Promise<string>

//避免精度丢失,使用string
  1. 调用钱包转账

 transfer = (to: string, amount:string, transferCb : SendTranscationCallback, errorCb : ErrorCallback)

//转账需要接收两个回调,一个转账成功回调,二个是转账出错回调
  1. 查询钱包地址
queryWalletAddress = () : string

使用方法

import { TonWalletConnector, WalletType, Wallet, WalletState , init} from 'dauth2ton'

init("test");//init("prod")

const tester = new TonWalletConnector(
  (state: WalletState | null) => {
    console.log(state)
    connected.value = state !== null
    tester.queryAddress()

   

    tester.getCurrentConnecWallet()
  },
  (err: Error) => {
    console.error(err)
  }
)


 tester.queryTonToUSDRate()

 ///withdraw

 前端 发起提现请求-》游戏后端,处理提现数量逻辑-》到infras->wowfish后端请求签名-》返回nonce和signture到游戏后端->游戏后端返回到游戏前端,传入

  tester.withdrawWow( 提现数量, nonce, signature).then((res) => {
        console.log("withdraw sucess", res)
      }).catch((er) => {
        console.log("withdraw faild", er)
      })

///消费wow

tester.consumeWow(消费数量, 附带信息(可以是订单号等))

 ///mint nft

 前端 发起提现请求-》游戏后端,处理提现数量逻辑 ,带上payload-》到infras->wowfish后端请求签名-》返回nonce、count、price、signture到游戏后端->游戏后端返回到游戏前端,传入

  tester.minNft( 购买类型, 购买数量, 价格, nonce, signature).then((res) => {
        console.log("withdraw sucess", res)
      }).catch((er) => {
        console.log("withdraw faild", er)
      })

  //前端提交到链上,链上成功后nfras->wowfish后端-》回调到游戏后端  payload 购买成功
0.2.14

12 months ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.1

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago