dauth2ton
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

封装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 'tonconnect'

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()


Readme

Keywords

none

Package Sidebar

Install

npm i dauth2ton

Weekly Downloads

301

Version

0.1.1

License

ISC

Unpacked Size

1.93 MB

Total Files

10

Last publish

Collaborators

  • heriantoxx0