@ton-api/client
is an automatically generated SDK that provides seamless access to the endpoints offered by tonapi.io. This client is specifically designed to integrate with the TON blockchain, offering type-safe interactions and full compatibility with @ton/core library.
For a detailed view of all methods and endpoints in a Swagger format, refer to the Swagger documentation For detailed API information and endpoint descriptions, please refer to the official documentation or check the Swagger UI for an interactive method list.
For usage examples, check the TonAPI Cookbook.
- Full coverage of tonapi.io endpoints
- Type-safe interactions with the API
- Seamless integration with
@ton/core
Additionally, @ton-api/ton-adapter
enables users to work with contracts written for @ton/ton
through @ton-api/client
, ensuring seamless integration while maintaining their existing code structure.
To use this SDK, you need to:
- Set up an account at tonconsole.com
- Obtain an API key for authentication
Install the package and its peer dependencies using npm, yarn, or pnpm:
npm install @ton-api/client @ton/core
# or
yarn add @ton-api/client @ton/core
# or
pnpm add @ton-api/client @ton/core
Here's a basic example to get you started:
import { TonApiClient } from '@ton-api/client';
import { Address } from '@ton/core';
// Initialize the TonApi
const ta = new TonApiClient({
baseUrl: 'https://tonapi.io',
apiKey: 'YOUR_API_KEY'
});
// Use the API
async function fetchAccountEvents() {
const address = Address.parse('YOUR_ADDRESS_HERE');
const events = await ta.accounts.getAccountEvents(address, { limit: 50 })
console.log('Account events:', events)
}
fetchAccountEvents();
For detailed API information and endpoint descriptions, please refer to the official documentation.
const collectionAddress = Address.parse('COLLECTION_ADDRESS_HERE');
ta.nft.getNftCollection(collectionAddress)
.then(collection => console.log('NFT Collection:', collection))
.catch(error => console.error('Error fetching NFT collection:', error));
const jettonAddress = Address.parse('JETTON_ADDRESS_HERE');
ta.jettons.getJettonInfo(jettonAddress)
.then(jetton => console.log('Jetton Info:', jetton))
.catch(error => console.error('Error fetching jetton info:', error));
import { beginCell, external, storeMessage, Address } from '@ton/core';
const accountAddress = Address.parse('JETTON_ADDRESS_HERE');
const exampleMessage = beginCell()
.storeUint(0, 64)
.endCell();
const messageBoc = beginCell()
.store(
storeMessage(
external({
to: address,
body: exampleMessage
})
)
)
.endCell();
ta.blockchain.sendBlockchainMessage({
boc: messageBoc
});
MIT