I am trying to create a game and integrate the unity SDK + soar into it for accounts / leaderboards ETC, and I'd like to make it so that the "play" button is unlocked for each turn by paying a certain amount of sol (say, 0.0001) (similar to an arcade where u throw tokens in to unlock the game if that makes sense). I have the unity game ready, and have managed to add the wallet connector & display balance from the docs i found on the Unity SDK, but i'm having trouble creating a script to charge tokens when clicking the button. Any advice on how I should go about this? tysm <3
1 Answer
A simple approach would be to create a program with one instruction that accepts the payment and creates a record on-chain (you could use SOAR achievement for the latter or a custom-made account/PDA), indicating that the user (public key) paid and is allowed to play. Upon login, you could make them sign a message, verifying that the user owns the public key and check the on-chain record.
- For the program you can use this as an example/reference: https://beta.solpg.io/tutorials/tiny-adventure-two
- Use Solana Unity Anchor tool to generate the Unity client for the program: https://github.com/magicblock-labs/Solana.Unity.Anchor
- Build the pay/unlock transaction in Unity, you can find an example here: https://github.com/magicblock-labs/Solana-Unity-Chess/blob/main/Assets/Solana%20Integration/On-Chain/SolChessClient.cs#L240