Skip to content

Example scripts missing namespaces added #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
650 changes: 326 additions & 324 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWallet.cs

Large diffs are not rendered by default.

184 changes: 93 additions & 91 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Events.cs
Original file line number Diff line number Diff line change
@@ -1,130 +1,132 @@
using System.Collections.Generic;
using UnityEngine;
using Thirdweb;
using Nethereum.ABI.FunctionEncoding.Attributes;
using System.Numerics;
using Newtonsoft.Json;

// Your Event type (WebGL)
[System.Serializable]
public struct TransferEvent
namespace Thirdweb.Examples
{
public string from;
public string to;
public string tokenId;

public override string ToString()
// Your Event type (WebGL)
[System.Serializable]
public struct TransferEvent
{
return $"TransferEvent:" + $"\n>from: {from}" + $"\n>to: {to}" + $"\n>tokenId: {tokenId}";
public string from;
public string to;
public string tokenId;

public override string ToString()
{
return $"TransferEvent:" + $"\n>from: {from}" + $"\n>to: {to}" + $"\n>tokenId: {tokenId}";
}
}
}

// Your Event type (Native platforms)
[Event("Transfer")]
public class TransferEventDTO : IEventDTO
{
[Parameter("address", "from", 1, true)]
public string From { get; set; }
// Your Event type (Native platforms)
[Event("Transfer")]
public class TransferEventDTO : IEventDTO
{
[Parameter("address", "from", 1, true)]
public string From { get; set; }

[Parameter("address", "to", 2, true)]
public string To { get; set; }
[Parameter("address", "to", 2, true)]
public string To { get; set; }

[Parameter("uint256", "tokenId", 3, true)]
public BigInteger TokenId { get; set; }
[Parameter("uint256", "tokenId", 3, true)]
public BigInteger TokenId { get; set; }

public override string ToString()
{
return $"TransferEvent:" + $"\n>from: {From}" + $"\n>to: {To}" + $"\n>tokenId: {TokenId}";
public override string ToString()
{
return $"TransferEvent:" + $"\n>from: {From}" + $"\n>to: {To}" + $"\n>tokenId: {TokenId}";
}
}
}

public class Prefab_Events : MonoBehaviour
{
// Get all events filtered by name (and optionally add more filters)

public async void GetEvents()
public class Prefab_Events : MonoBehaviour
{
try
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
// Get all events filtered by name (and optionally add more filters)

if (Utils.IsWebGLBuild())
public async void GetEvents()
{
try
{
// Optional event query options
Dictionary<string, object> filters = new Dictionary<string, object> { { "tokenId", 20 } };
EventQueryOptions options = new EventQueryOptions(filters);

List<ContractEvent<TransferEvent>> allEvents = await contract.events.Get<TransferEvent>("Transfer", options);
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].ToString());
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");

if (Utils.IsWebGLBuild())
{
// Optional event query options
Dictionary<string, object> filters = new Dictionary<string, object> { { "tokenId", 20 } };
EventQueryOptions options = new EventQueryOptions(filters);

List<ContractEvent<TransferEvent>> allEvents = await contract.events.Get<TransferEvent>("Transfer", options);
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].ToString());
}
else
{
// Optional event query options
ulong? fromBlock = null;
ulong? toBlock = null;

var allEvents = await contract.GetEventLogs<TransferEventDTO>(fromBlock, toBlock);
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].Event.ToString());
}
}
else
catch (System.Exception e)
{
// Optional event query options
ulong? fromBlock = null;
ulong? toBlock = null;

var allEvents = await contract.GetEventLogs<TransferEventDTO>(fromBlock, toBlock);
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].Event.ToString());
Debugger.Instance.Log("[Get Events] Error", e.Message);
}
}
catch (System.Exception e)
{
Debugger.Instance.Log("[Get Events] Error", e.Message);
}
}

// Get all contract events
// Get all contract events

public async void GetAllEvents()
{
try
public async void GetAllEvents()
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
try
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");

// Optional event query options
EventQueryOptions options = new EventQueryOptions(null, 0, 16500000, "desc");
// Optional event query options
EventQueryOptions options = new EventQueryOptions(null, 0, 16500000, "desc");

List<ContractEvent<object>> allContractEvents = await contract.events.GetAll(options);
Debugger.Instance.Log("[Get All Events] Get - ContractEvent #1", allContractEvents[0].ToString());
}
catch (System.Exception e)
{
Debugger.Instance.Log("[Get All Events] Error", e.Message);
List<ContractEvent<object>> allContractEvents = await contract.events.GetAll(options);
Debugger.Instance.Log("[Get All Events] Get - ContractEvent #1", allContractEvents[0].ToString());
}
catch (System.Exception e)
{
Debugger.Instance.Log("[Get All Events] Error", e.Message);
}
}
}

// Event listeners
// Event listeners

public void ListenToAllEvents()
{
try
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
contract.events.ListenToAll((ContractEvent<object> anyEvent) => OnEventTriggered(anyEvent));
Debugger.Instance.Log("Listening to all events!", "Try to trigger an event on the specified contract to get a callback.");
}
catch (System.Exception e)
public void ListenToAllEvents()
{
Debugger.Instance.Log("[Listen To All Events] Error", e.Message);
try
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
contract.events.ListenToAll((ContractEvent<object> anyEvent) => OnEventTriggered(anyEvent));
Debugger.Instance.Log("Listening to all events!", "Try to trigger an event on the specified contract to get a callback.");
}
catch (System.Exception e)
{
Debugger.Instance.Log("[Listen To All Events] Error", e.Message);
}
}
}

public async void RemoveAllEventListeners()
{
try
public async void RemoveAllEventListeners()
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
await contract.events.RemoveAllListeners();
Debugger.Instance.Log("Removed all event listeners!", "Events emitted will not trigger callbacks anymore.");
try
{
Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
await contract.events.RemoveAllListeners();
Debugger.Instance.Log("Removed all event listeners!", "Events emitted will not trigger callbacks anymore.");
}
catch (System.Exception e)
{
Debugger.Instance.Log("[Remove All Event Listeners] Error", e.Message);
}
}
catch (System.Exception e)

public void OnEventTriggered<T>(ContractEvent<T> contractEvent)
{
Debugger.Instance.Log("[Remove All Event Listeners] Error", e.Message);
Debugger.Instance.Log("[EventListener] OnEventTriggered", $"An event was just emitted!\n{contractEvent.ToString()}");
}
}

public void OnEventTriggered<T>(ContractEvent<T> contractEvent)
{
Debugger.Instance.Log("[EventListener] OnEventTriggered", $"An event was just emitted!\n{contractEvent.ToString()}");
}
}
Loading