Skip to content

Unity Link Client

PhantasmaLinkClient is the Unity wallet-link component used by the wallet-facing examples.

Component State

PhantasmaLinkClient is a MonoBehaviour singleton. On Awake, it assigns Instance unless another instance already exists. On Start, it calls Enable().

Field or propertyUse
VersionLink protocol version. The inspector default is 2.
DappIDdApp or contract identifier included in wallet authorization requests.
HostWallet endpoint host. The inspector default is localhost:7090.
PlatformSigning platform. Default is PlatformKind.Phantasma.
SignatureSignature kind. Default is SignatureKind.Ed25519.
GasPrice, GasLimitInspector-configured gas values used by example flows around the component.
ReadyTrue after the WebSocket connection opens.
EnabledTrue after Enable() initializes the component.
BusyPublic state flag reserved by the component.
NexusConfigured nexus value copied from the serialized _nexus field on enable.
Wallet, Token, Name, Address, IsLoggedSession values populated by wallet authorization and account fetch.
AvatarTexture slot cleared on logout.
AssetsSymbol keys currently present in the balance cache.

Events

EventPayloadUse
OnLoginUnityEvent<bool, string>Receives login success state and message.
OnInfoUnityEvent<string>Receives status messages emitted by the component.

Connection Lifecycle

MethodBehavior
Enable()Creates a WebSocket at ws://{Host}/phantasma, assigns event handlers, sets default session state, and connects. Returns immediately because it is async void.
Update()Dispatches queued WebSocket messages outside WebGL player builds and outside editor-disabled paths.
OnApplicationQuit()Closes the WebSocket if it exists.
Logout()Clears nexus, wallet, token, avatar, name, address, login state, and balance cache.

Wallet messages are matched to callbacks by numeric request id. Unknown ids are logged as warnings.

Login And Account Cache

MethodBehavior
Login(Action<bool, string> callback = null)Sends authorize/{DappID}/{Version}. On success it verifies that the returned nexus equals Nexus, stores wallet token fields, and fetches account data.
ReloadAccount(Action<bool, string> callback = null)Calls the same account-fetch path used after login.
GetBalance(string symbol)Returns the cached balance as a decimal using the cached token decimals. Returns 0 when the symbol is missing.
GetNFTs(string symbol)Returns cached NFT ids for a symbol. Returns an empty array when the symbol is missing.

The account fetch uses getAccount/{Platform} through Phantasma Link. It populates _balanceMap for all returned balances and _ownershipMap for entries that include NFT ids.

Transaction Signing

public void SendTransaction(
    string chain,
    byte[] script,
    byte[] payload,
    Action<Hash, string> callback = null,
    PlatformKind platform = PlatformKind.Phantasma,
    SignatureKind signature = SignatureKind.Ed25519)

SendTransaction rejects scripts with length >= 8192 before sending the wallet request. For Link version 2 and newer, the request contains chain, hex-encoded script, hex-encoded payload, signature kind, and platform. For older versions, the request includes Nexus before the chain/script/payload segment.

On wallet success, the callback receives the parsed Hash and null error text. On wallet rejection, the callback receives Hash.Null and a rejection message.

Data Signing

public void SignData(
    string data,
    Action<bool, string, string, string> callback = null,
    PlatformKind platform = PlatformKind.Phantasma,
    SignatureKind signature = SignatureKind.Ed25519)

SignData requires the component to be enabled, rejects null data, and rejects data strings with length >= 1024. It UTF-8 encodes the input, converts it to hex, and sends signData/{hex}/{signature}/{platform}.

On success, the callback receives:

PositionValue
booltrue
stringWallet signature
stringWallet random value
stringHex-encoded data

On failure, the callback receives false, a failure message, and empty strings for the random and encoded data fields.

Platform Enum

PlatformKind values. Current wallets use Phantasma; the other values are not used:

NameValue
None0x0
Phantasma0x1
Neo0x2
Ethereum0x4
BSC0x8