# tonkey-core-typescript-sdk

> ## Installation

Latest version **0.0.8** (published 2023-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install tonkey-core-typescript-sdk
pnpm add tonkey-core-typescript-sdk
yarn add tonkey-core-typescript-sdk
bun add tonkey-core-typescript-sdk
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-11-21 |
| First published | 2023-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 32.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tonkey |
| Maintainers | tonkey |

## Links

- npm: https://www.npmjs.com/package/tonkey-core-typescript-sdk
- npm.io page: https://npm.io/package/tonkey-core-typescript-sdk

## Dependencies (7)

- [ton](https://npm.io/package/ton.md) ^13.4.1
- [bn.js](https://npm.io/package/bn.js.md) ^5.2.1
- [tonweb](https://npm.io/package/tonweb.md) ^0.0.60
- [ton-core](https://npm.io/package/ton-core.md) ^0.49.0
- [ton3-core](https://npm.io/package/ton3-core.md) ^1.0.1
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [ton-crypto](https://npm.io/package/ton-crypto.md) ^3.2.0

## Recent versions

- 0.0.8 (latest) — 2023-11-21
- 0.0.7 — 2023-06-20
- 0.0.6 — 2023-06-20
- 0.0.5 — 2023-06-20
- 0.0.4 — 2023-06-19
- 0.0.3 — 2023-06-17
- 0.0.2 — 2023-06-15
- 0.0.1 — 2023-06-14

## README

# Tonkey Core SDK

## Installation

```shell
npm i tonkey-core-sdk
npm i ton3-core
npm i ton
```

## Example
### Init

```typescript
import { MultiSig, MULTISIG_CODE_CELL } from 'tonkey-sdk';
import { TonClient } from 'ton';

const ton = new TonClient({
    endpoint: 'RPC_URL',
    apiKey: 'API_KEY',
});

const config = {
    walletId: 8979,
    threshold: 2,
    owners: [
        {
            publicKey: '6003c68217a3d0063fd3b1a93a38c6fc8a45b3d0d78f6618a661c05fe1e7f969',
            address: '0:28f96b8d8f927b8e79514f0097a0600323d19a33a5013b70227d331795df5a01',
        },
        {
            publicKey: '8d2f6c1743b61633094c91356bb4f0697286a89a624856f1a672ab97e119105b',
            address: '0:a6c6c56bf941c19a2d25513005708daaec2ef322d23c7332aece3057ef28ef85',
        },
    ],
};

const multiSig = ton.open(
    MultiSig.createFromConfig(
        {
            walletId: config.walletId,
            threshold: config.threshold,
            owners: config.owners,
        },
        MULTISIG_CODE_CELL
    )
);

const safeAddress = multiSig.address;
const initCodeBoc = multiSig.init.code.toBoc();
const initDataBoc = multiSig.init.data.toBoc();
```

### Get Order Cell of Sending Base Coin

```typescript
import { BOC } from 'ton3-core';

const params = {
    recipient: '0:28f96b8d8f927b8e79514f0097a0600323d19a33a5013b70227d331795df5a01',
    amount: '0.01',
};

const message = MultiSig.createBaseCoinTransferMessage(params.recipient, params.amount);
const { orderCell } = MultiSig.createOrder(config.walletId, [message]);
```

### Get Order Cell of Sending Jetton Token

```typescript
import { BOC } from 'ton3-core';

const params = {
    tokenAddress: '0:11d54d84d2aa5309139575fdf6eda3df5ab3c51a9fa81c6bc2ab90387b4c1cc6',
    recipient: '0:28f96b8d8f927b8e79514f0097a0600323d19a33a5013b70227d331795df5a01',
    amount: '0.01',
};

const message = MultiSig.createJettonTransferMessage(params.tokenAddress, safeAddress, params.recipient, params.amount);
const { orderCell } = MultiSig.createOrder(config.walletId, [message]);
```

### Sign with OpenMask

```typescript
const accounts = await window.ton.send('ton_requestAccounts');
const signerAddress = accounts[0];

const signature = await MultiSig.signOrder(orderCell, async (orderCellHash) => {
    const signature = await window.ton.send('ton_rawSign', [
        {
            data: orderCellHash,
        },
        signerAddress,
    ]);
    return signature;
});
```

### Execute MultiSig Transaction

```typescript
import { Address } from 'ton3-core';
import { hexToBytes } from 'ton3-core/dist/utils/helpers';

const confirmations = [
    '58087e77823d1f0be53cb341762330dc5ac95b92db6239cbe4200666818dcbd42157d69fc6aae414ae32392377391e87819035d5941cf1515e39939dc3652803',
    '462a950ae04e99009018f604900632544cc8be17eaa4d5a84f40adb4d26c58b8265aa6dc53f867b33b960a52f98efdda2e9cf604105e80a2534bd786298bff09',
];

// the order of the signer in safe owner list
const ownerIndex = owners.findIndex((owner) => new Address(owner.address).toString('raw') === signerAddress);

await multiSig.sendExternalMessageWithSignatures(
    ownerIndex,
    orderCell,
    confirmations.map((confirmation, idx) => [hexToBytes(confirmation), idx]),
    async (orderCellHash) => {
        const signature = await window.ton.send('ton_rawSign', [
            {
                data: orderCellHash,
            },
            signerAddress,
        ]);
        return signature;
    }
);
```

## Changelog
### 0.0.7
* Add base coin transfer message parser
* Add jetton token transfer message parser
* Add external message body parser

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