allartprotocol / unity-solana-wallet

The First Open-Source Unity-Solana Wallet with NFT support
285 stars 133 forks source link

# Unity-Solana Wallet The First Open-Source Unity-Solana Wallet with NFT support The Unity-Solana Wallet is an essential bridge connecting game developers and the Solana blockchain. With Solana’s quick and low-cost transactions, games can start using blockchain technology like never before - in real-time. Thousands of developers will bring millions of players into the Solana ecosystem. This will, in turn, make the Solana projects benefit from an increased number of participants, and cross-protocol interoperability in games will take us beyond the current understanding of DeFi. Unity-Solana Wallet uses Solnet's implementation .NET SDK, but we had to modify the library to make it Unity compatible with .NET Standard 2.0 and .NET 4.x. Solnet is Solana's .NET SDK to integrate with the .NET ecosystem. [Solnet](https://blockmountain.io/Solnet/).

Features

Dependencies

External packages

Roadmap

Installation

  1. Clone this repository outside of the main Unity project
  2. Go to Package Manager in your project
  3. Click on the plus in the top left corner and select "Add package from disk"
  4. Select package.json file from a cloned dir
  5. Once the package is installed, in the Package Manager inspector you will have Samples. Click on Import

Step-by-step instructions

  1. If you have an older version of Unity that doesn't have imported Newtonsoft.Json just import it.
  2. After importing the wallet Unity will throw unity-plastic error. Just restart Unity.
  3. Create a new scene.
  4. Import WalletController prefab into your scene.
  5. Set Client Source (Mainnet/Testnet/Devnet/Custom uri) and Storage Method (Json/Simple txt) on SimpleWallet script in WalletController prefab.
  6. If you use custom URI be careful to use WS/WSS instead of HTTP/HTTPS because WebSocket does not work with HTTP / HTTPS.
  7. To save mnemonics in JSON format, select the JSON storage method, and if you want to save it as a regular string, select Simple Txt.
  8. If you want to use mnemonics saved in JSON format, you must deserialize it first. You have an example in ReGenerateAccountScreen.cs in the ResolveMnemonicsByType method.
  9. Create new Canvas
  10. Import WalletHolder prefab into the Canvas or if you want your design just import wallet prefab and customize the scene like we did with WalletHolder.

Functionalities description

Login Screen

Create Wallet Screen

Regenerate Wallet Screen

Wallet Screen

Recieve Screen

Transfer Screen

Introduction to WalletBaseComponent.cs

Create account

public async void CreateAccount(Account account, string toPublicKey = "", long ammount = 1000)

Start connection

public SolanaRpcClient StartConnection(EClientUrlSource clientUrlSource, string customUrl = "")

Generate wallet with mnemonics

 public Wallet GenerateWalletWithMenmonic(string mnemonics)

Start WebSocket connection

public void StartWebSocketConnection()

Introduction to WebsocketService.cs

Close connection

 public void CloseConnection()
 {
     if (_socket == null) return;

     _socket.CloseAsync();
 }

-To close WebSocket connection call CloseConnection from WebSocketService.cs

Introduction to Nft.cs

Find program address

public static Solnet.Wallet.PublicKey FindProgramAddress(string mintPublicKey, string programId = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")

Resize

private static Texture2D Resize(Texture2D texture2D, int targetX, int targetY)

This project is licensed under the MIT License - see the LICENSE file for details