Login Example
Import NFT
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
public class ImportNFTTextureCronos : MonoBehaviour
{
public class Response {
public string image;
}
async void Start()
{
string chain = "cronos";
string network = "mainnet"; // mainnet or testnet
string account = "WALLET_ADDRESS"; // PlayerPrefs.GetString("Account");
string contract = "CONTRACT_ADDRESS";
string tokenId = "TOKEN_ID";
string ownerOf = await ERC721.OwnerOf(chain, network, contract, tokenId);
if (ownerOf == account)
{
// fetch uri from chain
string uri = await ERC721.URI(chain, network, contract, tokenId);
print("uri: " + uri);
// fetch json from uri
UnityWebRequest webRequest = UnityWebRequest.Get(uri);
await webRequest.SendWebRequest();
Response data = JsonUtility.FromJson<Response>(System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data));
// parse json to get image uri
string imageUri = data.image;
print("imageUri: " + imageUri);
// fetch image and display in game
UnityWebRequest textureRequest = UnityWebRequestTexture.GetTexture(imageUri);
await textureRequest.SendWebRequest();
this.gameObject.GetComponent<Renderer>().material.mainTexture = ((DownloadHandlerTexture)textureRequest.downloadHandler).texture;
}
}
}Build the Scenes


Last updated
Was this helpful?