Web3WalletGetGasLimit.cs 995 B

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