Skip to content

TacBuild/tac-sdk

Repository files navigation

TacSdk

Version npm Downloads Try on RunKit

The TAC SDK makes it possible to create hybrid dApps that let TON users interact directly with EVM smart contracts without needing to manage multiple wallets or understand the complexities of cross-chain messaging.

Documentation

For full documentation and examples, please visit TAC SDK Documentation.

Installation

npm install @tonappchain/sdk

or

yarn add @tonappchain/sdk

Features

The TAC SDK enables you to create frontends that:

  • Connect to TON wallets like Tonkeeper or Tonhub
  • Send transactions from TON to your EVM contracts
  • Track cross-chain transaction status in real-time
  • Handle tokens across both chains
  • Create a seamless user experience for TON users

Available Resources

SDK Components

Data Models

  • Enums: Key enumerations used by the SDK.

    • Network: TESTNET or MAINNET.
    • SimplifiedStatuses: PENDING, FAILED, SUCCESSFUL, OPERATION_ID_NOT_FOUND.
    • OperationType: Detailed operation types (PENDING, TON_TAC_TON, ROLLBACK, etc.).
    • StageName: Identifiers for tracking stages (COLLECTED_IN_TAC, EXECUTED_IN_TAC, etc.).
  • Structs: Core data structures.

Navigate through the linked files for full details on parameters, return types, examples, and more.

TACHeader

Note: The TAC protocol only knows how to send data to contracts that inherit from a TacProxy (TacProxyV1) contract. Such a contract must have a strictly defined signature of its methods. It is specified below:

function myProxyFunction(bytes calldata tacHeader, bytes calldata arguments) external onlyTacCCL {
  // Function implementation 
}

Note: methodName in evmProxyMsg must be either a simple method name or a signature of the form MethodName(bytes,bytes)

The first argument of methods must always be TACHeader. It is sent by protocol, augmented with data from executor.

  • bytes tacHeader: Encoded structure TacHeaderV1, containing:
    • uint64 shardsKey: ID you can specify for yourself an inside message to the TVM contract on the TON network.
    • uint256 timestamp: The block timestamp on TON where the user's message was created.
    • bytes32 operationId: Unique identifier for the message created by the TAC infrastructure.
    • string tvmCaller: The TON user's wallet address that sent the message.
    • bytes extraData: Untrusted extra data, provided by executor with the current message if needed. Otherwise, it's an empty bytes array.

You need to specify all the remaining data you need in tuple (bytes) in arguments. For example this is how arguments for addLiquidity method in UniswapV2 (a special proxy contract for it) will look like:

    const abi = new ethers.AbiCoder();
    const encodedParameters = abi.encode(
        ['tuple(address,address,uint256,uint256,uint256,uint256,address,uint256)'],
        [
            [
                EVM_TOKEN_A_ADDRESS,
                EVM_TOKEN_B_ADDRESS,
                amountA,
                amountB,
                amountAMin, 
                amountBMin,  
                UNISWAPV2_PROXY_ADDRESS, 
                deadline 
            ]
        ]
    );

More details in sendAddLiquidity.ts and in other tests.


Usage

import { TacSdk } from '@tonappchain/sdk';
import { TonConnectUI } from '@tonconnect/ui';
import { ethers } from 'ethers';

// Create EVM payload for DappProxy
const abi = new ethers.AbiCoder();
const encodedParameters = abi.encode(
    ['tuple(uint256,uint256,address[],address)'],
    [
        [
            tokenAAmount,
            tokenBAmount,
            [EVMtokenAAddress, EVMtokenBAddress],
            proxyDapp
        ]
    ]
);
const evmProxyMsg: EvmProxyMsg = {
    evmTargetAddress: DappProxyAddress,
    methodName: 'addLiquidity',
    encodedParameters
};

// Create jetton transfer messages corresponding to EVM tokens, e.g., two tokens for adding liquidity to a pool
const assets: AssetBridgingData[] = [
    {
        address: TVMtokenAAddress,
        amount: tokenAAmount,
        type: AssetType.FT,

    },
    {
        address: TVMtokenBAddress,
        amount: tokenBAmount,
        type: AssetType.FT,
    }
];

const sdkParams: SDKParams = {
    network: Network.TESTNET
};
const tacSdk = await TacSdk.create(sdkParams);

//Send transaction via tonConnect or mnemonic
const tonConnectUI = new TonConnectUI({
    manifestUrl: config.tonconnectManifestUrl as string
});
const sender = await SenderFactory.getSender({
    tonConnect: tonConnectUI
});

await tacSdk.sendCrossChainTransaction(evmProxyMsg, sender, assets);

tacSdk.closeConnections();

For a detailed example, see test/sendSwap.ts or test/sendRemoveLiquidity.ts, which demonstrates swapping tokens and removing liquidity on Uniswap and tracking the transaction status.


License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5