0.4.0 • Published 4 months ago

@ton-api/ton-adapter v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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

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

License

MIT

0.4.0

4 months ago

0.4.0-beta.1

4 months ago

0.3.2-beta.0

5 months ago

0.4.0-beta.0

5 months ago

0.3.1

6 months ago

0.3.0

7 months ago

0.3.0-beta.0

7 months ago

0.2.0-beta.1

9 months ago

0.2.0

9 months ago

0.2.0-beta.0

9 months ago

0.1.0-beta.2

11 months ago

0.1.0-beta.1

11 months ago

0.1.0-beta.0

12 months ago

0.1.0

11 months ago

0.1.0-alpha.1

12 months ago

0.1.0-alpha.2

12 months ago

0.0.1-beta.3

1 year ago

0.0.1-beta.5

1 year ago

0.0.1-beta.4

1 year ago

0.0.1-beta.2

1 year ago

0.0.1-beta.1

1 year ago

0.0.1-beta.0

1 year ago