WebGLTransfer721.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using UnityEngine;
  3. using Newtonsoft.Json;
  4. using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
  5. using Web3Unity.Scripts.Prefabs;
  6. #if UNITY_WEBGL
  7. public class WebGLTransfer721 : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private string contract = "0xdE458Cd3dEaA28ce67BeEFE3F45368c875b3FfD6";
  11. [SerializeField]
  12. private string toAccount = "0xdA064B1Cef52e19caFF22ae2Cc1A4e8873B8bAB0";
  13. [SerializeField]
  14. private string tokenId = "1";
  15. private readonly string abi = ABI.ERC_721;
  16. async public void SafeTransferFrom()
  17. {
  18. // smart contract method to call
  19. string method = "safeTransferFrom";
  20. // array of arguments for contract
  21. string[] obj = { PlayerPrefs.GetString("Account"), toAccount, tokenId };
  22. string args = JsonConvert.SerializeObject(obj);
  23. // value in wei
  24. string value = "0";
  25. // gas limit OPTIONAL
  26. string gasLimit = "";
  27. // gas price OPTIONAL
  28. string gasPrice = "";
  29. // connects to user's browser wallet (metamask) to send a transaction
  30. try
  31. {
  32. string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
  33. Debug.Log(response);
  34. }
  35. catch (Exception e)
  36. {
  37. Debug.LogException(e, this);
  38. }
  39. }
  40. }
  41. #endif