Class MirrorNodeContractQuery<T extends MirrorNodeContractQuery<T>>

java.lang.Object
com.hedera.hashgraph.sdk.MirrorNodeContractQuery<T>
Direct Known Subclasses:
MirrorNodeContractCallQuery, MirrorNodeContractEstimateGasQuery

public abstract class MirrorNodeContractQuery<T extends MirrorNodeContractQuery<T>> extends Object
MirrorNodeContractQuery returns a result from EVM execution such as cost-free execution of read-only smart contract queries, gas estimation, and transient simulation of read-write operations.
  • Constructor Details

    • MirrorNodeContractQuery

      public MirrorNodeContractQuery()
  • Method Details

    • self

      protected T self()
    • getContractId

      public ContractId getContractId()
    • setContractId

      public T setContractId(ContractId contractId)
      Sets the contract instance to call.
      Parameters:
      contractId - The ContractId to be set
      Returns:
      this
    • getContractEvmAddress

      public String getContractEvmAddress()
    • setContractEvmAddress

      public T setContractEvmAddress(String contractEvmAddress)
      Set the 20-byte EVM address of the contract to call.
      Parameters:
      contractEvmAddress -
      Returns:
      this
    • getSender

      public AccountId getSender()
    • setSender

      public T setSender(AccountId sender)
      Sets the sender of the transaction simulation.
      Parameters:
      sender - The AccountId to be set
      Returns:
      this
    • getSenderEvmAddress

      public String getSenderEvmAddress()
    • setSenderEvmAddress

      public T setSenderEvmAddress(String senderEvmAddress)
      Set the 20-byte EVM address of the sender.
      Parameters:
      senderEvmAddress -
      Returns:
      this
    • getCallData

      public byte[] getCallData()
    • setFunction

      public T setFunction(String name, ContractFunctionParameters params)
      Sets the function to call, and the parameters to pass to the function.
      Parameters:
      name - The String to be set as the function name
      params - The function parameters to be set
      Returns:
      this
    • setFunction

      public T setFunction(String name)
      Sets the function name to call.

      The function will be called with no parameters. Use setFunction(String, ContractFunctionParameters) to call a function with parameters.

      Parameters:
      name - The String to be set as the function name
      Returns:
      this
    • setFunctionParameters

      public T setFunctionParameters(com.google.protobuf.ByteString functionParameters)
      Sets the function parameters as their raw bytes.

      Use this instead of setFunction(String, ContractFunctionParameters) if you have already pre-encoded a solidity function call.

      Parameters:
      functionParameters - The function parameters to be set
      Returns:
      this
    • getValue

      public long getValue()
    • setValue

      public T setValue(long value)
      Sets the amount of value (in tinybars or wei) to be sent to the contract in the transaction.

      Use this to specify an amount for a payable function call.

      Parameters:
      value - the amount of value to send, in tinybars or wei
      Returns:
      this
    • getGasLimit

      public long getGasLimit()
    • setGasLimit

      public T setGasLimit(long gasLimit)
      Sets the gas limit for the contract call.

      This specifies the maximum amount of gas that the transaction can consume.

      Parameters:
      gasLimit - the maximum gas allowed for the transaction
      Returns:
      this
    • getGasPrice

      public long getGasPrice()
    • setGasPrice

      public T setGasPrice(long gasPrice)
      Sets the gas price to be used for the contract call.

      This specifies the price of each unit of gas used in the transaction.

      Parameters:
      gasPrice - the gas price, in tinybars or wei, for each unit of gas
      Returns:
      this
    • getBlockNumber

      public Long getBlockNumber()
    • setBlockNumber

      public T setBlockNumber(Long block)
      Sets the block number for the simulation of the contract call.

      The block number determines the context of the contract call simulation within the blockchain.

      Parameters:
      block - the block number at which to simulate the contract call
      Returns:
      this
    • estimate

      protected long estimate(Client client) throws ExecutionException, InterruptedException
      Returns gas estimation for the EVM execution
      Parameters:
      client -
      Throws:
      ExecutionException
      InterruptedException
    • call

      protected String call(Client client) throws ExecutionException, InterruptedException
      Does transient simulation of read-write operations and returns the result in hexadecimal string format. The result can be any solidity type.
      Parameters:
      client -
      Throws:
      ExecutionException
      InterruptedException
    • createJsonPayload

      static String createJsonPayload(byte[] data, String senderAddress, String contractAddress, long gas, long gasPrice, long value, Long block, boolean estimate)
    • parseContractCallResult

      static String parseContractCallResult(String responseBody)
    • parseHexEstimateToLong

      static long parseHexEstimateToLong(String responseBody)
    • toString

      public String toString()
      Overrides:
      toString in class Object