Get smart contract bytecode

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.

Query Signing Requirements

  • The client operator account's private key (fee payer) is required to sign this query

Constructor

Description

new ContractByteCodeQuery()

Initializes a ContractByteCodeQuery object

new ContractByteCodeQuery()

Methods

V2
V1
V2

Method

Type

Description

Requirements

setContractId(<contractId>)

ContractId

The ID of the contract to return the bytecode for

Required

Java
//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
//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);
Go
//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)
}
V1

Method

Type

Description

Requirements

setContractId(<contractId>)

ContractId

The ID of the contract to return the bytecode for

Required

Java
ContractBytecodeQuery query = new ContractBytecodeQuery()
.setContractId(newContractId);
byte[] byteCode = query.execute(client);
JavaScript
const query = new ContractBytecodeQuery()
.setContractId(newContractId);
const byteCode = await query.execute(client);

Get query values

V2
V2

Method

Type

Description

Requirements

getContractId(<contractId>)

ContractId

Get the contract ID on the transaction

Required

Java
//Create the query
ContractByteCodeQuery query = new ContractByteCodeQuery()
.setContractId(newContractId);
//Get the contract ID
query.getContractId()
//v2.0.0
JavaScript
//Create the query
const query = new ContractByteCodeQuery()
.setContractId(newContractId);
//Get the contract ID
query.getContractId()
//v2.0.0
Go
//Create the query
query := hedera.NewContractByteCodeQuery().
SetContractID(contractId)
query.GetContractID()
//v2.0.0