I created a sync to watch for an ERC20 token approval event and this works perfectly fine in that I can see the entries in DB for each approval.
Now, in Unity I’m trying to add listener that would inform an app that even has been created/updated but nothing gets over to Unity.
The sync name (and DB table) in Moralis is “TUSDCoinApprovalCronos”
here is how I do it Unity:
public class TUSDCoinApprovalCronos: MoralisObject
{
public string spender { get; set; }
public bool confirmed { get; set; }
public TUSDCoinApprovalCronos() : base("TUSDCoinApprovalCronos")
{
}
}
then subcribtion is done like that:
private async void SubscribeToDatabaseEvents()
{
Debug.Log("SubscribeToDatabaseEvents called");
var callbacks = new MoralisLiveQueryCallbacks<TUSDCoinApprovalCronos>();
callbacks.OnConnectedEvent += (() => { Debug.Log("Connection Established."); });
callbacks.OnSubscribedEvent += ((requestId) => { Debug.Log($"Subscription {requestId} created."); });
callbacks.OnUnsubscribedEvent += ((requestId) => { Debug.Log($"Unsubscribed from {requestId}."); });
callbacks.OnErrorEvent += ((ErrorMessage em) =>
{
Debug.Log($"ERROR: code: {em.code}, msg: {em.error}, requestId: {em.requestId}");
});
callbacks.OnCreateEvent += ((item, requestId) =>
{
Debug.Log($"Created ");
});
callbacks.OnUpdateEvent += ((item, requestId) =>
{
Debug.Log($"Updated ");
});
callbacks.OnDeleteEvent += ((item, requestId) =>
{
Debug.Log($"Hero deleted");
});
callbacks.OnGeneralMessageEvent += ((text) =>
{
Debug.Log($"Websocket message: {text}");
});
var q = await Moralis.GetClient().Query<TUSDCoinApprovalCronos>();
MoralisLiveQueryController.AddSubscription<TUSDCoinApprovalCronos>("TUSDCoinApprovalCronos", q, callbacks);
}
given that I see the following in the logs:
SubscribeToDatabaseEvents called
Websocket message: Sending connection request.
Websocket message: Listening, status: New
Websocket message: Result received.
Websocket message: Received message $connected
Connection Established.
Websocket message: Processed connected.
Websocket message: Sending subscription request.
Websocket message: Listening, status: Opening
Websocket message: Received message $subscribed
Subscription 1 created.
Websocket message: Processed subscribed.
Websocket message: Listening, status: Open
I know the subscription itself is OK.
So the questions are:
- is my fundamental assumption that Moralis ERC20 Approval Sync triggers an event correct? (I use events from custom tables already in the project)
- if so what is the correct event name triggered? I tried both
TUSDCoinApprovalCronos
(as per DB name) andTUSDCoinApprovalCronosEvent
as I’ve seen somewhere on tutorial thatEvent
as post-fixed to the table name. - if one of the above names is correct then what else do I do wrong…
Any help greatly appreciated as I spent hours trying to get that to work.