0.0.8 • Published 12 months ago

tonkey-core-typescript-sdk v0.0.8

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

Tonkey Core SDK

Installation

npm i tonkey-core-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 message = MultiSig.createBaseCoinTransferMessage(params.recipient, params.amount);
const { orderCell } = MultiSig.createOrder(config.walletId, [message]);

Get Order Cell of Sending Jetton Token

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

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

0.0.7

  • Add base coin transfer message parser
  • Add jetton token transfer message parser
  • Add external message body parser
0.0.8

12 months 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