This is performed locally on the particular node that the client is communicating with. It cannot change the state of the contract instance (and so, cannot spend anything from the instance's cryptocurrency account).
It will not have a consensus timestamp. It cannot generate a record or a receipt. The response will contain the output returned by the function call. This is useful for calling getter functions, which purely read the state and don't change it. It is faster and cheaper than a normal call, because it is purely local to a single node.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.hedera.hashgraph.sdk.Executable
Executable.GrpcRequest -
Field Summary
Fields inherited from class com.hedera.hashgraph.sdk.Query
paymentTransactionId, paymentTransactionsFields inherited from class com.hedera.hashgraph.sdk.Executable
attemptedAllNodes, blockingUnaryCall, grpcDeadline, logger, maxAttempts, maxBackoff, minBackoff, nodeAccountIds, nodes, random, RST_STREAM -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExtract the contract id.getCostAsync(Client client) Fetch the expected cost asynchronously.com.google.protobuf.ByteStringExtract the function parameters.longgetGas()Extract the gas.longDeprecated.with no replacementCalled to direct the invocation of the query to the appropriate gRPC service.Get the sender account ID(package private) QueryHeadermapRequestHeader(Query request) The derived class should access its request header and return.(package private) ContractFunctionResultmapResponse(Response response, AccountId nodeId, Query request) Called after receiving the query response from Hedera.(package private) ResponseHeadermapResponseHeader(Response response) The derived class should access its response header and return.(package private) voidonMakeRequest(Query.Builder queryBuilder, QueryHeader header) Called inQuery.makeRequest()just before the query is built.setContractId(ContractId contractId) Sets the contract instance to call, in the format used in transactions.setFunction(String name) Sets the function name to call.setFunction(String name, ContractFunctionParameters params) Sets the function to call, and the parameters to pass to the function.setFunctionParameters(byte[] functionParameters) Sets the function parameters as their raw bytes.setGas(long gas) Sets the amount of gas to use for the call.setMaxResultSize(long size) Deprecated.with no replacement
Sets the max number of bytes that the result might include.setSenderAccountId(AccountId senderAccountId) Sets the account that is the "sender." If not present it is the accountId from the transactionId.(package private) voidvalidateChecksums(Client client) Validate the checksums.Methods inherited from class com.hedera.hashgraph.sdk.Query
getCost, getCost, getCostAsync, getCostAsync, getCostAsync, getCostAsync, getCostAsync, getOperatorFromClient, getPaymentTransaction, getPaymentTransactionId, getTransactionIdInternal, isPaymentRequired, makeRequest, mapResponseStatus, onExecute, onExecuteAsync, setMaxQueryPayment, setPaymentTransactionId, setQueryPayment, toStringMethods inherited from class com.hedera.hashgraph.sdk.Executable
advanceRequest, checkNodeAccountIds, execute, execute, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, getExecutionState, getGrpcRequest, getMaxAttempts, getMaxBackoff, getMaxRetry, getMinBackoff, getNodeAccountIds, getNodeForExecute, grpcDeadline, isBatchedAndNotBatchTransaction, logTransaction, mergeFromClient, setGrpcDeadline, setLogger, setMaxAttempts, setMaxBackoff, setMaxRetry, setMinBackoff, setNodeAccountIds, setNodesFromNodeAccountIds, setRequestListener, setResponseListener, shouldRetryExceptionally
-
Constructor Details
-
ContractCallQuery
public ContractCallQuery()Constructor.
-
-
Method Details
-
getContractId
Extract the contract id.- Returns:
- the contract id
-
setContractId
Sets the contract instance to call, in the format used in transactions.- Parameters:
contractId- The ContractId to be set- Returns:
this
-
getGas
public long getGas()Extract the gas.- Returns:
- the gas
-
setGas
Sets the amount of gas to use for the call.All of the gas offered will be charged for.
- Parameters:
gas- The long to be set as gas- Returns:
this
-
getCostAsync
Description copied from class:QueryFetch the expected cost asynchronously.- Overrides:
getCostAsyncin classQuery<ContractFunctionResult,ContractCallQuery> - Parameters:
client- the client- Returns:
- Future result of the cost in hbar
-
getFunctionParameters
public com.google.protobuf.ByteString getFunctionParameters()Extract the function parameters.- Returns:
- the byte string representation
-
setFunctionParameters
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
-
setFunction
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 function name to be set- Returns:
this
-
setFunction
Sets the function to call, and the parameters to pass to the function.- Parameters:
name- The function name to be setparams- The parameters to pass- Returns:
this
-
getMaxResultSize
Deprecated.with no replacementGet the max number of bytes that the result might include- Returns:
- the max number of byes
-
setMaxResultSize
Deprecated.with no replacement
Sets the max number of bytes that the result might include. The run will fail if it had returned more than this number of bytes.- Parameters:
size- The long to be set as size- Returns:
this
-
getSenderAccountId
Get the sender account ID- Returns:
- the account that is the "sender"
-
setSenderAccountId
Sets the account that is the "sender." If not present it is the accountId from the transactionId. Typically a different value than specified in the transactionId requires a valid signature over either the hedera transaction or foreign transaction data.- Parameters:
senderAccountId- the account that is the "sender"- Returns:
this
-
validateChecksums
Description copied from class:QueryValidate the checksums.- Specified by:
validateChecksumsin classQuery<ContractFunctionResult,ContractCallQuery> - Throws:
BadEntityIdException
-
onMakeRequest
Description copied from class:QueryCalled inQuery.makeRequest()just before the query is built. The intent is for the derived class to assign their data variant to the query.- Specified by:
onMakeRequestin classQuery<ContractFunctionResult,ContractCallQuery>
-
mapResponseHeader
Description copied from class:QueryThe derived class should access its response header and return.- Specified by:
mapResponseHeaderin classQuery<ContractFunctionResult,ContractCallQuery>
-
mapRequestHeader
Description copied from class:QueryThe derived class should access its request header and return.- Specified by:
mapRequestHeaderin classQuery<ContractFunctionResult,ContractCallQuery>
-
mapResponse
Description copied from class:ExecutableCalled after receiving the query response from Hedera. The derived class should map into its output type.- Specified by:
mapResponsein classExecutable<ContractCallQuery,Query, Response, ContractFunctionResult>
-
getMethodDescriptor
Description copied from class:ExecutableCalled to direct the invocation of the query to the appropriate gRPC service.- Specified by:
getMethodDescriptorin classExecutable<ContractCallQuery,Query, Response, ContractFunctionResult>
-