Created
February 21, 2022 17:51
-
-
Save johnsoncarl/e7e2e0d7bee52840c8cd3b26d8361e83 to your computer and use it in GitHub Desktop.
Minting Gaming assets on Polygon using Onecdot APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PostRequest.cs | |
using System.Collections; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEngine.Networking; | |
using System.Collections.Generic; | |
[System.Serializable] | |
public class Metadata | |
{ | |
public string imageURL; | |
public string twitterHandle; | |
} | |
[System.Serializable] | |
public class MetadataList | |
{ | |
public string public_address; | |
public Metadata metadata; | |
} | |
[System.Serializable] | |
public class Root | |
{ | |
public List<MetadataList> metadata_list; | |
public string SaveToString() | |
{ | |
return JsonUtility.ToJson(this); | |
} | |
} | |
public class PostRequest : MonoBehaviour | |
{ | |
InputField outputArea; | |
void Start() | |
{ | |
outputArea = GameObject.Find("OutputArea").GetComponent<InputField>(); | |
GameObject.Find("PostButton").GetComponent<Button>().onClick.AddListener(PostData); | |
} | |
void PostData() => StartCoroutine(PostDataCoroutine()); | |
IEnumerator PostDataCoroutine() | |
{ | |
outputArea.text = "Loading..."; | |
string url = "https://api.onec.in/api/v1/naas/mintNFT/"; | |
var webRequestVar = new UnityWebRequest(url, "POST"); | |
List<MetadataList> metadata_list = new List<MetadataList>(); | |
metadata_list.Add(new MetadataList | |
{ | |
public_address = "0x0000000000000000000000000000000000", | |
metadata = new Metadata | |
{ | |
twitterHandle = "https://twitter.com/amnpandey", | |
imageURL = "https://pbs.twimg.com/profile_images/1433036427223199748/QiPV4LYC_400x400.jpg" | |
} | |
}); | |
Root payload = new Root { | |
metadata_list = metadata_list | |
}; | |
string json = JsonUtility.ToJson(payload); | |
byte[] rawJSON = new System.Text.UTF8Encoding().GetBytes(json); | |
webRequestVar.uploadHandler = (UploadHandler) new UploadHandlerRaw(rawJSON); | |
webRequestVar.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); | |
//Set headers for the request | |
webRequestVar.SetRequestHeader("Content-Type", "application/json"); | |
webRequestVar.SetRequestHeader("NAAS-APIKEY", "PASTE_YOUR_APIKEY_FROM_DASHBOARD"); | |
//Makes request | |
yield return webRequestVar.SendWebRequest(); | |
if (webRequestVar.isNetworkError || webRequestVar.isHttpError) | |
outputArea.text = webRequestVar.error + webRequestVar.downloadHandler.text; | |
else | |
outputArea.text = webRequestVar.downloadHandler.text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment