@ton-api/ton-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-beta.5 • Public • Published

@ton-api/ton-adapter

⚠️ Note that the package is in public beta right now.

Overview

This is adapter allows to utilize TonApi client with @ton/ton and @ton/core libraries

Getting started

Install the package using npm or yarn:

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

Usage

Create a tonapi client first to use the adapter. You can open any wrapper of @ton/ton of @ton/core-compatible smart contract using the adapter. It means that you don't need additional rpc provider for the contracts-wrappers, you can work with the, using tonapi.

import { TonClient, WalletContractV4, internal } from "@ton/ton";
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
import { ContractAdapter } from "@ton-api/ton-adapter";

const httpClient = new HttpClient({
    baseUrl: 'https://tonapi.io',
    baseApiParams: {
        headers: {
            Authorization: `Bearer ${YOUR_TOKEN}`,
            'Content-type': 'application/json'
        }
    }
});

// Initialize the ton API client
const client = new Api(httpClient);

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


// Create wallet contract
const mnemonics = await mnemonicNew();
const keyPair = await mnemonicToPrivateKey(mnemonics);
const workchain = 0;
const wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });

// Use tonapi adapter to work with any @ton/ton smart-contracts wrappers
const contract = adapter.open(wallet);

// Get balance
const balance: bigint = await contract.getBalance();

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

Package Sidebar

Install

npm i @ton-api/ton-adapter

Weekly Downloads

5

Version

0.0.1-beta.5

License

GPL-3.0

Unpacked Size

37.5 kB

Total Files

7

Last publish

Collaborators

  • siandreev