Web3WalletTransfer20Example.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Newtonsoft.Json;
  5. using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
  6. using Web3Unity.Scripts.Library.Ethers.Contracts;
  7. using Web3Unity.Scripts.Library.Web3Wallet;
  8. public class Web3WalletTransfer20Example : MonoBehaviour
  9. {
  10. async public void OnTransfer20()
  11. {
  12. // https://chainlist.org/
  13. string chainId = "5"; // goerli
  14. // contract to interact with
  15. string contract = "0xc778417e063141139fce010982780140aa0cd5ab";
  16. // value in wei
  17. string value = "0";
  18. // abi in json format
  19. string abi = "";//ABI.ERC_20;
  20. // smart contract method to call
  21. string method = "";//ETH_METHOD.Transfer;
  22. // account to send erc20 to
  23. string toAccount = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
  24. // amount of erc20 tokens to send
  25. string amount = "1000000000000000";
  26. // create data to interact with smart contract
  27. var contractData = new Contract(abi, contract);
  28. var data = contractData.Calldata(method, new object[]
  29. {
  30. toAccount,
  31. amount
  32. });
  33. // gas limit OPTIONAL
  34. string gasLimit = "";
  35. // gas price OPTIONAL
  36. string gasPrice = "";
  37. // send transaction
  38. string response = await Web3Wallet.SendTransaction(chainId, contract, value, data, gasLimit, gasPrice);
  39. print(response);
  40. }
  41. }