init
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5342b2f73654466409804d88ee43581d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class CreateApprovalWebGL : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public string chain = "ethereum";
|
||||
public string network = "goerli";
|
||||
public string account;
|
||||
public string tokenType = "1155";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
}
|
||||
|
||||
public async void ApproveTransaction()
|
||||
{
|
||||
var response = await EVM.CreateApproveTransaction(chain, network, account, tokenType);
|
||||
Debug.Log("Response: " + response.connection.chain);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
string responseNft = await Web3GL.SendTransactionData(response.tx.to, "0", response.tx.gasPrice, response.tx.gasLimit, response.tx.data);
|
||||
if (responseNft == null)
|
||||
{
|
||||
Debug.Log("Empty Response Object:");
|
||||
}
|
||||
print(responseNft);
|
||||
Debug.Log(responseNft);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bee6d2ef00e0fc445ac34964f0acbf24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class CreateApprovalWebWallet : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public string chain = "ethereum";
|
||||
public string network = "goerli";
|
||||
public string account;
|
||||
public string tokenType = "1155";
|
||||
string chainID = "5";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
}
|
||||
|
||||
public async void ApproveTransaction()
|
||||
{
|
||||
var response = await EVM.CreateApproveTransaction(chain, network, account, tokenType);
|
||||
Debug.Log("Response: " + response.connection.chain);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
string responseNft = await Web3Wallet.SendTransaction(chainID, response.tx.to, "0",
|
||||
response.tx.data, response.tx.gasLimit, response.tx.gasPrice);
|
||||
if (responseNft == null)
|
||||
{
|
||||
Debug.Log("Empty Response Object:");
|
||||
}
|
||||
print(responseNft);
|
||||
Debug.Log(responseNft);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668cc0cec6fbbdb43b4a45004c327180
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
138
Assets/Web3Unity/Scripts/Prefabs/Minter/GetListedNFTWebGL.cs
Normal file
138
Assets/Web3Unity/Scripts/Prefabs/Minter/GetListedNFTWebGL.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Models;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
namespace Web3Unity.Scripts.Prefabs.Minter
|
||||
{
|
||||
public class GetListedNFTWebGL : MonoBehaviour
|
||||
{
|
||||
private string chain = "ethereum";
|
||||
public Renderer textureObject;
|
||||
private string network = "goerli";
|
||||
public Text price;
|
||||
public Text seller;
|
||||
public Text description;
|
||||
public Text listPercentage;
|
||||
public Text contractAddr;
|
||||
public Text tokenId;
|
||||
public Text itemId;
|
||||
private string _itemPrice = "";
|
||||
private string _tokenType = "";
|
||||
|
||||
private string _itemID = "";
|
||||
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
|
||||
price.text = "";
|
||||
seller.text = "";
|
||||
description.text = "";
|
||||
listPercentage.text = "";
|
||||
tokenId.text = "";
|
||||
itemId.text = "";
|
||||
contractAddr.text = "";
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
async void Start()
|
||||
{
|
||||
List<GetNftListModel.Response> response = await EVM.GetNftMarket(chain, network);
|
||||
price.text = response[0].price;
|
||||
seller.text = response[0].seller;
|
||||
if (response[0].uri.StartsWith("ipfs://"))
|
||||
{
|
||||
response[0].uri = response[0].uri.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
Debug.Log("Response URI" + response[0].uri);
|
||||
}
|
||||
|
||||
UnityWebRequest webRequest = UnityWebRequest.Get(response[0].uri);
|
||||
await webRequest.SendWebRequest();
|
||||
RootGetNFT data =
|
||||
JsonConvert.DeserializeObject<RootGetNFT>(
|
||||
System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data));
|
||||
description.text = data.description;
|
||||
// parse json to get image uri
|
||||
string imageUri = data.image;
|
||||
if (imageUri.StartsWith("ipfs://"))
|
||||
{
|
||||
imageUri = imageUri.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
|
||||
if (data.properties != null)
|
||||
{
|
||||
foreach (var prop in data.properties.additionalFiles)
|
||||
{
|
||||
if (prop.StartsWith("ipfs://"))
|
||||
{
|
||||
var additionalURi = prop.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
}
|
||||
}
|
||||
}
|
||||
listPercentage.text = response[0].listedPercentage;
|
||||
contractAddr.text = response[0].nftContract;
|
||||
itemId.text = response[0].itemId;
|
||||
_itemID = response[0].itemId;
|
||||
_itemPrice = response[0].price;
|
||||
_tokenType = response[0].tokenType;
|
||||
tokenId.text = response[0].tokenId;
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
IEnumerator DownloadImage(string MediaUrl)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.ProtocolError)
|
||||
Debug.Log(request.error);
|
||||
else
|
||||
{
|
||||
Texture2D webTexture = ((DownloadHandlerTexture)request.downloadHandler).texture as Texture2D;
|
||||
Sprite webSprite = SpriteFromTexture2D(webTexture);
|
||||
textureObject.GetComponent<Image>().sprite = webSprite;
|
||||
}
|
||||
}
|
||||
|
||||
Sprite SpriteFromTexture2D(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f),
|
||||
100.0f);
|
||||
}
|
||||
|
||||
public async void PurchaseItem()
|
||||
{
|
||||
BuyNFT.Response response = await EVM.CreatePurchaseNftTransaction(chain, network,
|
||||
PlayerPrefs.GetString("Account"), _itemID, _itemPrice, _tokenType);
|
||||
Debug.Log("Account: " + response.tx.account);
|
||||
Debug.Log("To : " + response.tx.to);
|
||||
Debug.Log("Value : " + response.tx.value);
|
||||
Debug.Log("Data : " + response.tx.data);
|
||||
Debug.Log("Gas Price : " + response.tx.gasPrice);
|
||||
Debug.Log("Gas Limit : " + response.tx.gasLimit);
|
||||
|
||||
try
|
||||
{
|
||||
string responseNft = await Web3GL.SendTransaction(response.tx.to, response.tx.value, response.tx.gasLimit, response.tx.gasLimit);
|
||||
if (responseNft == null)
|
||||
{
|
||||
Debug.Log("Empty Response Object:");
|
||||
}
|
||||
print(responseNft);
|
||||
Debug.Log(responseNft);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb4a53530137f5e4e99a1673c9be43a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
154
Assets/Web3Unity/Scripts/Prefabs/Minter/GetListedNFTWebWallet.cs
Normal file
154
Assets/Web3Unity/Scripts/Prefabs/Minter/GetListedNFTWebWallet.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Models;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class GetListedNFTWebWallet : MonoBehaviour
|
||||
{
|
||||
private string chain = "ethereum";
|
||||
public Renderer textureObject;
|
||||
private string network = "goerli";
|
||||
private string chainID = "5";
|
||||
public Text price;
|
||||
public Text seller;
|
||||
public Text description;
|
||||
public Text listPercentage;
|
||||
public Text contractAddr;
|
||||
public Text tokenId;
|
||||
public Text itemId;
|
||||
private string _itemPrice = "";
|
||||
private string _tokenType = "";
|
||||
|
||||
private string _itemID = "";
|
||||
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
|
||||
price.text = "";
|
||||
seller.text = "";
|
||||
description.text = "";
|
||||
listPercentage.text = "";
|
||||
tokenId.text = "";
|
||||
itemId.text = "";
|
||||
contractAddr.text = "";
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
async void Start()
|
||||
{
|
||||
List<GetNftListModel.Response> response = await EVM.GetNftMarket(chain, network);
|
||||
price.text = response[0].price;
|
||||
seller.text = response[0].seller;
|
||||
Debug.Log("Seller: " + response[0].seller);
|
||||
if (response[0].uri.StartsWith("ipfs://"))
|
||||
{
|
||||
response[0].uri = response[0].uri.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
Debug.Log("Response URI" + response[0].uri);
|
||||
}
|
||||
|
||||
UnityWebRequest webRequest = UnityWebRequest.Get(response[0].uri);
|
||||
await webRequest.SendWebRequest();
|
||||
RootGetNFT data =
|
||||
JsonConvert.DeserializeObject<RootGetNFT>(
|
||||
System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data));
|
||||
if (data.description == null)
|
||||
{
|
||||
description.text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
description.text = data.description;
|
||||
}
|
||||
|
||||
// parse json to get image uri
|
||||
string imageUri = data.image;
|
||||
if (imageUri.StartsWith("ipfs://"))
|
||||
{
|
||||
imageUri = imageUri.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
|
||||
if (data.properties != null)
|
||||
{
|
||||
foreach (var prop in data.properties.additionalFiles)
|
||||
{
|
||||
if (prop.StartsWith("ipfs://"))
|
||||
{
|
||||
var additionalURi = prop.Replace("ipfs://", "https://ipfs.io/ipfs/");
|
||||
}
|
||||
}
|
||||
}
|
||||
listPercentage.text = response[0].listedPercentage;
|
||||
Debug.Log(response[0].listedPercentage);
|
||||
contractAddr.text = response[0].nftContract;
|
||||
itemId.text = response[0].itemId;
|
||||
_itemID = response[0].itemId;
|
||||
_itemPrice = response[0].price;
|
||||
_tokenType = response[0].tokenType;
|
||||
tokenId.text = response[0].tokenId;
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
IEnumerator DownloadImage(string MediaUrl)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.ProtocolError)
|
||||
Debug.Log(request.error);
|
||||
else
|
||||
{
|
||||
Texture2D webTexture = ((DownloadHandlerTexture)request.downloadHandler).texture as Texture2D;
|
||||
Sprite webSprite = SpriteFromTexture2D(webTexture);
|
||||
textureObject.GetComponent<Image>().sprite = webSprite;
|
||||
}
|
||||
}
|
||||
|
||||
Sprite SpriteFromTexture2D(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f),
|
||||
100.0f);
|
||||
}
|
||||
|
||||
public async void PurchaseItem()
|
||||
{
|
||||
BuyNFT.Response response = await EVM.CreatePurchaseNftTransaction(chain, network,
|
||||
PlayerPrefs.GetString("Account"), _itemID, _itemPrice, _tokenType);
|
||||
Debug.Log("Account: " + response.tx.account);
|
||||
Debug.Log("To : " + response.tx.to);
|
||||
Debug.Log("Value : " + response.tx.value);
|
||||
Debug.Log("Data : " + response.tx.data);
|
||||
Debug.Log("Gas Price : " + response.tx.gasPrice);
|
||||
Debug.Log("Gas Limit : " + response.tx.gasLimit);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
string responseNft = await Web3Wallet.SendTransaction(chainID, response.tx.to, response.tx.value,
|
||||
response.tx.data, response.tx.gasLimit, response.tx.gasPrice);
|
||||
if (responseNft == null)
|
||||
{
|
||||
Debug.Log("Empty Response Object:");
|
||||
}
|
||||
print(responseNft);
|
||||
Debug.Log(responseNft);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2b606c43a8ad934f90b41d8f3adefa9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNFTWebGL.cs
Normal file
113
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNFTWebGL.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Models;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class ListNFTWebGL : MonoBehaviour
|
||||
{
|
||||
private string chain = "ethereum";
|
||||
private string network = "goerli";
|
||||
private string _itemPrice = "0.001";
|
||||
private string _tokenType = "";
|
||||
private string _itemID = "";
|
||||
private string account;
|
||||
|
||||
public Renderer textureObject;
|
||||
public Text description;
|
||||
public Text tokenURI;
|
||||
public Text contractAddr;
|
||||
public Text isApproved;
|
||||
public InputField itemPrice;
|
||||
public Text playerAccount;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
description.text = "";
|
||||
tokenURI.text = "";
|
||||
isApproved.text = "";
|
||||
contractAddr.text = "";
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private async void Start()
|
||||
{
|
||||
playerAccount.text = account;
|
||||
var response = await EVM.GetMintedNFT(chain, network, account);
|
||||
|
||||
if (response[1].uri.StartsWith("ipfs://"))
|
||||
response[1].uri = response[1].uri.Replace("ipfs://", "https://ipfs.chainsafe.io/ipfs/");
|
||||
|
||||
var webRequest = UnityWebRequest.Get(response[1].uri);
|
||||
await webRequest.SendWebRequest();
|
||||
var data =
|
||||
JsonConvert.DeserializeObject<RootGetNFT>(
|
||||
System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data));
|
||||
description.text = data.description;
|
||||
// parse json to get image uri
|
||||
var imageUri = data.image;
|
||||
if (imageUri.StartsWith("ipfs://"))
|
||||
{
|
||||
imageUri = imageUri.Replace("ipfs://", "https://ipfs.chainsafe.io/ipfs/");
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
|
||||
tokenURI.text = response[1].uri;
|
||||
Debug.Log(response[1].uri);
|
||||
contractAddr.text = response[1].nftContract;
|
||||
isApproved.text = response[1].isApproved.ToString();
|
||||
_itemID = response[1].id;
|
||||
_itemPrice = itemPrice.text;
|
||||
_tokenType = response[1].tokenType;
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
private IEnumerator DownloadImage(string MediaUrl)
|
||||
{
|
||||
var request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.Log(request.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var webTexture = ((DownloadHandlerTexture) request.downloadHandler).texture as Texture2D;
|
||||
var webSprite = SpriteFromTexture2D(webTexture);
|
||||
textureObject.GetComponent<Image>().sprite = webSprite;
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite SpriteFromTexture2D(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f),
|
||||
100.0f);
|
||||
}
|
||||
|
||||
public async void ListItem()
|
||||
{
|
||||
var eth = float.Parse(_itemPrice);
|
||||
float decimals = 1000000000000000000; // 18 decimals
|
||||
var wei = eth * decimals;
|
||||
var response =
|
||||
await EVM.CreateListNftTransaction(chain, network, account, _itemID, Convert.ToDecimal(wei).ToString(),
|
||||
_tokenType);
|
||||
var value = Convert.ToInt32(response.tx.value.hex, 16);
|
||||
try
|
||||
{
|
||||
var responseNft = await Web3GL.SendTransactionData(response.tx.to, value.ToString(),
|
||||
response.tx.gasPrice, response.tx.gasLimit, response.tx.data);
|
||||
if (responseNft == null) Debug.Log("Empty Response Object:");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log("Revoked Transaction" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNFTWebGL.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNFTWebGL.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd208d310cc4d2044924598d230f8f86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
140
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNftWebWallet.cs
Normal file
140
Assets/Web3Unity/Scripts/Prefabs/Minter/ListNftWebWallet.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Models;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
namespace Web3Unity.Scripts.Prefabs.Minter
|
||||
{
|
||||
public class ListNftWebWallet : MonoBehaviour
|
||||
{
|
||||
private readonly string chain = "ethereum";
|
||||
private readonly string network = "goerli";
|
||||
private readonly string chainID = "5";
|
||||
private string _itemPrice = "0.001";
|
||||
private string _tokenType = "";
|
||||
private string _itemID = "";
|
||||
private string account;
|
||||
|
||||
public Renderer textureObject;
|
||||
public Text description;
|
||||
public Text tokenURI;
|
||||
public Text contractAddr;
|
||||
public Text isApproved;
|
||||
public InputField itemPrice;
|
||||
public Text noListedItems;
|
||||
public Text playerAccount;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
description.text = "";
|
||||
tokenURI.text = "";
|
||||
isApproved.text = "";
|
||||
contractAddr.text = "";
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private async void Start()
|
||||
{
|
||||
playerAccount.text = account;
|
||||
try
|
||||
{
|
||||
var response = await EVM.GetMintedNFT(chain, network, account);
|
||||
|
||||
if (response[1].uri == null)
|
||||
{
|
||||
Debug.Log("Not Listed Items");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response[1].uri.StartsWith("ipfs://"))
|
||||
{
|
||||
response[1].uri = response[1].uri.Replace("ipfs://", "https://ipfs.chainsafe.io/ipfs/");
|
||||
}
|
||||
|
||||
var webRequest = UnityWebRequest.Get(response[1].uri);
|
||||
await webRequest.SendWebRequest();
|
||||
var data = JsonConvert.DeserializeObject<RootGetNFT>(Encoding.UTF8.GetString(webRequest.downloadHandler.data));
|
||||
description.text = data.description;
|
||||
// parse json to get image uri
|
||||
var imageUri = data.image;
|
||||
if (imageUri.StartsWith("ipfs://"))
|
||||
{
|
||||
imageUri = imageUri.Replace("ipfs://", "https://ipfs.chainsafe.io/ipfs/");
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(DownloadImage(imageUri));
|
||||
}
|
||||
|
||||
tokenURI.text = response[1].uri;
|
||||
Debug.Log(response[1].uri);
|
||||
contractAddr.text = response[1].nftContract;
|
||||
Debug.Log("NFT Contract: " + response[1].nftContract);
|
||||
isApproved.text = response[1].isApproved.ToString();
|
||||
_itemID = response[1].id;
|
||||
_itemPrice = itemPrice.text;
|
||||
Debug.Log("Token Type: " + response[1].tokenType);
|
||||
_tokenType = response[1].tokenType;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
noListedItems.text = "NO LISTED ITEM for " + account;
|
||||
Debug.Log("No Listed Items" + e);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
private IEnumerator DownloadImage(string mediaUrl)
|
||||
{
|
||||
var request = UnityWebRequestTexture.GetTexture(mediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.Log(request.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var webTexture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
var webSprite = SpriteFromTexture2D(webTexture);
|
||||
textureObject.GetComponent<Image>().sprite = webSprite;
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite SpriteFromTexture2D(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
|
||||
}
|
||||
|
||||
public async void ListItem()
|
||||
{
|
||||
var eth = float.Parse(_itemPrice);
|
||||
float decimals = 1000000000000000000; // 18 decimals
|
||||
var wei = eth * decimals;
|
||||
Debug.Log("ItemID: " + _itemID);
|
||||
var response =
|
||||
await EVM.CreateListNftTransaction(chain, network, account, _itemID, Convert.ToDecimal(wei).ToString(CultureInfo.InvariantCulture),
|
||||
_tokenType);
|
||||
var value = Convert.ToInt32(response.tx.value.hex, 16);
|
||||
Debug.Log("Response: " + response);
|
||||
try
|
||||
{
|
||||
var responseNft = await Web3Wallet.SendTransaction(chainID, response.tx.to, value.ToString(),
|
||||
response.tx.data, response.tx.gasLimit, response.tx.gasPrice);
|
||||
if (responseNft == null) Debug.Log("Empty Response Object:");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log("Error: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c24d9e426ddb1c543acdff61a6589df2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using Models;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using System;
|
||||
|
||||
public class MintWeb3Wallet1155 : MonoBehaviour
|
||||
{
|
||||
// set chain: ethereum, moonbeam, polygon etc
|
||||
public string chain = "ethereum";
|
||||
// chain id
|
||||
public string chainId = "5";
|
||||
// set network mainnet, testnet
|
||||
public string network = "goerli";
|
||||
// address of nft you want to mint
|
||||
public string nftAddress = "0x2c1867bc3026178a47a677513746dcc6822a137a";
|
||||
// type
|
||||
string type = "1155";
|
||||
|
||||
public async void VoucherMintNft1155()
|
||||
{
|
||||
var voucherResponse1155 = await EVM.Get1155Voucher();
|
||||
CreateRedeemVoucherModel.CreateVoucher1155 voucher1155 = new CreateRedeemVoucherModel.CreateVoucher1155();
|
||||
voucher1155.tokenId = voucherResponse1155.tokenId;
|
||||
voucher1155.minPrice = voucherResponse1155.minPrice;
|
||||
voucher1155.signer = voucherResponse1155.signer;
|
||||
voucher1155.receiver = voucherResponse1155.receiver;
|
||||
voucher1155.amount = voucherResponse1155.amount;
|
||||
voucher1155.nonce = voucherResponse1155.nonce;
|
||||
voucher1155.signature = voucherResponse1155.signature;
|
||||
string voucherArgs = JsonUtility.ToJson(voucher1155);
|
||||
|
||||
// connects to user's browser wallet to call a transaction
|
||||
RedeemVoucherTxModel.Response voucherResponse = await EVM.CreateRedeemTransaction(chain, network, voucherArgs, type, nftAddress, voucherResponse1155.receiver);
|
||||
string response = await Web3Wallet.SendTransaction(chainId, voucherResponse.tx.to, voucherResponse.tx.value.ToString(), voucherResponse.tx.data, voucherResponse.tx.gasLimit, voucherResponse.tx.gasPrice);
|
||||
print("Response: " + response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f530a2f3db5f5c7478b08921d42c5114
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet721.cs
Normal file
35
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet721.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Models;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
public class MintWeb3Wallet721 : MonoBehaviour
|
||||
{
|
||||
// set chain: ethereum, moonbeam, polygon etc
|
||||
public string chain = "ethereum";
|
||||
// chain id
|
||||
public string chainId = "5";
|
||||
// set network mainnet, testnet
|
||||
public string network = "goerli";
|
||||
// address of nft you want to mint
|
||||
public string nftAddress = "f01559ae4021a47e26bc773587278f62a833f2a6117411afbc5a7855661936d1c";
|
||||
// type
|
||||
string type = "721";
|
||||
|
||||
public async void VoucherMintNft721()
|
||||
{
|
||||
var voucherResponse721 = await EVM.Get721Voucher();
|
||||
CreateRedeemVoucherModel.CreateVoucher721 voucher721 = new CreateRedeemVoucherModel.CreateVoucher721();
|
||||
voucher721.tokenId = voucherResponse721.tokenId;
|
||||
voucher721.minPrice = voucherResponse721.minPrice;
|
||||
voucher721.signer = voucherResponse721.signer;
|
||||
voucher721.receiver = voucherResponse721.receiver;
|
||||
voucher721.signature = voucherResponse721.signature;
|
||||
string voucherArgs = JsonUtility.ToJson(voucher721);
|
||||
|
||||
// connects to user's browser wallet to call a transaction
|
||||
RedeemVoucherTxModel.Response voucherResponse = await EVM.CreateRedeemTransaction(chain, network, voucherArgs, type, nftAddress, voucherResponse721.receiver);
|
||||
string response = await Web3Wallet.SendTransaction(chainId, voucherResponse.tx.to, voucherResponse.tx.value.ToString(), voucherResponse.tx.data, voucherResponse.tx.gasLimit, voucherResponse.tx.gasPrice);
|
||||
print("Response: " + response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 785a5af054a848e4a93802898e155c97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL1155.cs
Normal file
44
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL1155.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Models;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class MintWebGL1155 : MonoBehaviour
|
||||
{
|
||||
// set chain: ethereum, moonbeam, polygon etc
|
||||
public string chain = "ethereum";
|
||||
// set network mainnet, testnet
|
||||
public string network = "goerli";
|
||||
// address of nft you want to mint
|
||||
public string nftAddress = "0x2c1867bc3026178a47a677513746dcc6822a137a";
|
||||
// type
|
||||
string type = "1155";
|
||||
|
||||
public async void VoucherMintNft1155()
|
||||
{
|
||||
try
|
||||
{
|
||||
var voucherResponse1155 = await EVM.Get1155Voucher();
|
||||
CreateRedeemVoucherModel.CreateVoucher1155 voucher1155 = new CreateRedeemVoucherModel.CreateVoucher1155();
|
||||
voucher1155.tokenId = voucherResponse1155.tokenId;
|
||||
voucher1155.minPrice = voucherResponse1155.minPrice;
|
||||
voucher1155.signer = voucherResponse1155.signer;
|
||||
voucher1155.receiver = voucherResponse1155.receiver;
|
||||
voucher1155.amount = voucherResponse1155.amount;
|
||||
voucher1155.nonce = voucherResponse1155.nonce;
|
||||
voucher1155.signature = voucherResponse1155.signature;
|
||||
string voucherArgs = JsonUtility.ToJson(voucher1155);
|
||||
|
||||
// connects to user's browser wallet to call a transaction
|
||||
RedeemVoucherTxModel.Response voucherResponse = await EVM.CreateRedeemTransaction(chain, network, voucherArgs, type, nftAddress, voucherResponse1155.receiver);
|
||||
string response = await Web3GL.SendTransactionData(voucherResponse.tx.to, voucherResponse.tx.value.ToString(), voucherResponse.tx.gasPrice, voucherResponse.tx.gasLimit, voucherResponse.tx.data);
|
||||
print("Response: " + response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25980a61c707bb34aaae782b8182fea7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL721.cs
Normal file
42
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL721.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Models;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class MintWebGL721 : MonoBehaviour
|
||||
{
|
||||
// set chain: ethereum, moonbeam, polygon etc
|
||||
public string chain = "ethereum";
|
||||
// set network mainnet, testnet
|
||||
public string network = "goerli";
|
||||
// address of nft you want to mint
|
||||
public string nftAddress = "f01559ae4021a47e26bc773587278f62a833f2a6117411afbc5a7855661936d1c";
|
||||
// type
|
||||
string type = "721";
|
||||
|
||||
public async void VoucherMintNft721()
|
||||
{
|
||||
try
|
||||
{
|
||||
var voucherResponse721 = await EVM.Get721Voucher();
|
||||
CreateRedeemVoucherModel.CreateVoucher721 voucher721 = new CreateRedeemVoucherModel.CreateVoucher721();
|
||||
voucher721.tokenId = voucherResponse721.tokenId;
|
||||
voucher721.minPrice = voucherResponse721.minPrice;
|
||||
voucher721.signer = voucherResponse721.signer;
|
||||
voucher721.receiver = voucherResponse721.receiver;
|
||||
voucher721.signature = voucherResponse721.signature;
|
||||
string voucherArgs = JsonUtility.ToJson(voucher721);
|
||||
|
||||
// connects to user's browser wallet to call a transaction
|
||||
RedeemVoucherTxModel.Response voucherResponse = await EVM.CreateRedeemTransaction(chain, network, voucherArgs, type, nftAddress, voucherResponse721.receiver);
|
||||
string response = await Web3GL.SendTransactionData(voucherResponse.tx.to, voucherResponse.tx.value.ToString(), voucherResponse.tx.gasPrice, voucherResponse.tx.gasLimit, voucherResponse.tx.data);
|
||||
print("Response: " + response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL721.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/Minter/MintWebGL721.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87fb94cf6fbd5254380c5b1504ca0727
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user