WebGLTransfer1155.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 WebGLTransfer1155 : MonoBehaviour
  10. {
  11. [SerializeField]
  12. private string contract = "0x8207ba6852ee561f0786e2d876b1a20fef916e46";
  13. [SerializeField]
  14. private string toAccount = "0xdA064B1Cef52e19caFF22ae2Cc1A4e8873B8bAB0";
  15. [SerializeField]
  16. private string tokenId = "0";
  17. [SerializeField]
  18. private string amount = "1";
  19. private readonly string abi = ABI.ERC_1155;
  20. async public void SafeTransferFrom()
  21. {
  22. // smart contract method to call
  23. string method = "safeTransferFrom";
  24. // array of arguments for contract
  25. string[] obj = { PlayerPrefs.GetString("Account"), toAccount, tokenId, amount, "0x" };
  26. string args = JsonConvert.SerializeObject(obj);
  27. // value in wei
  28. string value = "0";
  29. // gas limit OPTIONAL
  30. string gasLimit = "";
  31. // gas price OPTIONAL
  32. string gasPrice = "";
  33. // connects to user's browser wallet (metamask) to send a transaction
  34. try
  35. {
  36. string response = await Web3GL.SendContract(method, abi, contract, args, value, gasLimit, gasPrice);
  37. Debug.Log(response);
  38. }
  39. catch (Exception e)
  40. {
  41. Debug.LogException(e, this);
  42. };
  43. }
  44. }
  45. #endif