Socket
Book a DemoInstallSign in
Socket

@ton-api/ton-adapter

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ton-api/ton-adapter

TonApi adapter for @ton/ton

latest
Source
npmnpm
Version
0.4.1
Version published
Weekly downloads
4.7K
26.08%
Maintainers
2
Weekly downloads
 
Created
Source

@ton-api/ton-adapter

Overview

@ton-api/ton-adapter is an adapter that enables integration between TonApi client and the @ton/ton and @ton/core libraries. This adapter allows developers to use TonApi's functionality while maintaining compatibility with existing TON blockchain development tools.

Features

  • Integration with @ton-api/client
  • Compatibility with @ton/ton and @ton/core contract wrappers
  • Eliminates the need for additional RPC providers
  • Facilitates blockchain interactions through TonApi

Installation

Install the package and its peer dependency using npm, yarn, or pnpm:

npm install @ton-api/client @ton-api/ton-adapter
# or
yarn add @ton-api/client @ton-api/ton-adapter
# or
pnpm add @ton-api/client @ton-api/ton-adapter

Quick Start

Here's a basic example to get you started:

import { SendMode, WalletContractV5R1, internal } from '@ton/ton';
import { mnemonicNew, mnemonicToPrivateKey } from '@ton/crypto';
import { TonApiClient } from '@ton-api/client';
import { ContractAdapter } from '@ton-api/ton-adapter';

// Initialize TonApi client
const ta = new TonApiClient({
    baseUrl: 'https://tonapi.io',
    apiKey: 'YOUR_API_KEY'
});

// Create an adapter
const adapter = new ContractAdapter(ta);

// Create and use a wallet contract
async function main() {
    const mnemonics = await mnemonicNew();
    const keyPair = await mnemonicToPrivateKey(mnemonics);
    const wallet = WalletContractV5R1.create({ workchain: 0, publicKey: keyPair.publicKey });

    // Open the contract using the adapter
    const contract = adapter.open(wallet);

    // Get balance
    const balance = await contract.getBalance();
    console.log('Balance:', balance.toString());

    // Send a transfer
    const seqno = await contract.getSeqno();
    await contract.sendTransfer({
        seqno,
        secretKey: keyPair.secretKey,
        sendMode: SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS,
        messages: [
            internal({
                value: '0.001',
                to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
                body: 'Hello world'
            })
        ]
    });
}

main().catch(console.error);

Usage

  • Create a TonApi client.
  • Initialize the ContractAdapter with the TonApi client.
  • Use the open method of the adapter to work with any @ton/ton or @ton/core compatible smart contract wrapper.
  • Interact with the contract as you would normally, but now using TonApi under the hood.

License

MIT

Keywords

TON

FAQs

Package last updated on 23 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.