2.2.2 • Published 3 months ago

tonkey-sdk v2.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

Tonkey SDK

Installation

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

Example

Init

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

import { BOC } from 'ton3-core';

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

const remark = 'this is an order to send base coin';

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

Get Order Cell of Sending Jetton Token

import { BOC } from 'ton3-core';

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

const remark = 'this is an order to send jetton token';

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

Sign with OpenMask

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

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

v2.0.0

  • Feature: upgrade SDK based on contract v2.0.0
  • Fix: increase the msg value for Jetton transfer
  • Refactor: change default timeout to 20 years
  • Refactor: add BOC size check

v2.1.4

  • Feature: support comment for base coin and jetton transfer
  • Feature: change remark encoding from UTF-16 to UTF-8
2.2.2

3 months ago

2.2.1

4 months ago

2.2.0

4 months ago

1.0.4

6 months ago

1.0.3

6 months ago

2.1.5

6 months ago

2.0.4-beta

7 months ago

2.0.5-beta

7 months ago

2.1.2-beta

7 months ago

2.0.2-beta

7 months ago

2.0.3-beta

7 months ago

2.0.0-beta

7 months ago

2.1.0-beta

7 months ago

2.1.3-beta

7 months ago

2.0.1-beta

7 months ago

2.1.1-beta

7 months ago

2.1.4-beta

7 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

10 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago