init
This commit is contained in:
8
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge.meta
Normal file
8
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdf3dbc2030821146a887022b18b5cda
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Web3Unity.Scripts.Library.ETHEREUEM.WebGL
|
||||
{
|
||||
public class GameLogger
|
||||
{
|
||||
private const string loggingUrl = "https://game-api-stg.chainsafe.io/logging/logEvent";
|
||||
|
||||
public static async Task<string> Log(string _chain, string _network, object _data)
|
||||
{
|
||||
using var webRequest = new UnityWebRequest(loggingUrl, "POST");
|
||||
webRequest.timeout = -1;
|
||||
var bodyRaw = System.Text.Encoding.UTF8.GetBytes($"chain={_chain}&network={_network}&gameData={_data}");
|
||||
webRequest.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
||||
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
webRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
await webRequest.SendWebRequest();
|
||||
|
||||
return webRequest.result switch
|
||||
{
|
||||
UnityWebRequest.Result.ProtocolError => webRequest.error,
|
||||
_ => webRequest.downloadHandler.text
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5e65eab7e134a94f90d090a2d8d8a89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
232
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge/Web3GL.cs
Normal file
232
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge/Web3GL.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using GameData;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.WebGL;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class Web3GL
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SendContractJs(string method, string abi, string contract, string args, string value,
|
||||
string gasLimit, string gasPrice);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string SendContractResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SetContractResponse(string value);
|
||||
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void EcRecoverJS(string message, string signature);
|
||||
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string EcRecoverResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SendTransactionJs(string to, string value, string gasLimit, string gasPrice);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SendTransactionJsData(string to, string value, string gasPrice, string gasLimit,
|
||||
string data);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string SendTransactionResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SetTransactionResponse(string value);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SetTransactionResponseData(string value);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SignMessage(string value);
|
||||
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void HashMessage(string value);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string SignMessageResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string HashMessageResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SetSignMessageResponse(string value);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SetHashMessageResponse(string value);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern int GetNetwork();
|
||||
|
||||
// this function will create a metamask tx for user to confirm.
|
||||
public static async Task<string> SendContract(string _method, string _abi, string _contract, string _args,
|
||||
string _value, string _gasLimit = "", string _gasPrice = "")
|
||||
{
|
||||
// Set response to empty
|
||||
SetContractResponse("");
|
||||
SendContractJs(_method, _abi, _contract, _args, _value, _gasLimit, _gasPrice);
|
||||
var data = new
|
||||
{
|
||||
Client = "WebGL",
|
||||
Version = "v2",
|
||||
ProjectID = PlayerPrefs.GetString("ProjectID"),
|
||||
Player = Sha3(PlayerPrefs.GetString("Account") + PlayerPrefs.GetString("ProjectID")),
|
||||
Method = _method,
|
||||
Address = _contract,
|
||||
ABI = _abi,
|
||||
ARGS = _args,
|
||||
Value = _value,
|
||||
GasLimit = _gasLimit,
|
||||
GasPrice = _gasPrice
|
||||
};
|
||||
await GameLogger.Log(PlayerPrefs.GetString("ChainId"), PlayerPrefs.GetString("RPC"), data);
|
||||
var response = SendContractResponse();
|
||||
while (response == "")
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
response = SendContractResponse();
|
||||
}
|
||||
|
||||
SetContractResponse("");
|
||||
// check if user submmited or user rejected
|
||||
if (response.Length == 66)
|
||||
{
|
||||
await GameLogger.Log(PlayerPrefs.GetString("ChainId"), PlayerPrefs.GetString("RPC"), data);
|
||||
return response;
|
||||
}
|
||||
throw new Exception(response);
|
||||
}
|
||||
|
||||
public static async Task<string> SendTransaction(string _to, string _value, string _gasLimit = "",
|
||||
string _gasPrice = "")
|
||||
{
|
||||
// Set response to empty
|
||||
SetTransactionResponse("");
|
||||
SendTransactionJs(_to, _value, _gasLimit, _gasPrice);
|
||||
var data = new
|
||||
{
|
||||
Client = "WebGL",
|
||||
Version = "v2",
|
||||
ProjectID = PlayerPrefs.GetString("ProjectID"),
|
||||
Player = Sha3(PlayerPrefs.GetString("Account") + PlayerPrefs.GetString("ProjectID")).ToString(),
|
||||
To = _to,
|
||||
Value = _value,
|
||||
GasLimit = _gasLimit,
|
||||
GasPrice = _gasPrice
|
||||
};
|
||||
var response = SendTransactionResponse();
|
||||
while (response == "")
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
response = SendTransactionResponse();
|
||||
}
|
||||
|
||||
SetTransactionResponse("");
|
||||
// check if user submmited or user rejected
|
||||
if (response.Length == 66)
|
||||
{
|
||||
await GameLogger.Log(PlayerPrefs.GetString("ChainId"), PlayerPrefs.GetString("RPC"), data);
|
||||
return response;
|
||||
}
|
||||
throw new Exception(response);
|
||||
}
|
||||
|
||||
public static async Task<string> SendTransactionData(string _to, string _value, string _gasPrice = "",
|
||||
string _gasLimit = "", string _data = "")
|
||||
{
|
||||
// Set response to empty
|
||||
SetTransactionResponse("");
|
||||
SendTransactionJsData(_to, _value, _gasPrice, _gasLimit, _data);
|
||||
var data = new
|
||||
{
|
||||
Client = "WebGL",
|
||||
Version = "v2",
|
||||
ProjectID = PlayerPrefs.GetString("ProjectID"),
|
||||
Player = Sha3(PlayerPrefs.GetString("Account") + PlayerPrefs.GetString("ProjectID")),
|
||||
To = _to,
|
||||
Value = _value,
|
||||
GasLimit = _gasLimit,
|
||||
GasPrice = _gasPrice
|
||||
};
|
||||
var response = SendTransactionResponse();
|
||||
Debug.Log("called from webgl" + response);
|
||||
//Logging.SendGameData(data);
|
||||
while (response == "")
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
response = SendTransactionResponse();
|
||||
}
|
||||
SetTransactionResponse("");
|
||||
// check if user submmited or user rejected
|
||||
if (response.Length == 66)
|
||||
{
|
||||
return response;
|
||||
}
|
||||
throw new Exception(response);
|
||||
}
|
||||
|
||||
public static async Task<string> Sign(string _message)
|
||||
{
|
||||
SignMessage(_message);
|
||||
var response = SignMessageResponse();
|
||||
while (response == "")
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
response = SignMessageResponse();
|
||||
}
|
||||
|
||||
// Set response to empty
|
||||
SetSignMessageResponse("");
|
||||
// check if user submmited or user rejected
|
||||
if (response.Length == 132)
|
||||
return response;
|
||||
throw new Exception(response);
|
||||
}
|
||||
|
||||
public static async Task<string> Sha3(string _message)
|
||||
{
|
||||
HashMessage(_message);
|
||||
SetHashMessageResponse("");
|
||||
try
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
var response = HashMessageResponse();
|
||||
return response;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> EcRecover(string _message, string _signature)
|
||||
{
|
||||
EcRecoverJS(_message, _signature);
|
||||
EcRecoverResponse();
|
||||
try
|
||||
{
|
||||
await new WaitForSeconds(1f);
|
||||
var response = EcRecoverResponse();
|
||||
return response;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int Network()
|
||||
{
|
||||
return GetNetwork();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f471a8d48b5e844d9f6167058b8eebb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class Web3GLLight
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
private static extern void ClearResponseJs();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string SendAsyncResponse();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string SendAsyncError();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SendAsyncJs(string method, string parameters);
|
||||
|
||||
public static async Task<string> SendAsync(string method, string parameters)
|
||||
{
|
||||
ClearResponseJs();
|
||||
|
||||
SendAsyncJs(method, parameters);
|
||||
var response = "";
|
||||
var error = "";
|
||||
|
||||
while (response == "" && error == "")
|
||||
{
|
||||
await new WaitForSeconds(0.1f);
|
||||
response = SendAsyncResponse();
|
||||
error = SendAsyncError();
|
||||
}
|
||||
|
||||
if (error != "")
|
||||
{
|
||||
var err = JsonConvert.DeserializeObject<WalletError>(error);
|
||||
throw new WalletException(err!.Code, err.Message);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public class WalletError
|
||||
{
|
||||
[JsonProperty(PropertyName = "code")] public int Code { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "message")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class WalletException : Exception
|
||||
{
|
||||
public int code;
|
||||
public string message;
|
||||
|
||||
public WalletException(int code, string message)
|
||||
{
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fcd90ef44624854aa5ae479c1df87af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
121
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge/web3gl.jslib
Normal file
121
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLBridge/web3gl.jslib
Normal file
@@ -0,0 +1,121 @@
|
||||
mergeInto(LibraryManager.library, {
|
||||
Web3Connect: function () {
|
||||
window.web3gl.connect();
|
||||
},
|
||||
|
||||
ConnectAccount: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.connectAccount) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.connectAccount, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
SetConnectAccount: function (value) {
|
||||
window.web3gl.connectAccount = value;
|
||||
},
|
||||
|
||||
SendContractJs: function (method, abi, contract, args, value, gasLimit, gasPrice) {
|
||||
window.web3gl.sendContract(
|
||||
UTF8ToString(method),
|
||||
UTF8ToString(abi),
|
||||
UTF8ToString(contract),
|
||||
UTF8ToString(args),
|
||||
UTF8ToString(value),
|
||||
UTF8ToString(gasLimit),
|
||||
UTF8ToString(gasPrice)
|
||||
);
|
||||
},
|
||||
|
||||
SendContractResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.sendContractResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.sendContractResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
EcRecoverJS: function (message,signature) {
|
||||
window.web3gl.ecRecover(
|
||||
UTF8ToString(message),
|
||||
UTF8ToString(signature)
|
||||
);
|
||||
},
|
||||
|
||||
EcRecoverResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.ecRecoverAddressResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.ecRecoverAddressResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
SetContractResponse: function (value) {
|
||||
window.web3gl.sendContractResponse = value;
|
||||
},
|
||||
|
||||
SendTransactionJs: function (to, value, gasLimit, gasPrice) {
|
||||
window.web3gl.sendTransaction(
|
||||
UTF8ToString(to),
|
||||
UTF8ToString(value),
|
||||
UTF8ToString(gasLimit),
|
||||
UTF8ToString(gasPrice)
|
||||
);
|
||||
},
|
||||
|
||||
SendTransactionJsData: function (to, value, gasLimit, gasPrice, data) {
|
||||
window.web3gl.sendTransactionData(
|
||||
UTF8ToString(to),
|
||||
UTF8ToString(value),
|
||||
UTF8ToString(gasLimit),
|
||||
UTF8ToString(gasPrice),
|
||||
UTF8ToString(data)
|
||||
);
|
||||
},
|
||||
|
||||
SendTransactionResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.sendTransactionResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.sendTransactionResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
SetTransactionResponse: function (value) {
|
||||
window.web3gl.sendTransactionResponse = value;
|
||||
},
|
||||
|
||||
SetTransactionResponseData: function (value) {
|
||||
window.web3gl.sendTransactionResponseData = value;
|
||||
},
|
||||
|
||||
SignMessage: function (message) {
|
||||
window.web3gl.signMessage(UTF8ToString(message));
|
||||
},
|
||||
|
||||
HashMessage: function (message) {
|
||||
window.web3gl.sha3Message(UTF8ToString(message));
|
||||
},
|
||||
|
||||
SignMessageResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.signMessageResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.signMessageResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
HashMessageResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.hashMessageResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.hashMessageResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
SetSignMessageResponse: function (value) {
|
||||
window.web3gl.signMessageResponse = value;
|
||||
},
|
||||
|
||||
SetHashMessageResponse: function (value) {
|
||||
window.web3gl.hashMessageResponse = value;
|
||||
},
|
||||
|
||||
GetNetwork: function () {
|
||||
return window.web3gl.networkId;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b12b190155856e14fbd9f0c367af9a55
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
mergeInto(LibraryManager.library, {
|
||||
ClearResponseJs: function () {
|
||||
window.web3gl.clearResponse();
|
||||
},
|
||||
|
||||
SendAsyncJs: function (method, parameters) {
|
||||
window.web3gl.sendAsync(
|
||||
UTF8ToString(method),
|
||||
UTF8ToString(parameters)
|
||||
);
|
||||
},
|
||||
|
||||
SendAsyncResponse: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.sendAsyncResponse) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.sendAsyncResponse, buffer, bufferSize);
|
||||
return buffer;
|
||||
},
|
||||
|
||||
SendAsyncError: function () {
|
||||
var bufferSize = lengthBytesUTF8(window.web3gl.sendAsyncError) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(window.web3gl.sendAsyncError, buffer, bufferSize);
|
||||
return buffer;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 963e6e0df2159154bb03c6338828d46f
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12c3c7924ab68334ca08c68eedf55a48
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract AddressStore {
|
||||
address[] public bought;
|
||||
|
||||
// set the addresses in store
|
||||
function setStore(address[] calldata _addresses) public {
|
||||
bought = _addresses;
|
||||
}
|
||||
function getStore()public view returns( address [] memory){
|
||||
return bought;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ac4d629c54113243a1c4c633c4aca04
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetArray.cs
Normal file
34
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetArray.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetArray : MonoBehaviour
|
||||
{
|
||||
// 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";
|
||||
// Address TextField
|
||||
public Text playerAddresses;
|
||||
public async void GetArrayDataWeb()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
var contract = new Contract(abi, contractAddress, provider);
|
||||
Debug.Log("Gas Price: " + await provider.GetGasPrice());
|
||||
var gasPrice = await provider.GetGasPrice();
|
||||
var gasValue = await contract.EstimateGas("getStore", new object[] { });
|
||||
Debug.Log("Gas Value: " + gasValue.Value);
|
||||
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];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetArray.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetArray.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c4fcdfdd56ae3a439312cefcc53eb10
|
||||
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;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetBlockNumber : MonoBehaviour
|
||||
{
|
||||
public async void GetBlockNumber()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
Debug.Log("Block Number: " + await provider.GetBlockNumber());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df2f351c7e11d1e4c95243d4d43abd32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetGasLimit.cs
Normal file
19
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetGasLimit.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetGasLimit : 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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f88abf9564ecab49af77023a4f0023d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetGasPrice.cs
Normal file
13
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetGasPrice.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetGasPrice : MonoBehaviour
|
||||
{
|
||||
public async void GetGasPrice()
|
||||
{
|
||||
var provider = new JsonRpcProvider("YOUR_NODE");
|
||||
Debug.Log("Gas Price: " + await provider.GetGasPrice());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dae92c85fc31a554495867b0c4962907
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetNonce.cs
Normal file
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetNonce.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Nethereum.Hex.HexTypes;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Signers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Transactions;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetNonce : 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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetNonce.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetNonce.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c112af4422d1504e9dd6070f09fbdad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetTxStatus.cs
Normal file
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLGetTxStatus.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Nethereum.Hex.HexTypes;
|
||||
using Web3Unity.Scripts.Library.Ethers.Providers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Signers;
|
||||
using Web3Unity.Scripts.Library.Ethers.Transactions;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLGetTxStatus : 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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b51ac701446792d43928cfcd04421615
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSendContractExample : MonoBehaviour
|
||||
{
|
||||
async public void OnSendContract()
|
||||
{
|
||||
// smart contract method to call
|
||||
string method = "addTotal";
|
||||
// abi in json format
|
||||
string abi = "[ { \"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\" } ]";
|
||||
// address of contract
|
||||
string contract = "0x7286Cf0F6E80014ea75Dbc25F545A3be90F4904F";
|
||||
// array of arguments for contract
|
||||
string args = "[\"1\"]";
|
||||
// value in wei
|
||||
string value = "0";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// connects to user's browser wallet (metamask) to update contract state
|
||||
try
|
||||
{
|
||||
string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
|
||||
Debug.Log(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fda90bf1705674be5a4ba770e886ed57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSendTransactionExample : MonoBehaviour
|
||||
{
|
||||
async public void OnSendTransaction()
|
||||
{
|
||||
// account to send to
|
||||
string to = "0x428066dd8A212104Bc9240dCe3cdeA3D3A0f7979";
|
||||
// amount in wei to send
|
||||
string value = "12300000000000000";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// connects to user's browser wallet (metamask) to send a transaction
|
||||
try
|
||||
{
|
||||
string response = await Web3GL.SendTransaction(to, value, gasLimit, gasPrice);
|
||||
Debug.Log(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d39044a7e17140e5abc3f0bb134e195
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSetArray.cs
Normal file
35
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSetArray.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSetArray : MonoBehaviour
|
||||
{
|
||||
public async void SetArrayObject()
|
||||
{
|
||||
// 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 = "";
|
||||
var calldata = contract.Calldata(method, new object[]
|
||||
{
|
||||
stringArray
|
||||
});
|
||||
Debug.Log("Contract Data: " + calldata[0]);
|
||||
// send transaction
|
||||
var response = await Web3GL.SendTransactionData(contractAddress, value, gasLimit, gasPrice, calldata);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSetArray.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSetArray.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ec962d037f7c1542a2d9dc88c5f1319
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSha3Example.cs
Normal file
23
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSha3Example.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSha3Example : MonoBehaviour
|
||||
{
|
||||
async public void OnHashMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
string message = "hello";
|
||||
string hashedMessage = await Web3GL.Sha3(message);
|
||||
Debug.Log("Hashed Message :" + hashedMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 415a49f0cfd9258409e3bb0f5e2bff34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSignMessageExample : MonoBehaviour
|
||||
{
|
||||
async public void OnSignMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
string message = "hello";
|
||||
string response = await Web3GL.Sign(message);
|
||||
print(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52d4510e642f94f8aa1c0c8b71c8c0b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignOut.cs
Normal file
17
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignOut.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLSignOut : MonoBehaviour
|
||||
{
|
||||
public void OnSignOut()
|
||||
{
|
||||
// Clear Account
|
||||
PlayerPrefs.SetString("Account", "0x0000000000000000000000000000000000000001");
|
||||
// go to login scene
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignOut.cs.meta
Normal file
11
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignOut.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ea08ecba13e14353bd92a30e391a672
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
|
||||
public class WebGLSignVerifyExample : MonoBehaviour
|
||||
{
|
||||
public string message = "hello";
|
||||
public Text textHashedMessage;
|
||||
public Text textSignedHash;
|
||||
public Text verifyAddress;
|
||||
|
||||
async public void OnHashMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
string hashedMessage = await Web3GL.Sha3(message);
|
||||
textHashedMessage.text = hashedMessage;
|
||||
Debug.Log("Hashed Message: " + hashedMessage);
|
||||
string signHashed = await Web3GL.Sign(hashedMessage);
|
||||
Debug.Log("Signed Hashed: " + signHashed);
|
||||
textSignedHash.text = signHashed;
|
||||
ParseSignatureFunction(signHashed);
|
||||
string verify = await Web3GL.EcRecover(hashedMessage, signHashed);
|
||||
verifyAddress.text = verify;
|
||||
Debug.Log("Verify Address: " + verifyAddress.text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
public void ParseSignatureFunction(string sig)
|
||||
{
|
||||
string signature = sig;
|
||||
string r = signature.Substring(0, 66);
|
||||
Debug.Log("R:" + r);
|
||||
string s = "0x" + signature.Substring(66, 64);
|
||||
Debug.Log("S: " + s);
|
||||
int v = int.Parse(signature.Substring(130, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
Debug.Log("V: " + v);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c19034a790b61441adfd1dffc88b51c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer1155.cs
Normal file
47
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer1155.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Prefabs;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLTransfer1155 : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string contract = "0x8207ba6852ee561f0786e2d876b1a20fef916e46";
|
||||
[SerializeField]
|
||||
private string toAccount = "0xdA064B1Cef52e19caFF22ae2Cc1A4e8873B8bAB0";
|
||||
[SerializeField]
|
||||
private string tokenId = "0";
|
||||
[SerializeField]
|
||||
private string amount = "1";
|
||||
private readonly string abi = ABI.ERC_1155;
|
||||
|
||||
async public void SafeTransferFrom()
|
||||
{
|
||||
// smart contract method to call
|
||||
string method = "safeTransferFrom";
|
||||
// array of arguments for contract
|
||||
string[] obj = { PlayerPrefs.GetString("Account"), toAccount, tokenId, amount, "0x" };
|
||||
string args = JsonConvert.SerializeObject(obj);
|
||||
// value in wei
|
||||
string value = "0";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// connects to user's browser wallet (metamask) to send a transaction
|
||||
try
|
||||
{
|
||||
string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
|
||||
Debug.Log(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce14956df350145d3bbd308131fed178
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer20.cs
Normal file
46
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer20.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Prefabs;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLTransfer20 : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string contract = "0xc47cB02956F0c735f1136386B0B684e2CE5635dD";
|
||||
[SerializeField]
|
||||
private string toAccount = "0xdA064B1Cef52e19caFF22ae2Cc1A4e8873B8bAB0";
|
||||
[SerializeField]
|
||||
private string amount = "1000000000000000000";
|
||||
|
||||
private readonly string abi = ABI.ERC_20;
|
||||
|
||||
async public void Transfer()
|
||||
{
|
||||
// smart contract method to call
|
||||
string method = "transfer";
|
||||
// array of arguments for contract
|
||||
string[] obj = { toAccount, amount };
|
||||
string args = JsonConvert.SerializeObject(obj);
|
||||
// value in wei
|
||||
string value = "0";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// connects to user's browser wallet (metamask) to send a transaction
|
||||
try
|
||||
{
|
||||
string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
|
||||
Debug.Log(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5f632a6ef41741529047467ba439882
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer721.cs
Normal file
43
Assets/Web3Unity/Scripts/Prefabs/WebGL/WebGLTransfer721.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Prefabs;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
public class WebGLTransfer721 : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string contract = "0xdE458Cd3dEaA28ce67BeEFE3F45368c875b3FfD6";
|
||||
[SerializeField]
|
||||
private string toAccount = "0xdA064B1Cef52e19caFF22ae2Cc1A4e8873B8bAB0";
|
||||
[SerializeField]
|
||||
private string tokenId = "1";
|
||||
private readonly string abi = ABI.ERC_721;
|
||||
|
||||
async public void SafeTransferFrom()
|
||||
{
|
||||
// smart contract method to call
|
||||
string method = "safeTransferFrom";
|
||||
// array of arguments for contract
|
||||
string[] obj = { PlayerPrefs.GetString("Account"), toAccount, tokenId };
|
||||
string args = JsonConvert.SerializeObject(obj);
|
||||
// value in wei
|
||||
string value = "0";
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// connects to user's browser wallet (metamask) to send a transaction
|
||||
try
|
||||
{
|
||||
string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
|
||||
Debug.Log(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95c01fb230d7547dfa36bfc414e72e64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user