@tonx/core
The @tonx/core
SDK is a TypeScript library designed to streamline development on the TON blockchain. By integrating the TONX API, it enables developers to quickly build and deploy decentralized applications (dApps). This guide provides step-by-step instructions to set up the SDK, initialize the client, and showcase using core methods .
Getting Started
Before proceeding, ensure your environment meets the following prerequisites:
Environment Setup
-
Install Yarn (if not already installed):
npm install -g yarn
-
Verify Yarn Installation:
yarn --version
-
Initialize a New Project:
mkdir tonx-project && cd tonx-project yarn init -y
-
Install Development Tools:
yarn add tsx
-
Set Up Your Project Structure:
touch main.ts
Installation
Add the @tonx/core
SDK to your project:
npm install @tonx/core
To use the SDK, you’ll need an TON API key.
Visit the TONX API website to register and obtain your free API key.
Example: Query Jetton Wallets
Here’s how you can fetch Jetton wallets associated with a specific contract:
-
Open the
main.ts
file and add the following code:import { TONXJsonRpcProvider } from "@tonx/core"; const main = async () => { const client = new TONXJsonRpcProvider({ network: "mainnet", apiKey: "yourApiKey", // Replace with your TON API key }); try { const response = await client.getJettonWallets({ jetton_address: "0:49389D9E2FF094153FF4AFD99EA2A8CA53046DB42FFE354272BD6431B335567B", limit: 1, }); console.log(response); } catch (error) { console.error(error); } }; main().catch(console.error);
-
Run the script:
yarn tsx main.ts
-
Example Response:
[ { address: '0:8310D00A1EF6A6A69110C3F5DFC875A3A85D6B68644045ACBE47100440971933', balance: '4582985772187', owner: '0:A4771DF58DCE6BB948F40B4CE60BE5E59B832E732AF616B86B2212549824F0E2', jetton: '0:49389D9E2FF094153FF4AFD99EA2A8CA53046DB42FFE354272BD6431B335567B', last_transaction_lt: '49626741000001', code_hash: 'H80Uq+vJFFcfwZRSBQg82w29wQLUkdu8qisgG/VLOJE=', data_hash: 'V5UsPxtG5WsVHDVNa7WN98vPVk+S6AxOPpeqN3FiGb8=' } ]
Methods Overview
The TONXJsonRpcProvider
class provides a wide range of methods to interact with the TON blockchain. These include:
getJettonWallets
getJettonWallets
- Description: Retrieves wallets associated with a specific Jetton contract.
- Parameters:
jetton_address
(string): The Jetton contract address.limit
(integer): The maximum number of results to fetch.
- Returns: A Promise resolving to the queried wallets.
Refer to the TONX API documentation for more details.
Reminder
- Secure TON API Keys: Use environment variables or secret management tools to store sensitive information like API keys.
- Parameter Validation: Ensure that all method inputs meet the expected type definitions.
- Error Handling: Handle errors gracefully using
try-catch
or.catch()
for Promises.
For more advanced use cases and detailed API references, visit the official TONX API documentation.