# dauth2ton

> ## 提供接口

Latest version **0.2.14** (published 2024-07-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install dauth2ton
pnpm add dauth2ton
yarn add dauth2ton
bun add dauth2ton
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.14 |
| Published | 2024-07-10 |
| First published | 2024-04-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | heriantoxx0 |

## Links

- npm: https://www.npmjs.com/package/dauth2ton
- npm.io page: https://npm.io/package/dauth2ton

## Dependencies (8)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [tonweb](https://npm.io/package/tonweb.md) ^0.0.66
- [@ton/core](https://npm.io/package/@ton/core.md) ^0.56.3
- [@ton/crypto](https://npm.io/package/@ton/crypto.md) ^3.2.0
- [ua-parser-js](https://npm.io/package/ua-parser-js.md) ^1.0.37
- [patch-package](https://npm.io/package/patch-package.md) ^8.0.0
- [@tonconnect/sdk](https://npm.io/package/@tonconnect/sdk.md) ^3.0.3
- [@types/ua-parser-js](https://npm.io/package/@types/ua-parser-js.md) ^0.7.39

## Recent versions

- 0.2.14 (latest) — 2024-07-10
- 0.2.13 — 2024-07-02
- 0.2.12 — 2024-07-02
- 0.2.11 — 2024-06-26
- 0.2.10 — 2024-06-26
- 0.2.9 — 2024-06-25
- 0.2.8 — 2024-06-25
- 0.2.7 — 2024-06-24
- 0.2.6 — 2024-06-20
- 0.2.5 — 2024-06-19
- 0.2.4 — 2024-06-12
- 0.2.3 — 2024-06-11
- 0.2.2 — 2024-06-06
- 0.2.1 — 2024-06-04
- 0.2.0 — 2024-05-27
- … 12 more at https://npm.io/package/dauth2ton/versions

## README

# 封装toncnnect的调用

## 提供接口

1. 获取sdk支持的钱包信息 
   
```
getWallets = (): Promise<Wallet[]>

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


enum WalletType {
    desktop = 1,
    mobile = 2,
    extension = 4
}

```
2. 设置当前钱包
```
setCurrentWallet = (wallet:Wallet):WalletUrlInfo

interface WalletUrlInfo{
    url: string //链接钱包的链接
    iconUrl: string//钱包的图标链接
}

```

3. 打开当前钱包 
```
open = (openType:WalletType):void

//因为一个钱包支持多种打开方式，所以需要指定当前打开类型
```

4. 断开钱包链接

```
 close = () :void
```

5. 查询钱包余额
```
queryWalletBalance = async(): Promise<string>

//避免精度丢失，使用string
```

6. 调用钱包转账
   
```
 transfer = (to: string, amount:string, transferCb : SendTranscationCallback, errorCb : ErrorCallback)

//转账需要接收两个回调，一个转账成功回调，二个是转账出错回调

```

7. 查询钱包地址
```
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 购买成功

```

---
_Source: https://npm.io/package/dauth2ton · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
