using System; using MoralisUnity.Web3Api.Client; namespace MoralisUnity.Web3Api { /// /// Provides an easy to wrapper around the Moralis Web3Api REST services. /// public class MoralisClient { Web3ApiClient client = new Web3ApiClient(); static MoralisClient instance = new MoralisClient(); private MoralisClient() { } /// /// Initialize Moralis Web3API. Use this to initialize to your personal /// Moralis server. Major advantage is api key is supplied /// /// public static void Initialize(string url) => instance.client.Initialize(url); /// /// Initialize Moralis Web3API. /// /// If true enforces use of the standard REST server /// Required if useStandardServer is true /// Optional server url. If not provided default standard server Url is used. public static void Initialize(bool useStandardServer, string apiKey = null, string url = null) { if (useStandardServer && !(apiKey is { })) throw new ArgumentException("API Key is required for Standard REST server."); if (apiKey is { }) Configuration.ApiKey["X-API-Key"] = apiKey; instance.client.Initialize(url); } /// /// Gets the Web3ApiClient instance. Moralis.Initialize must be called first. /// If Moralis is not initialized this will throw an ApiException. /// /// Thrown when Moralis.Initialize has not been called. public static Web3ApiClient Web3Api { get => instance.client.IsInitialized ? instance.client : throw new ApiException(109, "Moralis must be initialized before use."); } } }