init
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7c4fab6fc8a6406c83e63a02caa076e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Text;
|
||||
using Nethereum.Signer;
|
||||
using Nethereum.Util;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletSignVerify : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
async void Start()
|
||||
{
|
||||
string message = "hello";
|
||||
string signature = await Web3Wallet.Sign(message);
|
||||
//verification
|
||||
SignVerifySignature(signature, message);
|
||||
}
|
||||
|
||||
public void SignVerifySignature(string signatureString, string originalMessage)
|
||||
{
|
||||
string msg = "\x19" + "Ethereum Signed Message:\n" + originalMessage.Length + originalMessage;
|
||||
byte[] msgHash = new Sha3Keccack().CalculateHash(Encoding.UTF8.GetBytes(msg));
|
||||
EthECDSASignature signature = MessageSigner.ExtractEcdsaSignature(signatureString);
|
||||
EthECKey key = EthECKey.RecoverFromSignature(signature, msgHash);
|
||||
|
||||
bool isValid = key.Verify(msgHash, signature);
|
||||
Debug.Log("Address Returned: " + key.GetPublicAddress());
|
||||
Debug.Log("Is Valid: " + isValid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22b7ebb5b91e09b4fa5c2911cefd95c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletTransfer1155Example : MonoBehaviour
|
||||
{
|
||||
public async void OnTransfer1155()
|
||||
{
|
||||
// https://chainlist.org/
|
||||
var chainId = "5"; // goerli
|
||||
// contract to interact with
|
||||
var contract = "0xae283E79a5361CF1077bf2638a1A953c872AD973";
|
||||
// value in wei
|
||||
var value = "0";
|
||||
// abi in json format
|
||||
var abi = "";//ABI.ERC_1155;
|
||||
// smart contract method to call
|
||||
var method = "safeTransferFrom";
|
||||
// account to sent tokens to
|
||||
var toAccount = PlayerPrefs.GetString("Account");
|
||||
// token id to send
|
||||
var tokenId = 0;
|
||||
// amount of tokens to send
|
||||
var amount = 1;
|
||||
// bytes
|
||||
byte[] dataObject = { };
|
||||
// array of arguments for contract
|
||||
var contractData = new Contract(abi, contract);
|
||||
var data = contractData.Calldata(method, new object[]
|
||||
{
|
||||
PlayerPrefs.GetString("Account"),
|
||||
toAccount,
|
||||
tokenId,
|
||||
amount,
|
||||
dataObject
|
||||
});
|
||||
// gas limit OPTIONAL
|
||||
var gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
var gasPrice = "";
|
||||
// send transaction
|
||||
var response = await Web3Wallet.SendTransaction(chainId, contract, value, data, gasLimit, gasPrice);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4bf735480ca04e308bcc3c68fc2ff9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
|
||||
public class Web3WalletTransfer20Example : MonoBehaviour
|
||||
{
|
||||
async public void OnTransfer20()
|
||||
{
|
||||
// https://chainlist.org/
|
||||
string chainId = "5"; // goerli
|
||||
// contract to interact with
|
||||
string contract = "0xc778417e063141139fce010982780140aa0cd5ab";
|
||||
// value in wei
|
||||
string value = "0";
|
||||
// abi in json format
|
||||
string abi = "";//ABI.ERC_20;
|
||||
// smart contract method to call
|
||||
string method = "";//ETH_METHOD.Transfer;
|
||||
// account to send erc20 to
|
||||
string toAccount = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
|
||||
// amount of erc20 tokens to send
|
||||
string amount = "1000000000000000";
|
||||
// create data to interact with smart contract
|
||||
var contractData = new Contract(abi, contract);
|
||||
var data = contractData.Calldata(method, new object[]
|
||||
{
|
||||
toAccount,
|
||||
amount
|
||||
});
|
||||
// gas limit OPTIONAL
|
||||
string gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
string gasPrice = "";
|
||||
// send transaction
|
||||
string response = await Web3Wallet.SendTransaction(chainId, contract, value, data, gasLimit, gasPrice);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7663fe07418404eb485419a59fbed93b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using UnityEngine;
|
||||
using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
|
||||
using Web3Unity.Scripts.Library.Ethers.Contracts;
|
||||
using Web3Unity.Scripts.Library.Web3Wallet;
|
||||
using Web3Unity.Scripts.Prefabs;
|
||||
using Contract = Web3Unity.Scripts.Library.Ethers.Contracts.Contract;
|
||||
|
||||
public class Web3WalletTransfer721Example : MonoBehaviour
|
||||
{
|
||||
public async void OnTransfer721()
|
||||
{
|
||||
// https://chainlist.org/
|
||||
var chainId = "5"; // goerli
|
||||
// contract to interact with
|
||||
var contract = "0x31A61D3B956d9E95e0b9434BEf24bfEebB48b2c5";
|
||||
// value in wei
|
||||
var value = "0";
|
||||
// abi in json format
|
||||
var abi = ABI.ERC_721;
|
||||
// smart contract method to call
|
||||
var method = ETH_METHOD.SafeTransferFrom;
|
||||
// account to send erc721 to
|
||||
var toAccount = PlayerPrefs.GetString("Account");
|
||||
// token id to send
|
||||
var tokenId = "0";
|
||||
var contractData = new Contract(abi, contract);
|
||||
|
||||
var data = contractData.Calldata(method, new object[]
|
||||
{
|
||||
toAccount,
|
||||
toAccount,
|
||||
tokenId
|
||||
});
|
||||
print(data);
|
||||
// gas limit OPTIONAL
|
||||
var gasLimit = "";
|
||||
// gas price OPTIONAL
|
||||
var gasPrice = "";
|
||||
// send transaction
|
||||
var response = await Web3Wallet.SendTransaction(chainId, contract, value, data, gasLimit, gasPrice);
|
||||
print(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54e07b30e098c4bdc86b1680d16ccd01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user