Skip to main content
A query that returns the bytecode for a smart contract instance. Anyone can request the byte code of a smart contract instance on the network. Queries do not change the state of the smart contract or require network consensus. The information is returned from a single node processing the query.

Recommend Using Mirror Node REST API

For obtaining smart contract information and historical data, consider using the Mirror Node REST API endpoint Get Contract by ID which offers several advantages:
  • Cost-effective and scalable: Mirror node providers offer paid plans with a large number of queries included. The Hedera-hosted mirror node offers free queries with specific throttles for testing. While some SDK queries are currently free, these are subject to change in the future.
  • Performance: Mirror nodes don’t burden consensus nodes, allowing them to focus on processing transactions and providing efficient access to historical data without impacting network performance.
  • Historical data: Mirror nodes store complete transaction history, records, and events - ideal for analytics, auditing, and monitoring past activity.
Query Signing Requirements
  • The client operator account’s private key (fee payer) is required to sign this query
Query Fees
  • Please see the transaction and query fees table for the base transaction fee
  • Please use the Hedera fee estimator to estimate your query fee cost

Methods

MethodTypeDescriptionRequirements
setContractId(<contractId>)ContractIdThe ID of the contract to return the bytecode forRequired
//Create the query
ContractByteCodeQuery query = new ContractByteCodeQuery()
    .setContractId(contractId);

//Sign with the client operator private key and submit to a Hedera network
ByteString bytecode = query.execute(client);

Get query values

MethodTypeDescriptionRequirements
getContractId(<contractId>)ContractIdGet the contract ID on the transactionRequired
//Create the query
ContractByteCodeQuery query = new ContractByteCodeQuery()
    .setContractId(newContractId);

//Get the contract ID
query.getContractId()

//v2.0.0