A native integration compatible with Unity3D and C# allowing users and developers to connect and communicate with Anchor Wallet and ESR-based applications. The Anchor & ESR Integration consists of multiple libraries for the ESR-Protocol, the Anchor-integration, Transports etc. which will be included via Submodules while being packaged and published as a single Package.
Dependencies
NativeWebsocket
WebSocket is a protocol that allows for real-time, two-way communication between a client and a server over a single, long-lived TCP connection. You can get installation instructions from this link
EosSharp
- EosSharp is a library containing the necessary functionallity to serialize and deserialize Actions, Transactions, Blocks and other Data
- In addition it contains the necessary functionallity for all kinds of cryptographic operations
- Lastly it contains the functionallity allowing you and the AnchorLink-Library to access EOSIO or LEAP-based Nodes via their APIs.
EosSharp is not contained in this Package and no matter which installation method you choose, you have to install it manually in addition to this Package.
If you havn't already installed it please follow the instructions in the section for EosSharp of this GitBook.
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. (for Standard .NET users)
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/AnchorLinkSharp.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 the latest Release.
Then in your Unity project, copy the sources from AnchorLinkSharp
into your Unity Assets
directory.
>dotnet add package Liquiid.io.AnchorLinkSharp --version 1.0.3
PM> Install-Package Liquiid.io.AnchorLinkSharp -Version 1.0.3
.NET and Unity3D-compatible (Desktop, Mobile, WebGL) ApiClient for the different APIs. Endpoints have its own set of parameters that you may build up and pass in to the relevant function.
- Add one of the Transport-Prefabs (UiToolkitTransport or CanvasTransport) to your Scene.
- Instantiate a new AnchorLink-object in one of your scripts, assign the Transport and configure your AnchorLink for the usage with WAX and the endpoints of your choice.
[SerializeField]
internal UnityTransport Transport;
internal AnchorLink myLink;
public void Start(){
myLink = new AnchorLink(new LinkOptions()
{
Transport = this.Transport,
ChainId = "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4",
Rpc = "https://api.wax.liquidstudios.io",
});
}
- Add a method calling the Login(identifier)-Method of the previously instantiated AnchorLink.
- When this Method is called from your UI, the Transport will show and Ask the User to Open Anchor to Login.
- After succesfull Login, data about the Account selected and additional session-data is returned your Application, available for use within the session-variable returned.
- Storing the Session will allow you to to promt the User with a Transact-Request without the user having to Login again.
internal LinkSession mySession;
internal async Task LoginAndStoreSession()
{
try
{
var loginResult = await myLink.Login(Identifier);
mySession = loginResult.Session;
Debug.Log($"{mySession.Auth.actor} logged-in");
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
}
}
- To transact without a Session, create a Method and pass a EosSharp Action-Object to it.
- Call await AnchorLink.Transact(new TransactArgs(){Action = action); to transact.
- When this Method is called from your UI or other Code, the Transport will show and Ask the User to Open Anchor to Login and afterwards to Sign a Transaction containing the Action passed.
internal async Task TransactWithoutSession(EosSharp.Core.Api.v1.Action action)
{
var transactResult = await myLink.Transact(new TransactArgs() { Action = action });
Debug.Log($"Transaction broadcast! {transactResult.Processed}");
}
- To transact without a Session, create a Method and pass a EosSharp Action-Object to it.
- Call await LinkSession.Transact(new TransactArgs(){Action = action); to transact.
- When this Method is called from your UI or other Code, the Transport will show and Ask the User to Sign a Transaction containing the Action passed (without requiring the User to Login again).
internal async Task TransactWithoutSession(EosSharp.Core.Api.v1.Action action)
{
var transactResult = await mySession.Transact(new TransactArgs() { Action = action });
Debug.Log($"Transaction broadcast! {transactResult.Processed}");
}
- Following Example shows how a Token Transfer Action could be created and passed to the Transact-Method using a Session.
// 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}
}
};
try
{
var transactResult = await mySession.Transact(new TransactArgs() { Action = action });
Debug.Log($"Transaction broadcast! {transactResult.Processed}");
waitCoroutine = StartCoroutine(SwitchPanels(Transport.currentPanel, CustomActionsPanel, 1.5f));
}
catch (Exception e)
{
Debug.Log(e);
throw;
}
}