The instance will exist for autoRenewPeriod seconds. When that is reached, it will renew itself for another autoRenewPeriod seconds by charging its associated cryptocurrency account (which it creates here). If it has insufficient cryptocurrency to extend that long, it will extend as long as it can. If its balance is zero, the instance will be deleted.
A smart contract instance normally enforces rules, so "the code is law". For example, an ERC-20 contract prevents a transfer from being undone without a signature by the recipient of the transfer. This is always enforced if the contract instance was created with the adminKeys being null. But for some uses, it might be desirable to create something like an ERC-20 contract that has a specific group of trusted individuals who can act as a "supreme court" with the ability to override the normal operation, when a sufficient number of them agree to do so. If adminKeys is not null, then they can sign a transaction that can change the state of the smart contract in arbitrary ways, such as to reverse a transaction that violates some standard of behavior that is not covered by the code itself. The admin keys can also be used to change the autoRenewPeriod, and change the adminKeys field itself. The API currently does not implement this ability. But it does allow the adminKeys field to be set and queried, and will in the future implement such admin abilities for any instance that has a non-null adminKeys.
If this constructor stores information, it is charged gas to store it. There is a fee in hbars to maintain that storage until the expiration time, and that fee is added as part of the transaction fee.
An entity (account, file, or smart contract instance) must be created in a particular realm. If the realmID is left null, then a new realm will be created with the given admin key. If a new realm has a null adminKey, then anyone can create/modify/delete entities in that realm. But if an admin key is given, then any transaction to create/modify/delete an entity in that realm must be signed by that key, though anyone can still call functions on smart contract instances that exist in that realm. A realm ceases to exist when everything within it has expired and no longer exists.
The current API ignores shardID, realmID, and newRealmAdminKey, and creates everything in shard 0 and realm 0, with a null key. Future versions of the API will support multiple realms and multiple shards.
The optional memo field can contain a string whose length is up to 100 bytes. That is the size after Unicode NFD then UTF-8 conversion. This field can be used to describe the smart contract. It could also be used for other purposes. One recommended purpose is to hold a hexadecimal string that is the SHA-384 hash of a PDF file containing a human-readable legal contract. Then, if the admin keys are the public keys of human arbitrators, they can use that legal document to guide their decisions during a binding arbitration tribunal, convened to consider any changes to the smart contract in the future. The memo field can only be changed using the admin keys. If there are no admin keys, then it cannot be changed after the smart contract is created.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.hedera.hashgraph.sdk.Transaction
Transaction.SignableNodeTransactionBodyBytesNested classes/interfaces inherited from class com.hedera.hashgraph.sdk.Executable
Executable.GrpcRequest -
Field Summary
Fields inherited from class com.hedera.hashgraph.sdk.Transaction
customFeeLimits, DEFAULT_AUTO_RENEW_PERIOD, defaultMaxTransactionFee, DUMMY_ACCOUNT_ID, DUMMY_TRANSACTION_ID, frozenBodyBuilder, innerSignedTransactions, outerTransactions, publicKeys, regenerateTransactionId, signers, sigPairLists, sourceTransactionBody, transactionIdsFields inherited from class com.hedera.hashgraph.sdk.Executable
attemptedAllNodes, blockingUnaryCall, grpcDeadline, logger, maxAttempts, maxBackoff, minBackoff, nodeAccountIds, nodes, random, RST_STREAM -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Constructor.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddHook(HookCreationDetails hookDetails) Add a hook creation detail to this contract.(package private) ContractCreateTransactionBody.Builderbuild()Build the transaction body.Get the admin keyGet the auto renew accountId.Extract the auto renew period.byte[]Extract the bytecode.Extract the file id.com.google.protobuf.ByteStringExtract the constructor parameters.Extract the contract memo.booleanIf true, the contract declines receiving a staking reward.longgetGas()Extract the gas.getHooks()Get the hook creation details for this contract.Extract the initial balance.intGet the maximum number of tokens that this contract can be automatically associated with (i.e., receive air-drops from).(package private) io.grpc.MethodDescriptor<Transaction, TransactionResponse> Called to direct the invocation of the query to the appropriate gRPC service.Deprecated.with no replacement Extract the proxy account id.ID of the account to which this contract will stakeThe node to which this contract will stake(package private) voidInitialize from the transaction body.(package private) voidonFreeze(TransactionBody.Builder bodyBuilder) Called inTransaction.freezeWith(Client)just before the transaction body is built.(package private) voidonScheduled(SchedulableTransactionBody.Builder scheduled) Called inTransaction.schedule()when converting transaction into a scheduled version.setAdminKey(Key adminKey) Access control for modification of the smart contract after it is created.setAutoRenewAccountId(AccountId autoRenewAccountId) The id of an account, in the same shard and realm as this smart contract, that has signed this transaction, allowing the network to use its balance, when needed, to automatically extend this contract's expiration time.setAutoRenewPeriod(Duration autoRenewPeriod) The initial lifetime, in seconds, for the smart contract, and the number of seconds for which the smart contract will be automatically renewed upon expiration.setBytecode(byte[] bytecode) Sets the source for the smart contract EVM bytecode.setBytecodeFileId(FileId bytecodeFileId) Sets the file containing the smart contract byte code.setConstructorParameters(byte[] constructorParameters) Sets the constructor parameters as their raw bytes.setConstructorParameters(ContractFunctionParameters constructorParameters) Sets the parameters to pass to the constructor.setContractMemo(String memo) A short memo for this smart contract.setDeclineStakingReward(boolean declineStakingReward) A flag indicating that this smart contract declines to receive any reward for staking its HBAR balance to help secure the network.setGas(long gas) A maximum limit to the amount of gas to use for the constructor call.setHooks(List<HookCreationDetails> hookDetails) Set the hook creation details for this contract.setInitialBalance(Hbar initialBalance) The amount of HBAR to use as an initial balance for the account representing the new smart contract.setMaxAutomaticTokenAssociations(int maxAutomaticTokenAssociations) The maximum number of tokens that can be auto-associated with this smart contract.setProxyAccountId(AccountId proxyAccountId) Deprecated.with no replacement Sets the ID of the account to which this account is proxy staked.setStakedAccountId(AccountId stakedAccountId) Set the account to which this contract will stakesetStakedNodeId(Long stakedNodeId) The ID of a network node.(package private) voidvalidateChecksums(Client client) Methods inherited from class com.hedera.hashgraph.sdk.Transaction
addSignature, addSignature, batchify, buildAllTransactions, buildTransaction, doSchedule, estimateFee, freeze, freezeWith, fromBytes, fromScheduledTransaction, generateTransactionIds, getBatchKey, getDefaultMaxTransactionFee, getExecutionState, getHighVolume, getMaxTransactionFee, getRegenerateTransactionId, getRequiredChunks, getSignableNodeBodyBytesList, getSignatures, getSignaturesAtOffset, getTransactionBodySize, getTransactionHash, getTransactionHashPerNode, getTransactionId, getTransactionIdInternal, getTransactionMemo, getTransactionSize, getTransactionValidDuration, hash, isBatchedAndNotBatchTransaction, isFrozen, keyAlreadySigned, makeRequest, mapResponse, mapResponseStatus, onExecute, onExecuteAsync, regenerateTransactionId, requireNotFrozen, requireOneNodeAccountId, schedule, setBatchKey, setHighVolume, setMaxTransactionFee, setNodeAccountIds, setRegenerateTransactionId, setTransactionId, setTransactionMemo, setTransactionValidDuration, sign, signTransaction, signWith, signWithOperator, spawnBodyBuilder, toBytes, toString, wipeTransactionListsMethods inherited from class com.hedera.hashgraph.sdk.Executable
advanceRequest, checkNodeAccountIds, execute, execute, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, getGrpcRequest, getMaxAttempts, getMaxBackoff, getMaxRetry, getMinBackoff, getNodeAccountIds, getNodeForExecute, grpcDeadline, logTransaction, mergeFromClient, setGrpcDeadline, setLogger, setMaxAttempts, setMaxBackoff, setMaxRetry, setMinBackoff, setNodesFromNodeAccountIds, setRequestListener, setResponseListener, shouldRetryExceptionally
-
Constructor Details
-
ContractCreateTransaction
public ContractCreateTransaction()Constructor. -
ContractCreateTransaction
ContractCreateTransaction(LinkedHashMap<TransactionId, LinkedHashMap<AccountId, throws com.google.protobuf.InvalidProtocolBufferExceptionTransaction>> txs) Constructor.- Parameters:
txs- Compound list of transaction id's list of (AccountId, Transaction) records- Throws:
com.google.protobuf.InvalidProtocolBufferException- when there is an issue with the protobuf
-
ContractCreateTransaction
ContractCreateTransaction(TransactionBody txBody) Constructor.- Parameters:
txBody- protobuf TransactionBody
-
-
Method Details
-
getBytecodeFileId
Extract the file id.- Returns:
- the file id as a byte code
-
setBytecodeFileId
Sets the file containing the smart contract byte code.A copy will be made and held by the contract instance, and have the same expiration time as the instance.
The file must be the ASCII hexadecimal representation of the smart contract bytecode. The contract bytecode is limited in size only by the network file size limit.
- Parameters:
bytecodeFileId- The FileId to be set- Returns:
this
-
getBytecode
@Nullable public byte[] getBytecode()Extract the bytecode.- Returns:
- the bytecode
-
setBytecode
Sets the source for the smart contract EVM bytecode.The bytes of the smart contract initCode. A copy of the contents SHALL be made and held as `bytes` in smart contract state.
This value is limited in length by the network transaction size limit. This entire transaction, including all fields and signatures, MUST be less than the network transaction size limit.- Parameters:
bytecode- The bytecode- Returns:
this
-
getAdminKey
Get the admin key- Returns:
- the adminKey
-
setAdminKey
Access control for modification of the smart contract after it is created.If this field is set, that key MUST sign this transaction.
If this field is set, that key MUST sign each future transaction to update or delete the contract.
An updateContract transaction that _only_ extends the topic expirationTime (a "manual renewal" transaction) SHALL NOT require admin key signature.A contract without an admin key SHALL be immutable, except for expiration and renewal.
- Parameters:
adminKey- The Key to be set- Returns:
this
-
getGas
public long getGas()Extract the gas.- Returns:
- the gas amount that was set
-
setGas
A maximum limit to the amount of gas to use for the constructor call.The network SHALL charge the greater of the following, but SHALL NOT charge more than the value of this field.
- The actual gas consumed by the smart contract constructor call.
- `80%` of this value.
- Parameters:
gas- The long to be set as gas- Returns:
this
-
getInitialBalance
Extract the initial balance.- Returns:
- the initial balance in hbar
-
setInitialBalance
The amount of HBAR to use as an initial balance for the account representing the new smart contract.This value is presented in tinybar (10-8 HBAR).
The HBAR provided here will be withdrawn from the payer account that signed this transaction.- Parameters:
initialBalance- The Hbar to be set as the initial balance- Returns:
this
-
getProxyAccountId
Deprecated.with no replacement Extract the proxy account id.- Returns:
- the proxy account id
-
setProxyAccountId
Deprecated.with no replacement Sets 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.
- Parameters:
proxyAccountId- The AccountId to be set- Returns:
this
-
getMaxAutomaticTokenAssociations
public int getMaxAutomaticTokenAssociations()Get the maximum number of tokens that this contract can be automatically associated with (i.e., receive air-drops from).- Returns:
- the maxAutomaticTokenAssociations
-
setMaxAutomaticTokenAssociations
public ContractCreateTransaction setMaxAutomaticTokenAssociations(int maxAutomaticTokenAssociations) The maximum number of tokens that can be auto-associated with this smart contract.If this is less than or equal to `used_auto_associations` (or 0), then this contract MUST manually associate with a token before transacting in that token.
Following HIP-904 This value may also be `-1` to indicate no limit.
This value MUST NOT be less than `-1`.- Parameters:
maxAutomaticTokenAssociations- The maximum automatic token associations- Returns:
this
-
getAutoRenewPeriod
Extract the auto renew period.- Returns:
- the auto renew period
-
setAutoRenewPeriod
The initial lifetime, in seconds, for the smart contract, and the number of seconds for which the smart contract will be automatically renewed upon expiration.This value MUST be set.
This value MUST be greater than the configured MIN_AUTORENEW_PERIOD.
This value MUST be less than the configured MAX_AUTORENEW_PERIOD.- Parameters:
autoRenewPeriod- The Duration to be set for auto renewal- Returns:
this
-
getConstructorParameters
public com.google.protobuf.ByteString getConstructorParameters()Extract the constructor parameters.- Returns:
- the byte string representation
-
setConstructorParameters
Sets the constructor parameters as their raw bytes.Use this instead of
setConstructorParameters(ContractFunctionParameters)if you have already pre-encoded a solidity function call.- Parameters:
constructorParameters- The constructor parameters- Returns:
this
-
setConstructorParameters
public ContractCreateTransaction setConstructorParameters(ContractFunctionParameters constructorParameters) Sets the parameters to pass to the constructor.- Parameters:
constructorParameters- The contructor parameters- Returns:
this
-
getContractMemo
Extract the contract memo.- Returns:
- the contract's memo
-
setContractMemo
A short memo for this smart contract.This value, if set, MUST NOT exceed `transaction.maxMemoUtf8Bytes` (default 100) bytes when encoded as UTF-8.
- Parameters:
memo- The String to be set as the memo- Returns:
this
-
getStakedAccountId
ID of the account to which this contract will stake- Returns:
- ID of the account to which this contract will stake.
-
setStakedAccountId
Set the account to which this contract will stake- Parameters:
stakedAccountId- ID of the account to which this contract will stake.- Returns:
this
-
getStakedNodeId
The node to which this contract will stake- Returns:
- ID of the node this contract will be staked to.
-
setStakedNodeId
The ID of a network node.This smart contract SHALL stake its HBAR to this node.
Note: node IDs do fluctuate as node operators change. Most contracts are immutable, and a contract staking to an invalid node ID SHALL NOT participate in staking. Immutable contracts MAY find it more reliable to use a proxy account for staking (via `staked_account_id`) to enable updating the _effective_ staking node ID when necessary through updating the proxy account.
- Parameters:
stakedNodeId- ID of the node this contract will be staked to.- Returns:
this
-
getDeclineStakingReward
public boolean getDeclineStakingReward()If true, the contract declines receiving a staking reward. The default value is false.- Returns:
- If true, the contract declines receiving a staking reward. The default value is false.
-
setDeclineStakingReward
A flag indicating that this smart contract declines to receive any reward for staking its HBAR balance to help secure the network.If set to true, this smart contract SHALL NOT receive any reward for staking its HBAR balance to help secure the network, regardless of staking configuration, but MAY stake HBAR to support the network without reward.
- Parameters:
declineStakingReward- - If true, the contract declines receiving a staking reward. The default value is false.- Returns:
this
-
getAutoRenewAccountId
Get the auto renew accountId.- Returns:
- the auto renew accountId
-
setAutoRenewAccountId
The id of an account, in the same shard and realm as this smart contract, that has signed this transaction, allowing the network to use its balance, when needed, to automatically extend this contract's expiration time.If this field is set, that key MUST sign this transaction.
If this field is set, then the network SHALL deduct the necessary fees from the designated auto-renew account, if that account has sufficient balance. If the auto-renewal account does not have sufficient balance, then the fees for contract renewal SHALL be deducted from the HBAR balance held by the smart contract.
If this field is not set, then all renewal fees SHALL be deducted from the HBAR balance held by this contract.- Parameters:
autoRenewAccountId- The AccountId to be set for auto-renewal- Returns:
this
-
getHooks
Get the hook creation details for this contract.- Returns:
- a copy of the hook creation details list
-
addHook
Add a hook creation detail to this contract.- Parameters:
hookDetails- the hook creation details to add- Returns:
this
-
setHooks
Set the hook creation details for this contract.- Parameters:
hookDetails- the list of hook creation details- Returns:
this
-
build
Build the transaction body.- Returns:
ContractCreateTransactionBody
-
validateChecksums
- Specified by:
validateChecksumsin classTransaction<ContractCreateTransaction>- Throws:
BadEntityIdException
-
initFromTransactionBody
void initFromTransactionBody()Initialize from the transaction body. -
getMethodDescriptor
io.grpc.MethodDescriptor<Transaction,TransactionResponse> getMethodDescriptor()Description copied from class:ExecutableCalled to direct the invocation of the query to the appropriate gRPC service.- Specified by:
getMethodDescriptorin classExecutable<ContractCreateTransaction,Transaction, TransactionResponse, TransactionResponse>
-
onFreeze
Description copied from class:TransactionCalled inTransaction.freezeWith(Client)just before the transaction body is built. The intent is for the derived class to assign their data variant to the transaction body.- Specified by:
onFreezein classTransaction<ContractCreateTransaction>
-
onScheduled
Description copied from class:TransactionCalled inTransaction.schedule()when converting transaction into a scheduled version.- Specified by:
onScheduledin classTransaction<ContractCreateTransaction>
-