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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) TransactionReceiptQueryCreate a new transaction receipt query.Execute the transactions in the flow with the passed in client.Execute the transactions in the flow with the passed in client.executeAsync(Client client) Execute the transactions in the flow with the passed in client asynchronously.executeAsync(Client client, Duration timeoutPerTransaction) Execute the transactions in the flow with the passed in client asynchronously.voidexecuteAsync(Client client, Duration timeoutPerTransaction, BiConsumer<TransactionResponse, Throwable> callback) Execute the transactions in the flow with the passed in client asynchronously.voidexecuteAsync(Client client, Duration timeoutPerTransaction, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure) Execute the transactions in the flow with the passed in client asynchronously.voidexecuteAsync(Client client, BiConsumer<TransactionResponse, Throwable> callback) Execute the transactions in the flow with the passed in client asynchronously.voidexecuteAsync(Client client, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure) Execute the transactions in the flow with the passed in client asynchronously.freezeWith(Client client) Set the client that this transaction will be frozen with.Extract the admin key.Get the account ID which will be charged for renewing this accountExtract the auto renew period.Extract the hex-encoded bytecode of the contract.com.google.protobuf.ByteStringExtract the byte string representation.Extract the contract memo.booleanIf true, the contract declines receiving a staking reward.longgetGas()Extract the gas.Extract the initial balance in hbar.intThe maximum number of tokens that an Account can be implicitly associated with.Get the maximum number of chunksExtract the list of node account id's.Deprecated.with no replacementID of the account to which this contract will stakeThe node to which this contract will stakesetAdminKey(Key adminKey) Sets the state of the instance and its fields can be modified arbitrarily if this key signs a transaction to modify it.setAutoRenewAccountId(AccountId autoRenewAccountId) Set the account ID which will be charged for renewing this accountsetAutoRenewPeriod(Duration autoRenewPeriod) Sets the period that the instance will charge its account every this many seconds to renew.setBytecode(byte[] bytecode) Sets the bytecode of the contract in raw bytes.setBytecode(com.google.protobuf.ByteString bytecode) Sets the bytecode of the contract in raw bytes.setBytecode(String bytecode) Sets the bytecode of the contract in hex.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) Sets the memo to be associated with this contract.setDeclineStakingReward(boolean declineStakingReward) If true, the contract declines receiving a staking reward.setGas(long gas) Sets the gas to run the constructor.setInitialBalance(Hbar initialBalance) Sets the initial number of hbars to put into the cryptocurrency account associated with and owned by the smart contract.setMaxAutomaticTokenAssociations(int maxAutomaticTokenAssociations) The maximum number of tokens that an Account can be implicitly associated with.setMaxChunks(int maxChunks) Set the maximal number of chunkssetNodeAccountIds(List<AccountId> nodeAccountIds) Set the account IDs of the nodes that this transaction will be submitted to.setProxyAccountId(AccountId proxyAccountId) Deprecated.with no replacementsetStakedAccountId(AccountId stakedAccountId) Set the account to which this contract will stakesetStakedNodeId(Long stakedNodeId) Set the node to which this contract will stakesign(PrivateKey privateKey) Set the private key that this transaction will be signed with.signWith(PublicKey publicKey, UnaryOperator<byte[]> transactionSigner) Set the public key and key list that this transaction will be signed with.signWithOperator(Client client) Set the operator that this transaction will be signed with.
-
Field Details
-
FILE_CREATE_MAX_BYTES
static final int FILE_CREATE_MAX_BYTES- See Also:
-
-
Constructor Details
-
ContractCreateFlow
public ContractCreateFlow()Constructor
-
-
Method Details
-
getBytecode
Extract the hex-encoded bytecode of the contract.- Returns:
- the hex-encoded bytecode of the contract.
-
setBytecode
Sets the bytecode of the contract in hex.- Parameters:
bytecode- the string to assign- Returns:
this
-
setBytecode
Sets the bytecode of the contract in raw bytes.- Parameters:
bytecode- the byte array- Returns:
this
-
setBytecode
Sets the bytecode of the contract in raw bytes.- Parameters:
bytecode- the byte string- Returns:
- the contract in raw bytes
-
getMaxChunks
Get the maximum number of chunks- Returns:
- the maxChunks
-
setMaxChunks
Set the maximal number of chunks- Parameters:
maxChunks- the maximum number of chunks- Returns:
this
-
getAdminKey
Extract the admin key.- Returns:
- the admin key
-
setAdminKey
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.- Parameters:
adminKey- The Key to be set- Returns:
this
-
getGas
public long getGas()Extract the gas.- Returns:
- the gas
-
setGas
Sets the gas to run the constructor.- Parameters:
gas- The long to be set as gas- Returns:
this
-
getInitialBalance
Extract the initial balance in hbar.- Returns:
- the initial balance in hbar
-
setInitialBalance
Sets the initial number of hbars to put into the cryptocurrency account associated with and owned by the smart contract.- Parameters:
initialBalance- The Hbar to be set as the initial balance- Returns:
this
-
getProxyAccountId
Deprecated.with no replacementExtract the proxy account id.
- Returns:
- the proxy account id
-
setProxyAccountId
Deprecated.with no replacementSets 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()The maximum number of tokens that an Account can be implicitly associated with. Defaults to 0 and up to a maximum value of 1000.- Returns:
- The maxAutomaticTokenAssociations.
-
setMaxAutomaticTokenAssociations
The maximum number of tokens that an Account can be implicitly associated with. Defaults to 0 and up to a maximum value of 1000.- Parameters:
maxAutomaticTokenAssociations- The maxAutomaticTokenAssociations to set- Returns:
this
-
getAutoRenewPeriod
Extract the auto renew period.- Returns:
- the auto renew period
-
setAutoRenewPeriod
Sets the period that the instance will charge its account every this many seconds to renew.- Parameters:
autoRenewPeriod- The Duration to be set for auto renewal- Returns:
this
-
getAutoRenewAccountId
Get the account ID which will be charged for renewing this account- Returns:
- the auto-renewal account id
-
setAutoRenewAccountId
Set the account ID which will be charged for renewing this account- Parameters:
autoRenewAccountId- the autoRenewAccountId to set- Returns:
this
-
getConstructorParameters
public com.google.protobuf.ByteString getConstructorParameters()Extract the byte string representation.- 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 ContractCreateFlow 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 memo
-
setContractMemo
Sets the memo to be associated with this contract.- 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
Set the node to which this contract will stake- 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
If true, the contract declines receiving a staking reward. The default value is false.- Parameters:
declineStakingReward- - If true, the contract declines receiving a staking reward. The default value is false.- Returns:
this
-
getNodeAccountIds
Extract the list of node account id's.- Returns:
- the list of node account id's
-
setNodeAccountIds
Set the account IDs of the nodes that this transaction will be submitted to.Providing an explicit node account ID interferes with client-side load balancing of the network. By default, the SDK will pre-generate a transaction for 1/3 of the nodes on the network. If a node is down, busy, or otherwise reports a fatal error, the SDK will try again with a different node.
- Parameters:
nodeAccountIds- The list of node AccountIds to be set- Returns:
this
-
freezeWith
Set the client that this transaction will be frozen with.- Parameters:
client- the client with the transaction to execute- Returns:
this
-
sign
Set the private key that this transaction will be signed with.- Parameters:
privateKey- the private key used for signing- Returns:
this
-
signWith
Set the public key and key list that this transaction will be signed with.- Parameters:
publicKey- the public keytransactionSigner- the key list- Returns:
this
-
signWithOperator
Set the operator that this transaction will be signed with.- Parameters:
client- the client with the transaction to execute- Returns:
this
-
createTransactionReceiptQuery
Create a new transaction receipt query.- Parameters:
response- the transaction response- Returns:
- the receipt query
-
execute
Execute the transactions in the flow with the passed in client.- Parameters:
client- the client with the transaction to execute- Returns:
- the response
- Throws:
PrecheckStatusException- when the precheck failsTimeoutException- when the transaction times out
-
execute
public TransactionResponse execute(Client client, Duration timeoutPerTransaction) throws PrecheckStatusException, TimeoutException Execute the transactions in the flow with the passed in client.- Parameters:
client- the client with the transaction to executetimeoutPerTransaction- The timeout after which each transaction's execution attempt will be cancelled.- Returns:
- the response
- Throws:
PrecheckStatusException- when the precheck failsTimeoutException- when the transaction times out
-
executeAsync
Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to execute- Returns:
- the response
-
executeAsync
public CompletableFuture<TransactionResponse> executeAsync(Client client, Duration timeoutPerTransaction) Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to executetimeoutPerTransaction- The timeout after which each transaction's execution attempt will be cancelled.- Returns:
- the response
-
executeAsync
Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to executecallback- a BiConsumer which handles the result or error.
-
executeAsync
public void executeAsync(Client client, Duration timeoutPerTransaction, BiConsumer<TransactionResponse, Throwable> callback) Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to executetimeoutPerTransaction- The timeout after which each transaction's execution attempt will be cancelled.callback- a BiConsumer which handles the result or error.
-
executeAsync
public void executeAsync(Client client, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure) Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to executeonSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-
executeAsync
public void executeAsync(Client client, Duration timeoutPerTransaction, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure) Execute the transactions in the flow with the passed in client asynchronously.- Parameters:
client- the client with the transaction to executetimeoutPerTransaction- The timeout after which each transaction's execution attempt will be cancelled.onSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-