WebGLGetGasLimit.cs 1013 B

12345678910111213141516171819
  1. using Web3Unity.Scripts.Library.Ethers.Contracts;
  2. using Web3Unity.Scripts.Library.Ethers.Providers;
  3. using UnityEngine;
  4. #if UNITY_WEBGL
  5. public class WebGLGetGasLimit : MonoBehaviour
  6. {
  7. public async void GetGasLimit()
  8. {
  9. var provider = new JsonRpcProvider("YOUR_NODE");
  10. string contractAbi =
  11. "[ { \"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\" } ]";
  12. string contractAddress = "0x741C3F3146304Aaf5200317cbEc0265aB728FE07";
  13. var contract = new Contract(contractAbi, contractAddress, provider);
  14. var gasLimit = await contract.EstimateGas("addTotal", new object[] { });
  15. Debug.Log("Gas Limit: " + gasLimit);
  16. }
  17. }
  18. #endif