changes
This commit is contained in:
8
Assets/Web3Unity/Scripts/Helpers.meta
Normal file
8
Assets/Web3Unity/Scripts/Helpers.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96e29a10958eb1a459e0f2df6aa45dca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Web3Unity/Scripts/Helpers/ABI.cs
Normal file
14
Assets/Web3Unity/Scripts/Helpers/ABI.cs
Normal file
File diff suppressed because one or more lines are too long
11
Assets/Web3Unity/Scripts/Helpers/ABI.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Helpers/ABI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 249f219a8a2002b46939c72b58456401
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Web3Unity/Scripts/Helpers/ETH_METHOD.cs
Normal file
14
Assets/Web3Unity/Scripts/Helpers/ETH_METHOD.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
public static class ETH_METHOD
|
||||
{
|
||||
public const string BalanceOf = "balanceOf";
|
||||
public const string Name = "name";
|
||||
public const string Symbol = "symbol";
|
||||
public const string Decimals = "decimals";
|
||||
public const string TotalSupply = "totalSupply";
|
||||
public const string OwnerOf = "ownerOf";
|
||||
public const string TokenUri = "tokenURI";
|
||||
public const string Uri = "uri";
|
||||
public const string BalanceOfBatch = "balanceOfBatch";
|
||||
public const string Transfer = "transfer";
|
||||
public const string SafeTransferFrom = "safeTransferFrom";
|
||||
}
|
||||
11
Assets/Web3Unity/Scripts/Helpers/ETH_METHOD.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Helpers/ETH_METHOD.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb760047f12743142843ed9f14ff2205
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 626e9532c187c4f81823c9dab3d2f907
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/ERC1155.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/ERC1155.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f172d96e750446ceb4ba389097afe0d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Numerics;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC1155BalanceOfBatchExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0xdc4aff511e1b94677142a43df90f948f9ae181dd";
|
||||
string[] accounts = { "0xd25b827D92b0fd656A1c829933e9b0b836d5C3e2", "0xE51995Cdb3b1c109E0e6E67ab5aB31CDdBB83E4a" };
|
||||
string[] tokenIds = { "1", "2" };
|
||||
|
||||
List<BigInteger> batchBalances = await ERC1155.BalanceOfBatch(contract, accounts, tokenIds);
|
||||
foreach (var balance in batchBalances)
|
||||
{
|
||||
print("BalanceOfBatch: " + balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f30fc62ae2197408a96eb300583f594e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC1155BalanceOfExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x2c1867bc3026178a47a677513746dcc6822a137a";
|
||||
string account = "0xd25b827D92b0fd656A1c829933e9b0b836d5C3e2";
|
||||
string tokenId = "0x01559ae4021aee70424836ca173b6a4e647287d15cee8ac42d8c2d8d128927e5";
|
||||
|
||||
BigInteger balanceOf = await ERC1155.BalanceOf(contract, account, tokenId);
|
||||
print(balanceOf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54b5a3b9772a74c428edd0b51e976dba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC1155URIExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x2c1867BC3026178A47a677513746DCc6822A137A";
|
||||
string tokenId = "0x01559ae4021aee70424836ca173b6a4e647287d15cee8ac42d8c2d8d128927e5";
|
||||
string uri = await ERC1155.URI(contract, tokenId);
|
||||
print(uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0de38d3113ee4e6c9e80cfc689eab8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c80051128db3d447b5ac761a1b0d2ae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class AllErc1155 : MonoBehaviour
|
||||
{
|
||||
string account;
|
||||
public string tokenIdHex;
|
||||
public string[] nftContracts;
|
||||
|
||||
async void Start()
|
||||
{
|
||||
// This is the account taken from the user login scene
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
// Searches through your listed contracts for balance and uri of the chosen tokenId
|
||||
foreach (string contract in nftContracts)
|
||||
{
|
||||
BigInteger balance = await ERC1155.BalanceOf(contract, account, tokenIdHex);
|
||||
Debug.Log("Balance of contract " + contract + ": " + balance);
|
||||
string uri = await ERC1155.URI(contract, tokenIdHex);
|
||||
Debug.Log("Token URI: " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cdc6d760edc9764399a0b3206fdd6c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/ERC20.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/ERC20.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e5225008201b49989d9ec10e2a0a971
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC20BalanceOfExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x3E0C0447e47d49195fbE329265E330643eB42e6f";
|
||||
string account = "0xd25b827D92b0fd656A1c829933e9b0b836d5C3e2";
|
||||
|
||||
BigInteger balanceOf = await ERC20.BalanceOf(contract, account);
|
||||
Debug.Log("Balance Of: " + balanceOf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d5005ecc83b74897a816ce083f0c65c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
|
||||
public class ERC20CustomTokenBalance : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
// abi in json format
|
||||
string contractAbi = "YOUR_TOKEN_ABI";
|
||||
// address of contract
|
||||
string contractAddress = "YOUR_TOKEN_ADDRESS";
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
var contract = new Contract(contractAbi, contractAddress, provider);
|
||||
var calldata = await contract.Call("balanceOf", new object[]
|
||||
{
|
||||
PlayerPrefs.GetString("Account")
|
||||
});
|
||||
Debug.Log(calldata[0].ToString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc736206b5c11724bb6b6d294e5eb793
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Numerics;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC20DecimalsExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x3E0C0447e47d49195fbE329265E330643eB42e6f";
|
||||
|
||||
BigInteger decimals = await ERC20.Decimals(contract);
|
||||
print(decimals);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ea463c4c7b684f87bd4ebc6abe57006
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Web3Unity/Scripts/Prefabs/ERC20/ERC20NameExample.cs
Normal file
14
Assets/Web3Unity/Scripts/Prefabs/ERC20/ERC20NameExample.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC20NameExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x3E0C0447e47d49195fbE329265E330643eB42e6f";
|
||||
string name = await ERC20.Name(contract);
|
||||
print(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7387687bed044dba9f9d2bdf6a6b895
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
public class ERC20NativeBalanceOf : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string account = "0xaBed4239E4855E120fDA34aDBEABDd2911626BA1";
|
||||
var provider = RPC.GetInstance.Provider();
|
||||
var getBalance = await provider.GetBalance(account);
|
||||
Debug.Log("Account Balance: " + getBalance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de5e4eb76511f1f4da883328043f95b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Web3Unity/Scripts/Prefabs/ERC20/ERC20SymbolExample.cs
Normal file
13
Assets/Web3Unity/Scripts/Prefabs/ERC20/ERC20SymbolExample.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC20SymbolExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x3E0C0447e47d49195fbE329265E330643eB42e6f";
|
||||
|
||||
string symbol = await ERC20.Symbol(contract);
|
||||
print(symbol);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c79c7f1d80e13484daae5e7ea00d883a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Numerics;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC20TotalSupplyExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x3E0C0447e47d49195fbE329265E330643eB42e6f";
|
||||
BigInteger totalSupply = await ERC20.TotalSupply(contract);
|
||||
print(totalSupply);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38a1274a3f350490e8fc93a926c9d9f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/ERC721.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/ERC721.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c11310df7fc78437093a78706e8be787
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC721BalanceOfExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x9123541E259125657F03D7AD2A7D1a8Ec79375BA";
|
||||
string account = "0xd25b827D92b0fd656A1c829933e9b0b836d5C3e2";
|
||||
|
||||
BigInteger balance = await ERC721.BalanceOf(contract, account);
|
||||
print(balance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75d27837ef25c4d2992393ea70605c11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC721OwnerOfBatchExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x47381c5c948254e6e0E324F1AA54b7B24104D92D";
|
||||
string[] tokenIds = { "33", "29" };
|
||||
string multicall = "0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e"; // optional: multicall contract https://github.com/makerdao/multicall
|
||||
|
||||
List<string> batchOwners = await ERC721.OwnerOfBatch(contract, tokenIds, multicall);
|
||||
foreach (string owner in batchOwners)
|
||||
{
|
||||
print("OwnerOfBatch: " + owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8daf09cb680004087b202594bdd8adf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class ERC721OwnerOfExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x06dc21f89f01409e7ed0e4c80eae1430962ae52c";
|
||||
string tokenId = "0x01559ae4021a565d5cc4740f1cefa95de8c1fb193949ecd32c337b03047da501";
|
||||
string ownerOf = await ERC721.OwnerOf(contract, tokenId);
|
||||
print(ownerOf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3813571b518fd457bbad45d1347dc4cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Web3Unity/Scripts/Prefabs/ERC721/ERC721URIExample.cs
Normal file
15
Assets/Web3Unity/Scripts/Prefabs/ERC721/ERC721URIExample.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
public class ERC721URIExample : MonoBehaviour
|
||||
{
|
||||
async void Start()
|
||||
{
|
||||
string contract = "0x06dc21f89f01409e7ed0e4c80eae1430962ae52c";
|
||||
string tokenId = "0x01559ae4021a565d5cc4740f1cefa95de8c1fb193949ecd32c337b03047da501";
|
||||
|
||||
string uri = await ERC721.URI(contract, tokenId);
|
||||
print(uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 925dc0696e2c24348975c2f9c518476f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 664760b4705f5d747bc1e90125b61304
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
|
||||
public class AllErc721 : MonoBehaviour
|
||||
{
|
||||
public string[] nftContracts;
|
||||
public int amountOfTokenIdsToSearch;
|
||||
public int tokenIDStart; // set this as a starting point as needed
|
||||
string account;
|
||||
int balanceSearched;
|
||||
|
||||
async void Start()
|
||||
{
|
||||
// This is the account taken from the user login scene
|
||||
account = PlayerPrefs.GetString("Account");
|
||||
// Searches through your listed contracts
|
||||
foreach (string contract in nftContracts)
|
||||
{
|
||||
int balance = await ERC721.BalanceOf(contract, account);
|
||||
Debug.Log("Balance of contract " + contract + ": " + balance);
|
||||
// if i is less than the selected amount of tokenIDs to search, keep searching
|
||||
for (int i = 1; i < amountOfTokenIdsToSearch; i++)
|
||||
{
|
||||
// if balanceSearched is less than the balance for each contract, keep searching
|
||||
if (balanceSearched < balance)
|
||||
{
|
||||
Debug.Log("Searching" + (tokenIDStart + i));
|
||||
string ownerOf = await ERC721.OwnerOf(contract, (tokenIDStart + i).ToString());
|
||||
// if token id id matches the account from login, print the tokenID and get the URI
|
||||
if (ownerOf == account)
|
||||
{
|
||||
string uri = await ERC721.URI(contract, (tokenIDStart + i).ToString());
|
||||
Debug.Log("TokenID: " + (tokenIDStart + i));
|
||||
Debug.Log("Token URI: " + uri);
|
||||
balanceSearched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9b3d2893e2892a4d962a7c0348f71c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Web3Unity/Scripts/Prefabs/IPFS.meta
Normal file
3
Assets/Web3Unity/Scripts/Prefabs/IPFS.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe89c788c024a36b2b9e9dfaa40107e
|
||||
timeCreated: 1654612230
|
||||
18
Assets/Web3Unity/Scripts/Prefabs/IPFS/IPFSUploadExample.cs
Normal file
18
Assets/Web3Unity/Scripts/Prefabs/IPFS/IPFSUploadExample.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.IPFS;
|
||||
|
||||
public class IPFSUploadExample : MonoBehaviour
|
||||
{
|
||||
private const string apiKey = "YOUR_CHAINSAFE_STORE_API_KEY";
|
||||
|
||||
async void Start()
|
||||
{
|
||||
var data = System.Text.Encoding.UTF8.GetBytes("YOUR_DATA");
|
||||
|
||||
var ipfs = new IPFS(apiKey);
|
||||
var cid = await ipfs.Upload("BUCKET_ID", "/PATH", "FILENAME.ext", data, "application/octet-stream");
|
||||
print(cid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c21d8011b8fc440b9ca370987c9b813
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/Minter.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/Minter.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b87f9453f21675439a7996671f63f08
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/TheGraph.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/TheGraph.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac8b013b3c712ee48925b4e4dea394d6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
public class AllErc1155Example : MonoBehaviour
|
||||
{
|
||||
private class NFTs
|
||||
{
|
||||
public string contract { get; set; }
|
||||
public string tokenId { get; set; }
|
||||
public string uri { get; set; }
|
||||
public string balance { get; set; }
|
||||
}
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
var chain = "ethereum";
|
||||
var network = "goerli"; // mainnet goerli
|
||||
var account = "0xfaecAE4464591F8f2025ba8ACF58087953E613b1";
|
||||
var contract = "";
|
||||
var first = 1000;
|
||||
var skip = 0;
|
||||
var response = await EVM.AllErc1155(chain, network, account, contract, first, skip);
|
||||
try
|
||||
{
|
||||
var erc1155s = JsonConvert.DeserializeObject<NFTs[]>(response);
|
||||
print(erc1155s[0].contract);
|
||||
print(erc1155s[0].tokenId);
|
||||
print(erc1155s[0].uri);
|
||||
print(erc1155s[0].balance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
print("Error: " + response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de39b41a15d891546a231ca232181c16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.Connect;
|
||||
|
||||
public class AllErc721Example : MonoBehaviour
|
||||
{
|
||||
private class NFTs
|
||||
{
|
||||
public string contract { get; set; }
|
||||
public string tokenId { get; set; }
|
||||
public string uri { get; set; }
|
||||
public string balance { get; set; }
|
||||
}
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
var chain = "ethereum";
|
||||
var network = "goerli"; // mainnet goerli
|
||||
var account = "0xfaecAE4464591F8f2025ba8ACF58087953E613b1";
|
||||
var contract = "";
|
||||
var first = 500;
|
||||
var skip = 0;
|
||||
var response = await EVM.AllErc721(chain, network, account, contract, first, skip);
|
||||
try
|
||||
{
|
||||
var erc721s = JsonConvert.DeserializeObject<NFTs[]>(response);
|
||||
print(erc721s[0].contract);
|
||||
print(erc721s[0].tokenId);
|
||||
print(erc721s[0].uri);
|
||||
print(erc721s[0].balance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
print("Error: " + response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3039997b64df6fb4a98a78d54a695ee4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Web3Unity/Scripts/Prefabs/Wallet.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/Wallet.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45141def5c6f4f549bc12d5d2a05034f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Web3Unity/Scripts/Prefabs/Wallet/Web3WalletEvent.cs
Normal file
22
Assets/Web3Unity/Scripts/Prefabs/Wallet/Web3WalletEvent.cs
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 929873104199f244c8db737e1b9a68a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
public class Web3WalletGetArray : MonoBehaviour
|
||||
{
|
||||
public Text playerAddresses;
|
||||
public async void GetArrayData()
|
||||
{
|
||||
// contract to interact with
|
||||
string contractAddress = "0x5244d0453A727EDa96299384370359f4A2B5b20a";
|
||||
// abi in json format
|
||||
string abi =
|
||||
"[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_addresses\",\"type\":\"address[]\"}],\"name\":\"setStore\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"bought\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getStore\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";
|
||||
// smart contract method to call
|
||||
string method = "getStore";
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
var contract = new Contract(abi, contractAddress, provider);
|
||||
var calldata = await contract.Call(method);
|
||||
string json = JsonConvert.SerializeObject(calldata[0], Formatting.Indented);
|
||||
string[] addresses = JsonConvert.DeserializeObject<string[]>(json);
|
||||
if (addresses != null) Debug.Log("Addresses: " + addresses[0]);
|
||||
if (addresses != null) playerAddresses.text = addresses[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09dd3324433fb5345b67f400a3f0cb04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
public class Web3WalletGetBlockNumber : MonoBehaviour
|
||||
{
|
||||
public async void GetBlockNumber()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
Debug.Log("Block Number: " + await provider.GetBlockNumber());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc2f7d2ee51da6b4d98d7cc4944fbb9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using UnityEngine;
|
||||
|
||||
public class Web3WalletGetGasLimit : MonoBehaviour
|
||||
{
|
||||
public async void GetGasLimit()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
string contractAbi =
|
||||
"[ { \"inputs\": [ { \"internalType\": \"uint8\", \"name\": \"_myArg\", \"type\": \"uint8\" } ], \"name\": \"addTotal\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"myTotal\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
|
||||
string contractAddress = "0x741C3F3146304Aaf5200317cbEc0265aB728FE07";
|
||||
var contract = new Contract(contractAbi, contractAddress, provider);
|
||||
var gasLimit = await contract.EstimateGas("addTotal", new object[] { });
|
||||
Debug.Log("Gas Limit: " + gasLimit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45a6e642600fe8a4f93b2e228a559483
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
public class Web3WalletGetGasPrice : MonoBehaviour
|
||||
{
|
||||
public async void GetGasPrice()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
Debug.Log("Gas Price: " + await provider.GetGasPrice());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f26fd0d35dbb0394294765634254cf82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using Nethereum.Hex.HexTypes;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Signers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Transactions;
|
||||
using UnityEngine;
|
||||
|
||||
public class Web3WalletGetNonce : MonoBehaviour
|
||||
{
|
||||
public async void GetNonce()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
var signer = new JsonRpcSigner(provider, 0);
|
||||
var tx = await signer.SendTransaction(new TransactionRequest
|
||||
{
|
||||
To = await signer.GetAddress(),
|
||||
Value = new HexBigInteger(100000)
|
||||
});
|
||||
var nonce = tx.Nonce;
|
||||
Debug.Log("Nonce: " + nonce);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89c6d68520c0f4842aeb8fa424dd0164
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using Nethereum.Hex.HexTypes;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Signers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Transactions;
|
||||
using UnityEngine;
|
||||
|
||||
public class Web3WalletGetTxStatus : MonoBehaviour
|
||||
{
|
||||
public async void GetTransactionStatus()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
var signer = new JsonRpcSigner(provider, 0);
|
||||
var tx = await signer.SendTransaction(new TransactionRequest
|
||||
{
|
||||
To = await signer.GetAddress(),
|
||||
Value = new HexBigInteger(100000)
|
||||
});
|
||||
var txReceipt = await tx.Wait();
|
||||
Debug.Log("Transaction receipt: " + txReceipt.Confirmations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad93277313896614e96ab7f57eb29455
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Web3Unity/Scripts/Prefabs/Wallet/Web3WalletLogOut.cs
Normal file
13
Assets/Web3Unity/Scripts/Prefabs/Wallet/Web3WalletLogOut.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Web3WalletLogOut : MonoBehaviour
|
||||
{
|
||||
public void OnLogOut()
|
||||
{
|
||||
PlayerPrefs.SetString("Account", "");
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a372a6027936491684330010b06fd52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 236c27bfef14a7048a578ac4571d8518
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletSendArray : MonoBehaviour
|
||||
{
|
||||
public async void SendArrayObject()
|
||||
{
|
||||
// https://chainlist.org/
|
||||
var chainId = "5"; // goerli
|
||||
// contract to interact with
|
||||
var contractAddress = "0x5244d0453A727EDa96299384370359f4A2B5b20a";
|
||||
// value in wei
|
||||
var value = "0";
|
||||
// abi in json format
|
||||
var abi =
|
||||
"[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_addresses\",\"type\":\"address[]\"}],\"name\":\"setStore\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"bought\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getStore\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";
|
||||
// smart contract method to call
|
||||
var method = "setStore";
|
||||
string[] stringArray =
|
||||
{"0xFb3aECf08940785D4fB3Ad87cDC6e1Ceb20e9aac", "0x92d4040e4f3591e60644aaa483821d1bd87001e3"};
|
||||
var contract = new Contract(abi, contractAddress);
|
||||
// gas limit OPTIONAL
|
||||
var gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
var gasPrice = "";
|
||||
Debug.Log("Contract: " + contract);
|
||||
var calldata = contract.Calldata(method, new object[]
|
||||
{
|
||||
stringArray
|
||||
});
|
||||
Debug.Log("Contract Data: " + calldata);
|
||||
// send transaction
|
||||
var response = await Web3Wallet.SendTransaction(chainId, contractAddress, value, calldata, gasLimit, gasPrice);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e41dc1c4e5486124e80cce27fdc26795
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletSendTransactionExample : MonoBehaviour
|
||||
{
|
||||
async public void OnSendTransaction()
|
||||
{
|
||||
// https://chainlist.org/
|
||||
string chainId = "5"; // goerli
|
||||
// account to send to
|
||||
string to = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
|
||||
// value in wei
|
||||
string value = "12300000000000000";
|
||||
// data OPTIONAL
|
||||
string data = "";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// send transaction
|
||||
string response = await Web3Wallet.SendTransaction(chainId, to, value, data, gasLimit, gasPrice);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 232b754398a224e1d973860638474f95
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletSha3Example : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
string message = "hello";
|
||||
string hashedMessage = Web3Wallet.Sha3(message);
|
||||
// 0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8
|
||||
print(hashedMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc0471990638941039f2a83a72240425
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletSignMessageExample : MonoBehaviour
|
||||
{
|
||||
async public void OnSignMessage()
|
||||
{
|
||||
string response = await Web3Wallet.Sign("hello");
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user