Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Python SDK for tonapi.io.
Information about the API can be found in the documentation.
To use the API you need an API key, you can get it here tonconsole.com.
For creating wallets, transferring TON, Jetton, NFTs, and other operations, recommend using tonutils in combination with TonapiClient
. For more information, refer to the library documentation.
pip install pytonapi
Asynchronous
from pytonapi import AsyncTonapi
# Declare an asynchronous function for using await
async def main():
# Create a new Tonapi object with the provided API key
tonapi = AsyncTonapi(api_key="Your API key")
# Specify the account ID
account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess" # noqa
# Retrieve account information asynchronously
account = await tonapi.accounts.get_info(account_id=account_id)
# Print account details
print(f"Account Address (raw): {account.address.to_raw()}")
print(f"Account Address (userfriendly): {account.address.to_userfriendly(is_bounceable=True)}")
print(f"Account Balance (nanoton): {account.balance.to_nano()}")
print(f"Account Balance (amount): {account.balance.to_amount()}")
if __name__ == '__main__':
import asyncio
# Run the asynchronous function
asyncio.run(main())
Synchronous
from pytonapi import Tonapi
def main():
# Create a new Tonapi object with the provided API key
tonapi = Tonapi(api_key="Your API key")
# Specify the account ID
account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess" # noqa
# Retrieve account information
account = tonapi.accounts.get_info(account_id=account_id)
# Print account details
print(f"Account Address (raw): {account.address.to_raw()}")
print(f"Account Address (userfriendly): {account.address.to_userfriendly(is_bounceable=True)}")
print(f"Account Balance (nanoton): {account.balance.to_nano()}")
print(f"Account Balance (amount): {account.balance.to_amount()}")
if __name__ == '__main__':
main()
Additional examples can be found examples folder.
TON - EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess
USDT (TRC-20) - TGKmm9H3FApFw8xcgRcZDHSku68vozAjo9
We welcome your contributions! If you have ideas for improvement or have identified a bug, please create an issue or submit a pull request.
Supported by TONAPI and TON Society (Grants and Bounties program).
This repository is distributed under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.
FAQs
Provide access to indexed TON blockchain.
We found that pytonapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.