The TON UNITY SDK allows you to connect TON-compatible wallets in Unity using QR code and send transactions. This SDK uses Ton Connect v2 for wallet integration.
Before using this SDK, you need to have:
- Unity 2018 or later installed.
- A TON-compatible wallet.
- Ton Connect v2.
- Clone the repository and add the TonConnect.cs script to your Unity project.
- Create an empty game object in your scene and attach the TonConnect.cs script to it.
- Attach RawImage components to the image1 and image2 variables in the TonConnect script.
- Attach the TransactionSender script to any game object that will send transactions.
- Attach the Button component to the sendTransactionButton variable in the TonConnect script.
- In the Start() method of the TonConnect script, create a ConnectRequest object with the manifestUrl and items properties.
- Serialize the ConnectRequest object to JSON.
- Generate a random ID using the GenerateRandomId() method.
- Generate the Ton Connect URL by appending the v, id, r, and ret parameters to the wallet universal URL.
- Load the QR code image using the LoadQrCode() method and pass in the Ton Connect URL and the RawImage component.
- Open a server-sent events stream using the OpenSSEStream() method and pass in the client ID.
- To send a transaction, simply click the sendTransactionButton. This will call the SendTransaction() method in the TransactionSender script, passing in the client ID.
See the included SampleScene in the Unity project for an example implementation.
This project was created by @andreykobal. Feel free to contribute to this project by submitting pull requests or issues.
