NOTE: Matrix Unity Tool recently got updated to V0.2 with additional support of Algorand and suppporting wallets. If you were working with V0.1, please make sure you have checked latest API updates
You should import the MatrixSDK
namespace into your script.
using MatrixSDK;
We use a singleton approach, to import the sdk, it is as simple as this:
private MatrixUnityToolkit mw;
void Start() {
mw = MatrixUnityToolkit.Instance;
}
Matrix Unity Tool supports multiple chains and wallets including Algorand, Ethereum, Flow, Aptos & Sui. Follow the example to configure the Web3 wallets and chains for your application:
mw.SetConfig(new WalletName[] { WalletName.PeraWallet, WalletName.MyAlgoConnect }, Blockchain.Algorand, "4160"); // chainIDs: 416001, 416002, 416003 , 4160
We provide 2 ways to connect to a wallet. Each method requires you to pass in a callback function (or not) which provides an instance of the wallet after connection is made:
- Using the provided UI (similar to WalletConnect)
mw.Connect(this.WalletConnected);
- Manually selecting the wallet
mw.Connect(WalletName.PeraWallet, this.WalletConnected);
Getting balance of user's account can be done using the following:
this.walletInstance.GetBalance("{}", null, null, false);
Here, we can pass any optional metadata, onSuccess, onError functions, enable timeout, set timeout duration
Sign transaction can be done using the following:
this.walletInstance.SignMessage("sample message", null, null, false);
Here, we can pass any message, onSuccess, onError functions, enable timeout, set timeout duration
Sign transaction can be done using the following:
this.walletInstance.SignTransaction("{}", null, null, false);
Here, we can pass any optional metadata, onSuccess, onError functions, enable timeout, set timeout duration
Send transaction can be done using the following:
this.walletInstance.SendTransaction("{}", null, null, false);
Here, we can pass any optional metadata, onSuccess, onError functions, enable timeout, set timeout duration
Blockchain Name | Supported |
---|---|
Ethereum | ✔️ |
Flow | ✔️ |
Aptos | ✔️ |
Sui | ✔️ |
Algorand | ✔️ |
Wallet Name | Supported |
---|---|
Metamask | ✔️ |
Pera Wallet | ✔️ |
Petra Wallet | ✔️ |
Sui Wallet | ✔️ |
Blocto | ✔️ |
Since this project is in active development, we are making major breaking changes to both C# & Unity packages.
- Adding new chains: Add new enum, setup the chain ID for the new chain, and add support for new wallets if necessary.
- Adding support for new wallets: Go to src/wallets and create a new class for the wallet inheriting the Wallet.ts. Functionalities not implemented would throw an error in the Unity client. Make sure to update the WalletFactory and enums in both c# and TS code.
- Adding new APIs: Start by updating C# code, by introducing new MethodName enum keys, design a request and response body and then reciprocate this action in TS.
Matrix Unity Tool is a multichain Web3 toolkit which helps integrate Web3 to Unity WebGL based games. It provides a easy-to-use set of APIs inside unity for game developers to design their multichain games.
- Helps integrate WebGL Unity 3D build with Web
- Provides a framework and a standard UI for integrating Web 3 Auth for Algorand, Ethereum, Flow, Aptos & Sui.
- Provides a package for Unity 3D and React
- Customizable UI, API for easy integration
- Provides API for signing messages, transactions
- A game developer should be able to integrate the package provided to add Web support to the non-Web3 game
- A game developer should be able to make use of the provided sample UI for integrating Web3 authentication in Unity3D games
- A game developer should not be required to modify React code as It should be plug-and-play
- A game developer should be able to make use of the provided API for connecting a wallet, carrying out transactions, and fetching wallet balance
Tech Stack -
Frontend - React, Typescript
Client - Unity 3D (and C#)
Others - https://react-unity-webgl.dev/
- Supporting New Chains & Wallets - Add new Classes (parsers) forintegrating more wallets
- Documentation - create easy to follow documentation and a video tutorial series for game developers to use this package.
- Adding more APIs - Add more APIs for blockchain, such as NFT creation, and coin transfer, making it even easier for the developers
- Auto-generate React App - We want to create a CLI-based application that auto-generates a React app that can be directly used as the client front-end.
- The user (game developer) is familiar with Unity and Web3 terminologies and APIs
- Only WebGL build is supported
Solutions
- Connection to a web wallet (eg; Pera Wallet)
- https://flow-view-source.com/
- https://developers.flow.com/tools/fcl-js/reference/api
- https://aptos.dev/guides/aptos-guides
- https://github.com/jeffreylanters/react-unity-webgl/issues/
- https://github.com/jeffreylanters/react-unity-webgl/discussions/
- https://ethereum.stackexchange.com/questions/92095/web3-current-best-practice-to-connect-metamask-to-chrome
- https://stackoverflow.com/questions/56663785/invalid-hook-call-hooks-can-only-be-called-inside-of-the-body-of-a-function-com