WebGLTransfer20.cs 1.3 KB

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