Hedera
Search…
Create a smart contract
Before you get started with smart contracts consider if the Hedera Token Service is better for your use case. For most, it provides greater performance and lowers costs. Learn more in the blog series, Getting Started with Hedera Token Service.
A transaction that creates a new contract instance. After the contract is created you can get the new contract ID by requesting the receipt of the transaction. To create the solidity smart contract, you can use remix or another solidity compiler. After you have the hex-encoded byte code of the smart contract you need to store that on a file using the Hedera File Service. Then you will create the smart contract instance that will run the byte code stored in the given Hedera file, referenced either by file ID. The constructor will be executed using the given amount of gas.
Solidity Support Hedera smart contracts support Solidity versions up to v0.5.9.
Smart Contract State Size and Gas Limit Each smart contract has a maximum state size of 1MB which can store up to approximately 16,000 key-value pairs. The maximum gas limit is 300_000.
Transaction Signing Requirements
    The client operator account is required to sign the transaction
    The admin key, if specified
Smart Contract Properties
Field
Description
Admin Key
Sets the state of the instance and its fields can be modified arbitrarily if this key signs a transaction to modify it. If this is null, then such modifications are not possible, and there is no administrator that can override the normal operation of this smart contract instance. Note that if it is created with no admin keys, then there is no administrator to authorize changing the admin keys, so there can never be any admin keys for that instance.
Gas
The gas to run the constructor.
Initial Balance
The initial number of hbars to put into the cryptocurrency account associated with and owned by the smart contract.
Byte Code File
The file containing the smart contract byte code.
Proxy Account
The ID of the account to which this account is proxy staked. If proxyAccountID is null, or is an invalid account, or is an account that isn't a node, then this account is automatically proxy staked to a node chosen by the network, but without earning payments. If the proxyAccountID account refuses to accept proxy staking, or if it is not currently running a node, then it will behave as if proxyAccountID was null.
Auto Renew Period
The period that the instance will charge its account every this many seconds to renew.
Constructor Parameters
The constructor parameters to pass.
Memo
The memo to be associated with this contract.
Constructor
Description
new ContractCreateTransaction()
Initializes the ContractCreateTransaction()
1
new ContractCreateTransaction()
Copied!

Methods

V2
V1
Method
Type
Requirement
setGas(<gas>)
long
Required
setBytecodeFileId(<fileId>)
FileId
Required
setInitialBalance(<initialBalance>)
Hbar
Optional
setAdminKey(<keys>)
Key
Optional
setProxyAccountId(<accountId>)
AccountId
Optional
setConstructorParameters(<constructorParameters>)
byte [ ]
Optional
setConstructorParameters(<constructorParameters>)
ContractFunctionParameters
Optional
setContractMemo(<memo>)
String
Optional
setAutoRenewPeriod(<autoRenewPeriod>)
Duration
Optional
Java
1
//Create the transaction
2
ContractCreateTransaction transaction = new ContractCreateTransaction()
3
.setGas(500)
4
.setBytecodeFileId(bytecodeFileId)
5
.setAdminKey(adminKey);
6
7
//Modify the default max transaction fee (1 hbar)
8
ContractCreateTransaction modifyTransactionFee = transaction.setMaxTransactionFee(new Hbar(16));
9
10
//Sign the transaction with the client operator key and submit to a Hedera network
11
TransactionResponse txResponse = modifyTransactionFee.execute(client);
12
13
//Get the receipt of the transaction
14
TransactionReceipt receipt = txResponse.getReceipt(client);
15
16
//Get the new contract ID
17
ContractId newContractId = receipt.contractId;
18
19
System.out.println("The new contract ID is " +newContractId);
20
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new ContractCreateTransaction()
3
.setGas(500)
4
.setBytecodeFileId(bytecodeFileId)
5
.setAdminKey(adminKey);
6
7
//Modify the default max transaction fee (1 hbar)
8
const modifyTransactionFee = transaction.setMaxTransactionFee(new Hbar(16));
9
10
//Sign the transaction with the client operator key and submit to a Hedera network
11
const txResponse = await modifyTransactionFee.execute(client);
12
13
//Get the receipt of the transaction
14
const receipt = await txResponse.getReceipt(client);
15
16
//Get the new contract ID
17
const newContractId = receipt.contractId;
18
19
console.log("The new contract ID is " +newContractId);
20
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewContractCreateTransaction().
3
SetGas(500).
4
SetBytecodeFileID(byteCodeFileID).
5
SetAdminKey(adminKey)
6
7
//Sign the transaction with the client operator key and submit to a Hedera network
8
txResponse, err := transaction.Execute(client)
9
if err != nil {
10
panic(err)
11
}
12
13
//Request the receipt of the transaction
14
receipt, err = txResponse.GetReceipt(client)
15
if err != nil {
16
panic(err)
17
}
18
19
//Get the topic ID
20
newContractId := *receipt.ContractID
21
22
fmt.Printf("The new topic ID is %v\n", newContractId)
23
//v2.0.0
Copied!
Method
Type
Requirement
setGas(<gas>)
long
Required
setBytecodeFileId(<fileId>)
FileId
Required
setInitialBalance(<initialBalance>)
long/Hbar
Optional
setAdminKey(<publicKeys>)
Ed25519PublicKey
Optional
setProxyAccountId(<accountId>)
AccountId
Optional
setConstructorParameters(<constructorParameters>)
byte [ ]
Optional
setConstructorParameters(<constructorParameters>)
ContractFunctionParameters
Optional
setContractMemo(<memo>)
String
Optional
setAutoRenewPeriod(<autoRenewPeriod>)
Duration
Optional
Java
1
//Create the transaction
2
ContractCreateTransaction transaction = new ContractCreateTransaction()
3
.setBytecodeFileId(fileId)
4
.setGas(100_000_000)
5
.setConstructorParams(new ContractFunctionParams().addString("hello from hedera!"));
6
7
//Sign with the client operator account private key, submit to a Hedera network
8
TransactionId txId = transaction.execute(client);
9
10
//Get the receipt of the transaction
11
TransactionReceipt receipt = txId.getReceipt(client);
12
13
//Get the new contract ID
14
ContractId newContractId = receipt.getContractId();
15
16
System.out.println("The new contract ID is " + newContractId);
17
18
//v1.3.2
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new ContractCreateTransaction()
3
.setBytecodeFileId(fileId)
4
.setGas(100_000_000)
5
.setConstructorParams(new ContractFunctionParams().addString("hello from hedera!"));
6
7
//Sign with the client operator account private key, submit to a Hedera network
8
const txId = await transaction.execute(client);
9
10
//Get the receipt of the transaction
11
const receipt = await txId.getReceipt(client);
12
13
//Get the new contract ID
14
const newContractId = receipt.getContractId();
15
16
System.out.println("The new contract ID is " + newContractId);
17
18
//v1.4.4
19
Copied!

Get transaction values

V2
Method
Type
Requirement
getAdminKey(<keys>)
Key
Optional
getGas(<gas>)
long
Optional
getInitialBalance(<initialBalance>)
Hbar
Optional
getBytecodeFileId(<fileId>)
FileId
Optional
getProxyAccountId(<accountId>)
AccountId
Optional
getConstructorParameters(<constructorParameters>)
ByteString
Optional
getContractMemo(<memo>)
String
Optional
getAutoRenewPeriod(<autoRenewPeriod>)
Duration
Optional
Java
1
//Create the transaction
2
ContractCreateTransaction transaction = new ContractCreateTransaction()
3
.setGas(500)
4
.setBytecodeFileId(bytecodeFileId)
5
.setAdminKey(adminKey);
6
7
//Get admin key
8
transaction.getAdminKey()
9
10
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = await new ContractCreateTransaction()
3
.setGas(500)
4
.setBytecodeFileId(bytecodeFileId)
5
.setAdminKey(adminKey);
6
7
//Get admin key
8
transaction.getAdminKey()
9
10
//v2.0.0
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewContractCreateTransaction().
3
SetGas(500).
4
SetBytecodeFileID(byteCodeFileID).
5
SetAdminKey(adminKey)
6
7
//Get admin key
8
transaction.GetAdminKey()
9
10
//v2.0.0
Copied!

Last modified 7d ago