A native integration of the Wax Cloud Wallet compatible with all major Build Targets (WebGL, Windows, Mac, Linux, Android, iOS) without relying on WebViews.
Requires Unity 2019.1+ with .NET 4.x+ Runtime
This package can be included into your project by either:
- Installing the package via Unity's Package Manager (UPM) in the editor (recommended).
- Importing the .unitypackage which you can download here.
- Manually add the files in this repo.
- Installing it via NuGet.
In your Unity project:
-
Open the Package Manager Window/Tab
-
Click on + icon and then click on "Add Package From Git URL"
-
Enter URL:
https://github.com/liquiidio/CloudWalletUnity.git#upm
Download the UnityPackage here.
Then in your Unity project:
-
Open up the import a custom package window
-
Navigate to where you downloaded the file and open it.
-
Check all the relevant files needed (if this is a first time import, just select ALL) and click on import.
Download this project here.
Then in your Unity project, copy the sources from CloudWalletUnity
into your Unity Assets
directory.
- Create a new script inheriting from MonoBehaviour
- Add a member of type WaxCloudWalletPlugin as well as a string to store the name of the user that is logged in.
- In the Start-method, instantiate/initialize the CloudWalletPlugin.
- Assign the EventHandlers/Callbacks allowing the CloudWalletPlugin to notify your Script about events and related Data
- Initialize the CloudWalletPlugin. This will start the communication with the Browser and create the binding between your local script and the wax-js running in the Browser.
private CloudWalletPlugin _cloudWalletPlugin;
public string Account { get; private set; }
public void Start()
{
// Instantiate the WaxCloudWalletPlugin
_cloudWalletPlugin = new GameObject(nameof(CloudWalletPlugin)).AddComponent<CloudWalletPlugin>();
// Assign Event-Handlers/Callbacks
_cloudWalletPlugin.OnLoggedIn += (loginEvent) =>
{
Account = loginEvent.Account;
Debug.Log($"{loginEvent.Account} Logged In");
};
_cloudWalletPlugin.OnError += (errorEvent) =>
{
Debug.Log($"Error: {errorEvent.Message}");
};
_cloudWalletPlugin.OnTransactionSigned += (signEvent) =>
{
Debug.Log($"Transaction signed: {JsonConvert.SerializeObject(signEvent.Result)}");
};
// Inititalize the WebGl binding while passign the RPC-Endpoint of your Choice
_cloudWalletPlugin.InitializeWebGl("https://wax.greymass.com");
}
- Logging in to the Wax Cloud Wallet Plugin is as simple as calling the Login-Method on the previously initialized WaxCloudWalletPlugin-instance.
- Once the Login-Method is called, the user will be prompted with the standard Wax Cloud Wallet Login prompt and will be requested to follow the typical Login/Authentication-Scheme.
public void Login()
{
_cloudWalletPlugin.Login();
}
- The following example shows how a Token Transfer Action can be created and passed to the Sign-Method of the previously initialized WaxCloudWalletPlugin-Object.
// transfer tokens using a session
private async Task Transfer(string frmAcc, string toAcc, string qnty, string memo)
{
var action = new EosSharp.Core.Api.v1.Action()
{
account = "eosio.token",
name = "transfer",
authorization = new List<PermissionLevel>() { _session.Auth },
data = new Dictionary<string, object>
{
{"from", frmAcc},
{"to", toAcc},
{"quantity", qnty},
{"memo", memo}
}
};
// Sign
_cloudWalletPlugin.Sign(new[] { action });
}
- Transacting/Signing Transactions with the Wax Cloud Wallet Plugin is as simple as calling the Sign-Method on the previously initialized WaxCloudWalletPlugin-instance while passing a EosSharp Action Object.
- To be able to perform a transaction, a user needs to login first. Once a user has been logged in, the Plugin will automatically use the the logged in user to sign transactions.
- Once the Sign-Method is called (while a user has previously logged in and a valid Action Object has been passed) the user will automatically be prompted with the typical Wax Cloud Authentication and Signing-Scheme.
- If "Auto-Signing" is enabled, transactions will be signed automatically.
- Immediately a Transaction-Signing is successful, the OnTransactionSigned-Handler will be called (see the Quick-Start example)
- If an error occurs, the OnError-Handler will be called (see the Quick-Start example)
public void Transact(EosSharp.Core.Api.v1.Action action)
{
_cloudWalletPlugin.Sign(new[] { action });
}