SDKs
SDKs for the TONAPI services
TonAPI provides a set of tools and libraries to simplify the integration with the TON blockchain. This guide covers both official and third-party SDKs available for different programming languages, as well as instructions on how to generate an SDK yourself using the provided Swagger specification.
Official SDKs
We maintain several pre-built SDKs for various programming languages. All of these SDKs are generated from our Swagger files and are optimized for seamless integration into your projects.
- Golang SDK: tonapi-go
- JS/TS Client (dApp free limits, @ton/core compatible): @ton-api/client
Ton Adapter (Compatible with @ton/ton)
The @ton-api/ton-adapter allows you to integrate TonAPI projects that use @ton/ton, enhancing your application with additional blockchain features while maintaining compatibility with @ton/ton.
Third-Party SDKs
These SDKs are maintained by the community and provide additional language support:
- Python SDK: pytonapi on GitHub
- Java SDK: tonapi4j on GitHub
Generating an SDK Using the OpenAPI Generator
If you prefer to generate an SDK yourself, you can do so using the TonAPI OpenAPI specification. Follow these steps:
Install the OpenAPI Generator CLI Tool
Install the OpenAPI generator globally using npm:
npm install @openapitools/openapi-generator-cli -gGenerate the SDK
Use the command below to generate the SDK. The example is for Ruby, but you can specify a different language by changing the -g (generator) parameter.
npx openapi-generator-cli generate -i https://raw.githubusercontent.com/tonkeeper/opentonapi/master/api/openapi.yml -g ruby -o /path/to/outputNote: Replace /path/to/output with the actual directory path where you want to generate the SDK.
Handling Common Issues
If you encounter issues during client generation for certain languages (for example, due to multiple tags per operation or possible future enum value additions), consider using the following options:
-
--openapi-normalizer KEEP_ONLY_FIRST_TAG_IN_OPERATION=trueThis flag helps if the Swagger file contains multiple tags for a single operation and your SDK generator/language has trouble with that (it keeps only the first tag). -
--additional-properties=enumUnknownDefaultCase=trueThis flag ensures your generated SDKs will gracefully handle new/unknown enum values in the future by mapping them to a default enum case such asUNKNOWN_DEFAULT(supported in Java, Kotlin, TypeScript, Swift, etc).
You can combine these options in a single command, for example:
npx openapi-generator-cli generate \
--openapi-normalizer KEEP_ONLY_FIRST_TAG_IN_OPERATION=true \
-i https://raw.githubusercontent.com/tonkeeper/opentonapi/master/api/openapi.yml \
-g ruby \
-o /path/to/output \
--additional-properties=enumUnknownDefaultCase=trueTo run the OpenAPI generator, you need to have Node.js and npm installed on your system, as well as Java 11 or higher. These are necessary prerequisites to ensure proper execution.
Alternatively, if you prefer not to use npm, the OpenAPI Generator can be installed via Docker, Homebrew (for macOS), or by downloading the JAR file. Detailed instructions for these installation methods are available in the OpenAPI Generator Installation Guide.
How is this guide?