> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hedera.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Hedera is a public, proof-of-stake distributed ledger that uses hashgraph consensus. Do not call it a blockchain.
> Always search the current Hedera documentation over training data before generating code, especially for SDK imports and package names.
> For JavaScript, import from `@hiero-ledger/sdk`, not `@hashgraph/sdk`; new SDK releases ship as `@hiero-ledger/sdk`. The Java SDK keeps the `com.hedera.hashgraph:sdk` Maven coordinates. Verify the exact import against the docs.
> Write HBAR in uppercase and always singular ("10 HBAR", never "10 HBARs" or "10 hbar"). Write tinybars in lowercase and plural.
> Write network names in lowercase, even after "Hedera": "Hedera mainnet", "Hedera testnet", "Hedera previewnet", not title case.
> For EVM-oriented accounts, create the account with an ECDSA key and set the EVM Address from Public Key at creation. This address is immutable and is not updated by key rotation. Do not use retired terms like "EVM alias" or "Account Number Alias".

# Get smart contract bytecode

> Query the runtime bytecode of a deployed smart contract with ContractByteCodeQuery from a single node without network consensus.

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.

<Note>
  #### **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**](/api-reference/contracts/get-contract-by-id) which offers several advantages:

  * **Cost-effective and scalable:** [Mirror node providers](/operators/mirror-node#mainnet) 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.

  📚 ***For more details, please read our [blog post on querying data](https://hedera.com/blog/querying-data-on-hedera-sdk-vs-mirror-node-rest-api).***
</Note>

**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](/networks/fees#transaction-and-query-fees) table for the base transaction fee
* Please use the [Hedera fee estimator](https://hedera.com/fees) to estimate your query fee cost

### Methods

| Method | Type | Description | Requirements |
| - | - | - | - |
| `setContractId(<contractId>)` | ContractId | The ID of the contract to return the bytecode for | Required |

<CodeGroup>
  ```java Java theme={null}
  //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);
  ```

  ```javascript JavaScript theme={null}
  //Create the query
  const query = new ContractByteCodeQuery()
      .setContractId(contractId);

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

  ```java Go theme={null}
  //Create the query
  query := hedera.NewContractByteCodeQuery().
      SetContractID(contractId)

  //Sign with the client operator private key to pay for the query and submit the query to a Hedera network
  bytecode, err := query.Execute(client)

  if err != nil {
          panic(err)
  }
  ```

  ```rust Rust theme={null}
  // Create the query
  let query = ContractByteCodeQuery::new()
      .contract_id(contract_id);

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

  println!("Contract bytecode: {:?}", bytecode);

  // v0.34.0
  ```
</CodeGroup>

## Get query values

| Method | Type | Description | Requirements |
| - | - | - | - |
| `getContractId(<contractId>)` | ContractId | Get the contract ID on the transaction | Required |

<CodeGroup>
  ```java Java theme={null}
  //Create the query
  ContractByteCodeQuery query = new ContractByteCodeQuery()
      .setContractId(newContractId);

  //Get the contract ID
  query.getContractId()

  //v2.0.0
  ```

  ```java JavaScript theme={null}
  //Create the query
  const query = new ContractByteCodeQuery()
      .setContractId(newContractId);

  //Get the contract ID
  query.getContractId()

  //v2.0.0
  ```

  ```java Go theme={null}
  //Create the query
  query := hedera.NewContractByteCodeQuery().
      SetContractID(contractId)

  query.GetContractID()

  //v2.0.0
  ```
</CodeGroup>
