github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_create_transaction.go (about)

     1  package hedera
     2  
     3  /*-
     4   *
     5   * Hedera Go SDK
     6   *
     7   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
     8   *
     9   * Licensed under the Apache License, Version 2.0 (the "License");
    10   * you may not use this file except in compliance with the License.
    11   * You may obtain a copy of the License at
    12   *
    13   *      http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   *
    21   */
    22  
    23  import (
    24  	"time"
    25  
    26  	"github.com/hashgraph/hedera-protobufs-go/services"
    27  )
    28  
    29  // TokenCreateTransaction
    30  // Create a new token. After the token is created, the Token ID for it is in the receipt.
    31  // The specified Treasury Account is receiving the initial supply of tokens as-well as the tokens
    32  // from the Token Mint operation once executed. The balance of the treasury account is decreased
    33  // when the Token Burn operation is executed.
    34  //
    35  // The initialSupply is the initial supply of the smallest parts of a token (like a
    36  // tinybar, not an hbar). These are the smallest units of the token which may be transferred.
    37  //
    38  // The supply can change over time. If the total supply at some moment is S parts of tokens,
    39  // and the token is using D decimals, then S must be less than or equal to
    40  // 2<sup>63</sup>-1, which is 9,223,372,036,854,775,807. The number of whole tokens (not parts) will
    41  // be S / 10<sup>D</sup>.
    42  //
    43  // If decimals is 8 or 11, then the number of whole tokens can be at most a few billions or
    44  // millions, respectively. For example, it could match Bitcoin (21 million whole tokens with 8
    45  // decimals) or hbars (50 billion whole tokens with 8 decimals). It could even match Bitcoin with
    46  // milli-satoshis (21 million whole tokens with 11 decimals).
    47  //
    48  // Note that a created token is immutable if the adminKey is omitted. No property of
    49  // an immutable token can ever change, with the sole exception of its expiry. Anyone can pay to
    50  // extend the expiry time of an immutable token.
    51  //
    52  // A token can be either FUNGIBLE_COMMON or NON_FUNGIBLE_UNIQUE, based on its
    53  // TokenType. If it has been omitted, FUNGIBLE_COMMON type is used.
    54  //
    55  // A token can have either INFINITE or FINITE supply type, based on its
    56  // TokenType. If it has been omitted, INFINITE type is used.
    57  //
    58  // If a FUNGIBLE TokenType is used, initialSupply should explicitly be set to a
    59  // non-negative. If not, the transaction will resolve to INVALID_TOKEN_INITIAL_SUPPLY.
    60  //
    61  // If a NON_FUNGIBLE_UNIQUE TokenType is used, initialSupply should explicitly be set
    62  // to 0. If not, the transaction will resolve to INVALID_TOKEN_INITIAL_SUPPLY.
    63  //
    64  // If an INFINITE TokenSupplyType is used, maxSupply should explicitly be set to 0. If
    65  // it is not 0, the transaction will resolve to INVALID_TOKEN_MAX_SUPPLY.
    66  //
    67  // If a FINITE TokenSupplyType is used, maxSupply should be explicitly set to a
    68  // non-negative value. If it is not, the transaction will resolve to INVALID_TOKEN_MAX_SUPPLY.
    69  type TokenCreateTransaction struct {
    70  	Transaction
    71  	treasuryAccountID  *AccountID
    72  	autoRenewAccountID *AccountID
    73  	customFees         []Fee
    74  	tokenName          string
    75  	memo               string
    76  	tokenSymbol        string
    77  	decimals           uint32
    78  	tokenSupplyType    TokenSupplyType
    79  	tokenType          TokenType
    80  	maxSupply          int64
    81  	metadata           []byte
    82  	adminKey           Key
    83  	kycKey             Key
    84  	freezeKey          Key
    85  	wipeKey            Key
    86  	scheduleKey        Key
    87  	supplyKey          Key
    88  	pauseKey           Key
    89  	metadataKey        Key
    90  	initialSupply      uint64
    91  	freezeDefault      *bool
    92  	expirationTime     *time.Time
    93  	autoRenewPeriod    *time.Duration
    94  }
    95  
    96  // NewTokenCreateTransaction creates TokenCreateTransaction which creates a new token.
    97  // After the token is created, the Token ID for it is in the receipt.
    98  // The specified Treasury Account is receiving the initial supply of tokens as-well as the tokens
    99  // from the Token Mint operation once executed. The balance of the treasury account is decreased
   100  // when the Token Burn operation is executed.
   101  //
   102  // The initialSupply is the initial supply of the smallest parts of a token (like a
   103  // tinybar, not an hbar). These are the smallest units of the token which may be transferred.
   104  //
   105  // The supply can change over time. If the total supply at some moment is S parts of tokens,
   106  // and the token is using D decimals, then S must be less than or equal to
   107  // 2<sup>63</sup>-1, which is 9,223,372,036,854,775,807. The number of whole tokens (not parts) will
   108  // be S / 10<sup>D</sup>.
   109  //
   110  // If decimals is 8 or 11, then the number of whole tokens can be at most a few billions or
   111  // millions, respectively. For example, it could match Bitcoin (21 million whole tokens with 8
   112  // decimals) or hbars (50 billion whole tokens with 8 decimals). It could even match Bitcoin with
   113  // milli-satoshis (21 million whole tokens with 11 decimals).
   114  //
   115  // Note that a created token is immutable if the adminKey is omitted. No property of
   116  // an immutable token can ever change, with the sole exception of its expiry. Anyone can pay to
   117  // extend the expiry time of an immutable token.
   118  //
   119  // A token can be either FUNGIBLE_COMMON or NON_FUNGIBLE_UNIQUE, based on its
   120  // TokenType. If it has been omitted, FUNGIBLE_COMMON type is used.
   121  //
   122  // A token can have either INFINITE or FINITE supply type, based on its
   123  // TokenType. If it has been omitted, INFINITE type is used.
   124  //
   125  // If a FUNGIBLE TokenType is used, initialSupply should explicitly be set to a
   126  // non-negative. If not, the transaction will resolve to INVALID_TOKEN_INITIAL_SUPPLY.
   127  //
   128  // If a NON_FUNGIBLE_UNIQUE TokenType is used, initialSupply should explicitly be set
   129  // to 0. If not, the transaction will resolve to INVALID_TOKEN_INITIAL_SUPPLY.
   130  //
   131  // If an INFINITE TokenSupplyType is used, maxSupply should explicitly be set to 0. If
   132  // it is not 0, the transaction will resolve to INVALID_TOKEN_MAX_SUPPLY.
   133  //
   134  // If a FINITE TokenSupplyType is used, maxSupply should be explicitly set to a
   135  // non-negative value. If it is not, the transaction will resolve to INVALID_TOKEN_MAX_SUPPLY.
   136  func NewTokenCreateTransaction() *TokenCreateTransaction {
   137  	tx := TokenCreateTransaction{
   138  		Transaction: _NewTransaction(),
   139  	}
   140  
   141  	tx.SetAutoRenewPeriod(7890000 * time.Second)
   142  	tx._SetDefaultMaxTransactionFee(NewHbar(40))
   143  	tx.SetTokenType(TokenTypeFungibleCommon)
   144  
   145  	return &tx
   146  }
   147  
   148  func _TokenCreateTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *TokenCreateTransaction {
   149  	customFees := make([]Fee, 0)
   150  
   151  	for _, fee := range pb.GetTokenCreation().GetCustomFees() {
   152  		customFees = append(customFees, _CustomFeeFromProtobuf(fee))
   153  	}
   154  	adminKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetAdminKey())
   155  	kycKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetKycKey())
   156  	freezeKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetFreezeKey())
   157  	wipeKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetWipeKey())
   158  	scheduleKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetFeeScheduleKey())
   159  	supplyKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetSupplyKey())
   160  	pauseKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetPauseKey())
   161  	metadataKey, _ := _KeyFromProtobuf(pb.GetTokenCreation().GetMetadataKey())
   162  
   163  	freezeDefault := pb.GetTokenCreation().GetFreezeDefault()
   164  
   165  	expirationTime := _TimeFromProtobuf(pb.GetTokenCreation().GetExpiry())
   166  	autoRenew := _DurationFromProtobuf(pb.GetTokenCreation().GetAutoRenewPeriod())
   167  
   168  	return &TokenCreateTransaction{
   169  		Transaction:        tx,
   170  		treasuryAccountID:  _AccountIDFromProtobuf(pb.GetTokenCreation().GetTreasury()),
   171  		autoRenewAccountID: _AccountIDFromProtobuf(pb.GetTokenCreation().GetAutoRenewAccount()),
   172  		customFees:         customFees,
   173  		tokenName:          pb.GetTokenCreation().GetName(),
   174  		memo:               pb.GetTokenCreation().GetMemo(),
   175  		tokenSymbol:        pb.GetTokenCreation().GetSymbol(),
   176  		decimals:           pb.GetTokenCreation().GetDecimals(),
   177  		tokenSupplyType:    TokenSupplyType(pb.GetTokenCreation().GetSupplyType()),
   178  		tokenType:          TokenType(pb.GetTokenCreation().GetTokenType()),
   179  		maxSupply:          pb.GetTokenCreation().GetMaxSupply(),
   180  		metadata:           pb.GetTokenCreation().GetMetadata(),
   181  		adminKey:           adminKey,
   182  		kycKey:             kycKey,
   183  		freezeKey:          freezeKey,
   184  		wipeKey:            wipeKey,
   185  		scheduleKey:        scheduleKey,
   186  		supplyKey:          supplyKey,
   187  		pauseKey:           pauseKey,
   188  		metadataKey:        metadataKey,
   189  		initialSupply:      pb.GetTokenCreation().InitialSupply,
   190  		freezeDefault:      &freezeDefault,
   191  		expirationTime:     &expirationTime,
   192  		autoRenewPeriod:    &autoRenew,
   193  	}
   194  }
   195  
   196  // SetTokenName Sets the publicly visible name of the token, specified as a string of only ASCII characters
   197  func (tx *TokenCreateTransaction) SetTokenName(name string) *TokenCreateTransaction {
   198  	tx._RequireNotFrozen()
   199  	tx.tokenName = name
   200  	return tx
   201  }
   202  
   203  // GetTokenName returns the token name
   204  func (tx *TokenCreateTransaction) GetTokenName() string {
   205  	return tx.tokenName
   206  }
   207  
   208  // SetTokenSymbol Sets the publicly visible token symbol. It is UTF-8 capitalized alphabetical string identifying the token
   209  func (tx *TokenCreateTransaction) SetTokenSymbol(symbol string) *TokenCreateTransaction {
   210  	tx._RequireNotFrozen()
   211  	tx.tokenSymbol = symbol
   212  	return tx
   213  }
   214  
   215  // SetTokenMemo Sets the publicly visible token memo. It is max 100 bytes.
   216  func (tx *TokenCreateTransaction) SetTokenMemo(memo string) *TokenCreateTransaction {
   217  	tx._RequireNotFrozen()
   218  	tx.memo = memo
   219  	return tx
   220  }
   221  
   222  // GetTokenMemo returns the token memo
   223  func (tx *TokenCreateTransaction) GetTokenMemo() string {
   224  	return tx.memo
   225  }
   226  
   227  // GetTokenSymbol returns the token symbol
   228  func (tx *TokenCreateTransaction) GetTokenSymbol() string {
   229  	return tx.tokenSymbol
   230  }
   231  
   232  // SetDecimals Sets the number of decimal places a token is divisible by. This field can never be changed!
   233  func (tx *TokenCreateTransaction) SetDecimals(decimals uint) *TokenCreateTransaction {
   234  	tx._RequireNotFrozen()
   235  	tx.decimals = uint32(decimals)
   236  	return tx
   237  }
   238  
   239  // GetDecimals returns the number of decimal places a token is divisible by
   240  func (tx *TokenCreateTransaction) GetDecimals() uint {
   241  	return uint(tx.decimals)
   242  }
   243  
   244  // SetTokenType Specifies the token type. Defaults to FUNGIBLE_COMMON
   245  func (tx *TokenCreateTransaction) SetTokenType(t TokenType) *TokenCreateTransaction {
   246  	tx._RequireNotFrozen()
   247  	tx.tokenType = t
   248  	return tx
   249  }
   250  
   251  // GetTokenType returns the token type
   252  func (tx *TokenCreateTransaction) GetTokenType() TokenType {
   253  	return tx.tokenType
   254  }
   255  
   256  // SetSupplyType Specifies the token supply type. Defaults to INFINITE
   257  func (tx *TokenCreateTransaction) SetSupplyType(tokenSupply TokenSupplyType) *TokenCreateTransaction {
   258  	tx._RequireNotFrozen()
   259  	tx.tokenSupplyType = tokenSupply
   260  	return tx
   261  }
   262  
   263  // GetSupplyType returns the token supply type
   264  func (tx *TokenCreateTransaction) GetSupplyType() TokenSupplyType {
   265  	return tx.tokenSupplyType
   266  }
   267  
   268  // SetMaxSupply Depends on TokenSupplyType. For tokens of type FUNGIBLE_COMMON - sets the
   269  // maximum number of tokens that can be in circulation. For tokens of type NON_FUNGIBLE_UNIQUE -
   270  // sets the maximum number of NFTs (serial numbers) that can be minted. This field can never be
   271  // changed!
   272  func (tx *TokenCreateTransaction) SetMaxSupply(maxSupply int64) *TokenCreateTransaction {
   273  	tx._RequireNotFrozen()
   274  	tx.maxSupply = maxSupply
   275  	return tx
   276  }
   277  
   278  // GetMaxSupply returns the max supply
   279  func (tx *TokenCreateTransaction) GetMaxSupply() int64 {
   280  	return tx.maxSupply
   281  }
   282  
   283  // SetTokenMetadata Sets the metadata for the token
   284  func (tx *TokenCreateTransaction) SetTokenMetadata(metadata []byte) *TokenCreateTransaction {
   285  	tx._RequireNotFrozen()
   286  	tx.metadata = metadata
   287  	return tx
   288  }
   289  
   290  // GetTokenMetadata returns token class metadata
   291  func (tx *TokenCreateTransaction) GetTokenMetadata() []byte {
   292  	return tx.metadata
   293  }
   294  
   295  // SetTreasuryAccountID Sets the account which will act as a treasury for the token. This account will receive the specified initial supply
   296  func (tx *TokenCreateTransaction) SetTreasuryAccountID(treasuryAccountID AccountID) *TokenCreateTransaction {
   297  	tx._RequireNotFrozen()
   298  	tx.treasuryAccountID = &treasuryAccountID
   299  	return tx
   300  }
   301  
   302  // GetTreasuryAccountID returns the treasury account ID
   303  func (tx *TokenCreateTransaction) GetTreasuryAccountID() AccountID {
   304  	if tx.treasuryAccountID == nil {
   305  		return AccountID{}
   306  	}
   307  
   308  	return *tx.treasuryAccountID
   309  }
   310  
   311  // SetAdminKey Sets the key which can perform update/delete operations on the token. If empty, the token can be perceived as immutable (not being able to be updated/deleted)
   312  func (tx *TokenCreateTransaction) SetAdminKey(publicKey Key) *TokenCreateTransaction {
   313  	tx._RequireNotFrozen()
   314  	tx.adminKey = publicKey
   315  	return tx
   316  }
   317  
   318  // GetAdminKey returns the admin key
   319  func (tx *TokenCreateTransaction) GetAdminKey() Key {
   320  	return tx.adminKey
   321  }
   322  
   323  // SetKycKey Sets the key which can grant or revoke KYC of an account for the token's transactions. If empty, KYC is not required, and KYC grant or revoke operations are not possible.
   324  func (tx *TokenCreateTransaction) SetKycKey(publicKey Key) *TokenCreateTransaction {
   325  	tx._RequireNotFrozen()
   326  	tx.kycKey = publicKey
   327  	return tx
   328  }
   329  
   330  func (tx *TokenCreateTransaction) GetKycKey() Key {
   331  	return tx.kycKey
   332  }
   333  
   334  // SetFreezeKey Sets the key which can sign to freeze or unfreeze an account for token transactions. If empty, freezing is not possible
   335  func (tx *TokenCreateTransaction) SetFreezeKey(publicKey Key) *TokenCreateTransaction {
   336  	tx._RequireNotFrozen()
   337  	tx.freezeKey = publicKey
   338  	return tx
   339  }
   340  
   341  // GetFreezeKey returns the freeze key
   342  func (tx *TokenCreateTransaction) GetFreezeKey() Key {
   343  	return tx.freezeKey
   344  }
   345  
   346  // SetWipeKey Sets the key which can wipe the token balance of an account. If empty, wipe is not possible
   347  func (tx *TokenCreateTransaction) SetWipeKey(publicKey Key) *TokenCreateTransaction {
   348  	tx._RequireNotFrozen()
   349  	tx.wipeKey = publicKey
   350  	return tx
   351  }
   352  
   353  // GetWipeKey returns the wipe key
   354  func (tx *TokenCreateTransaction) GetWipeKey() Key {
   355  	return tx.wipeKey
   356  }
   357  
   358  // SetFeeScheduleKey Set the key which can change the token's custom fee schedule; must sign a TokenFeeScheduleUpdate
   359  // transaction
   360  func (tx *TokenCreateTransaction) SetFeeScheduleKey(key Key) *TokenCreateTransaction {
   361  	tx._RequireNotFrozen()
   362  	tx.scheduleKey = key
   363  	return tx
   364  }
   365  
   366  // GetFeeScheduleKey returns the fee schedule key
   367  func (tx *TokenCreateTransaction) GetFeeScheduleKey() Key {
   368  	return tx.scheduleKey
   369  }
   370  
   371  // SetPauseKey Set the Key which can pause and unpause the Token.
   372  // If Empty the token pause status defaults to PauseNotApplicable, otherwise Unpaused.
   373  func (tx *TokenCreateTransaction) SetPauseKey(key Key) *TokenCreateTransaction {
   374  	tx._RequireNotFrozen()
   375  	tx.pauseKey = key
   376  	return tx
   377  }
   378  
   379  // GetPauseKey returns the pause key
   380  func (tx *TokenCreateTransaction) GetPauseKey() Key {
   381  	return tx.pauseKey
   382  }
   383  
   384  // SetMetadataKey Set the Key which can update the metadata.
   385  func (tx *TokenCreateTransaction) SetMetadataKey(key Key) *TokenCreateTransaction {
   386  	tx._RequireNotFrozen()
   387  	tx.metadataKey = key
   388  	return tx
   389  }
   390  
   391  // GetMetadataKey returns the metadata key
   392  func (tx *TokenCreateTransaction) GetMetadataKey() Key {
   393  	return tx.metadataKey
   394  }
   395  
   396  // SetCustomFees Set the custom fees to be assessed during a CryptoTransfer that transfers units of this token
   397  func (tx *TokenCreateTransaction) SetCustomFees(customFee []Fee) *TokenCreateTransaction {
   398  	tx._RequireNotFrozen()
   399  	tx.customFees = customFee
   400  	return tx
   401  }
   402  
   403  // GetCustomFees returns the custom fees
   404  func (tx *TokenCreateTransaction) GetCustomFees() []Fee {
   405  	return tx.customFees
   406  }
   407  
   408  // The key which can change the supply of a token. The key is used to sign Token Mint/Burn operations
   409  // SetInitialBalance sets the initial number of Hbar to put into the token
   410  func (tx *TokenCreateTransaction) SetSupplyKey(publicKey Key) *TokenCreateTransaction {
   411  	tx._RequireNotFrozen()
   412  	tx.supplyKey = publicKey
   413  	return tx
   414  }
   415  
   416  func (tx *TokenCreateTransaction) GetSupplyKey() Key {
   417  	return tx.supplyKey
   418  }
   419  
   420  // Specifies the initial supply of tokens to be put in circulation. The initial supply is sent to the Treasury Account. The supply is in the lowest denomination possible.
   421  func (tx *TokenCreateTransaction) SetInitialSupply(initialSupply uint64) *TokenCreateTransaction {
   422  	tx._RequireNotFrozen()
   423  	tx.initialSupply = initialSupply
   424  	return tx
   425  }
   426  
   427  func (tx *TokenCreateTransaction) GetInitialSupply() uint64 {
   428  	return tx.initialSupply
   429  }
   430  
   431  // The default Freeze status (frozen or unfrozen) of Hedera accounts relative to this token. If true, an account must be unfrozen before it can receive the token
   432  func (tx *TokenCreateTransaction) SetFreezeDefault(freezeDefault bool) *TokenCreateTransaction {
   433  	tx._RequireNotFrozen()
   434  	tx.freezeDefault = &freezeDefault
   435  	return tx
   436  }
   437  
   438  // GetFreezeDefault returns the freeze default
   439  func (tx *TokenCreateTransaction) GetFreezeDefault() bool {
   440  	return *tx.freezeDefault
   441  }
   442  
   443  // The epoch second at which the token should expire; if an auto-renew account and period are specified, this is coerced to the current epoch second plus the autoRenewPeriod
   444  func (tx *TokenCreateTransaction) SetExpirationTime(expirationTime time.Time) *TokenCreateTransaction {
   445  	tx._RequireNotFrozen()
   446  	tx.autoRenewPeriod = nil
   447  	tx.expirationTime = &expirationTime
   448  
   449  	return tx
   450  }
   451  
   452  func (tx *TokenCreateTransaction) GetExpirationTime() time.Time {
   453  	if tx.expirationTime != nil {
   454  		return *tx.expirationTime
   455  	}
   456  
   457  	return time.Time{}
   458  }
   459  
   460  // An account which will be automatically charged to renew the token's expiration, at autoRenewPeriod interval
   461  func (tx *TokenCreateTransaction) SetAutoRenewAccount(autoRenewAccountID AccountID) *TokenCreateTransaction {
   462  	tx._RequireNotFrozen()
   463  	tx.autoRenewAccountID = &autoRenewAccountID
   464  	return tx
   465  }
   466  
   467  func (tx *TokenCreateTransaction) GetAutoRenewAccount() AccountID {
   468  	if tx.autoRenewAccountID == nil {
   469  		return AccountID{}
   470  	}
   471  
   472  	return *tx.autoRenewAccountID
   473  }
   474  
   475  // The interval at which the auto-renew account will be charged to extend the token's expiry
   476  func (tx *TokenCreateTransaction) SetAutoRenewPeriod(autoRenewPeriod time.Duration) *TokenCreateTransaction {
   477  	tx._RequireNotFrozen()
   478  	tx.autoRenewPeriod = &autoRenewPeriod
   479  	return tx
   480  }
   481  
   482  func (tx *TokenCreateTransaction) GetAutoRenewPeriod() time.Duration {
   483  	if tx.autoRenewPeriod != nil {
   484  		return time.Duration(int64(tx.autoRenewPeriod.Seconds()) * time.Second.Nanoseconds())
   485  	}
   486  
   487  	return time.Duration(0)
   488  }
   489  
   490  // ---- Required Interfaces ---- //
   491  
   492  // Sign uses the provided privateKey to sign the transaction.
   493  func (tx *TokenCreateTransaction) Sign(privateKey PrivateKey) *TokenCreateTransaction {
   494  	tx.Transaction.Sign(privateKey)
   495  	return tx
   496  }
   497  
   498  // SignWithOperator signs the transaction with client's operator privateKey.
   499  func (tx *TokenCreateTransaction) SignWithOperator(client *Client) (*TokenCreateTransaction, error) {
   500  	_, err := tx.Transaction.signWithOperator(client, tx)
   501  	if err != nil {
   502  		return nil, err
   503  	}
   504  	return tx, nil
   505  }
   506  
   507  // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map
   508  // with the publicKey as the map key.
   509  func (tx *TokenCreateTransaction) SignWith(
   510  	publicKey PublicKey,
   511  	signer TransactionSigner,
   512  ) *TokenCreateTransaction {
   513  	tx.Transaction.SignWith(publicKey, signer)
   514  	return tx
   515  }
   516  
   517  // AddSignature adds a signature to the transaction.
   518  func (tx *TokenCreateTransaction) AddSignature(publicKey PublicKey, signature []byte) *TokenCreateTransaction {
   519  	tx.Transaction.AddSignature(publicKey, signature)
   520  	return tx
   521  }
   522  
   523  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
   524  func (tx *TokenCreateTransaction) SetGrpcDeadline(deadline *time.Duration) *TokenCreateTransaction {
   525  	tx.Transaction.SetGrpcDeadline(deadline)
   526  	return tx
   527  }
   528  
   529  func (tx *TokenCreateTransaction) Freeze() (*TokenCreateTransaction, error) {
   530  	return tx.FreezeWith(nil)
   531  }
   532  
   533  func (tx *TokenCreateTransaction) FreezeWith(client *Client) (*TokenCreateTransaction, error) {
   534  	_, err := tx.Transaction.freezeWith(client, tx)
   535  	return tx, err
   536  }
   537  
   538  // SetMaxTransactionFee sets the max transaction fee for this TokenCreateTransaction.
   539  func (tx *TokenCreateTransaction) SetMaxTransactionFee(fee Hbar) *TokenCreateTransaction {
   540  	tx.Transaction.SetMaxTransactionFee(fee)
   541  	return tx
   542  }
   543  
   544  // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received
   545  func (tx *TokenCreateTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *TokenCreateTransaction {
   546  	tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID)
   547  	return tx
   548  }
   549  
   550  // SetTransactionMemo sets the memo for this TokenCreateTransaction.
   551  func (tx *TokenCreateTransaction) SetTransactionMemo(memo string) *TokenCreateTransaction {
   552  	tx.Transaction.SetTransactionMemo(memo)
   553  	return tx
   554  }
   555  
   556  // SetTransactionValidDuration sets the valid duration for this TokenCreateTransaction.
   557  func (tx *TokenCreateTransaction) SetTransactionValidDuration(duration time.Duration) *TokenCreateTransaction {
   558  	tx.Transaction.SetTransactionValidDuration(duration)
   559  	return tx
   560  }
   561  
   562  // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not
   563  func (tx *TokenCreateTransaction) ToBytes() ([]byte, error) {
   564  	bytes, err := tx.Transaction.toBytes(tx)
   565  	if err != nil {
   566  		return nil, err
   567  	}
   568  	return bytes, nil
   569  }
   570  
   571  // SetTransactionID sets the TransactionID for this TokenCreateTransaction.
   572  func (tx *TokenCreateTransaction) SetTransactionID(transactionID TransactionID) *TokenCreateTransaction {
   573  	tx.Transaction.SetTransactionID(transactionID)
   574  	return tx
   575  }
   576  
   577  // SetNodeAccountIDs sets the _Node AccountID for this TokenCreateTransaction.
   578  func (tx *TokenCreateTransaction) SetNodeAccountIDs(nodeID []AccountID) *TokenCreateTransaction {
   579  	tx.Transaction.SetNodeAccountIDs(nodeID)
   580  	return tx
   581  }
   582  
   583  // SetMaxRetry sets the max number of errors before execution will fail.
   584  func (tx *TokenCreateTransaction) SetMaxRetry(count int) *TokenCreateTransaction {
   585  	tx.Transaction.SetMaxRetry(count)
   586  	return tx
   587  }
   588  
   589  // SetMaxBackoff The maximum amount of time to wait between retries.
   590  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   591  func (tx *TokenCreateTransaction) SetMaxBackoff(max time.Duration) *TokenCreateTransaction {
   592  	tx.Transaction.SetMaxBackoff(max)
   593  	return tx
   594  }
   595  
   596  // SetMinBackoff sets the minimum amount of time to wait between retries.
   597  func (tx *TokenCreateTransaction) SetMinBackoff(min time.Duration) *TokenCreateTransaction {
   598  	tx.Transaction.SetMinBackoff(min)
   599  	return tx
   600  }
   601  
   602  func (tx *TokenCreateTransaction) SetLogLevel(level LogLevel) *TokenCreateTransaction {
   603  	tx.Transaction.SetLogLevel(level)
   604  	return tx
   605  }
   606  
   607  func (tx *TokenCreateTransaction) Execute(client *Client) (TransactionResponse, error) {
   608  	return tx.Transaction.execute(client, tx)
   609  }
   610  
   611  func (tx *TokenCreateTransaction) Schedule() (*ScheduleCreateTransaction, error) {
   612  	return tx.Transaction.schedule(tx)
   613  }
   614  
   615  // ----------- Overridden functions ----------------
   616  
   617  func (tx *TokenCreateTransaction) getName() string {
   618  	return "TokenCreateTransaction"
   619  }
   620  
   621  func (tx *TokenCreateTransaction) validateNetworkOnIDs(client *Client) error {
   622  	if client == nil || !client.autoValidateChecksums {
   623  		return nil
   624  	}
   625  
   626  	if tx.treasuryAccountID != nil {
   627  		if err := tx.treasuryAccountID.ValidateChecksum(client); err != nil {
   628  			return err
   629  		}
   630  	}
   631  
   632  	if tx.autoRenewAccountID != nil {
   633  		if err := tx.autoRenewAccountID.ValidateChecksum(client); err != nil {
   634  			return err
   635  		}
   636  	}
   637  
   638  	for _, customFee := range tx.customFees {
   639  		if err := customFee.validateNetworkOnIDs(client); err != nil {
   640  			return err
   641  		}
   642  	}
   643  
   644  	return nil
   645  }
   646  
   647  func (tx *TokenCreateTransaction) build() *services.TransactionBody {
   648  	return &services.TransactionBody{
   649  		TransactionFee:           tx.transactionFee,
   650  		Memo:                     tx.Transaction.memo,
   651  		TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
   652  		TransactionID:            tx.transactionID._ToProtobuf(),
   653  		Data: &services.TransactionBody_TokenCreation{
   654  			TokenCreation: tx.buildProtoBody(),
   655  		},
   656  	}
   657  }
   658  
   659  func (tx *TokenCreateTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) {
   660  	return &services.SchedulableTransactionBody{
   661  		TransactionFee: tx.transactionFee,
   662  		Memo:           tx.Transaction.memo,
   663  		Data: &services.SchedulableTransactionBody_TokenCreation{
   664  			TokenCreation: tx.buildProtoBody(),
   665  		},
   666  	}, nil
   667  }
   668  
   669  func (tx *TokenCreateTransaction) buildProtoBody() *services.TokenCreateTransactionBody {
   670  	body := &services.TokenCreateTransactionBody{
   671  		Name:          tx.tokenName,
   672  		Symbol:        tx.tokenSymbol,
   673  		Memo:          tx.memo,
   674  		Decimals:      tx.decimals,
   675  		TokenType:     services.TokenType(tx.tokenType),
   676  		SupplyType:    services.TokenSupplyType(tx.tokenSupplyType),
   677  		MaxSupply:     tx.maxSupply,
   678  		InitialSupply: tx.initialSupply,
   679  	}
   680  
   681  	if tx.autoRenewPeriod != nil {
   682  		body.AutoRenewPeriod = _DurationToProtobuf(*tx.autoRenewPeriod)
   683  	}
   684  
   685  	if tx.expirationTime != nil {
   686  		body.Expiry = _TimeToProtobuf(*tx.expirationTime)
   687  	}
   688  
   689  	if tx.treasuryAccountID != nil {
   690  		body.Treasury = tx.treasuryAccountID._ToProtobuf()
   691  	}
   692  
   693  	if tx.autoRenewAccountID != nil {
   694  		body.AutoRenewAccount = tx.autoRenewAccountID._ToProtobuf()
   695  	}
   696  
   697  	if body.CustomFees == nil {
   698  		body.CustomFees = make([]*services.CustomFee, 0)
   699  	}
   700  	for _, customFee := range tx.customFees {
   701  		body.CustomFees = append(body.CustomFees, customFee._ToProtobuf())
   702  	}
   703  
   704  	if tx.adminKey != nil {
   705  		body.AdminKey = tx.adminKey._ToProtoKey()
   706  	}
   707  
   708  	if tx.freezeKey != nil {
   709  		body.FreezeKey = tx.freezeKey._ToProtoKey()
   710  	}
   711  
   712  	if tx.scheduleKey != nil {
   713  		body.FeeScheduleKey = tx.scheduleKey._ToProtoKey()
   714  	}
   715  
   716  	if tx.kycKey != nil {
   717  		body.KycKey = tx.kycKey._ToProtoKey()
   718  	}
   719  
   720  	if tx.wipeKey != nil {
   721  		body.WipeKey = tx.wipeKey._ToProtoKey()
   722  	}
   723  
   724  	if tx.supplyKey != nil {
   725  		body.SupplyKey = tx.supplyKey._ToProtoKey()
   726  	}
   727  
   728  	if tx.pauseKey != nil {
   729  		body.PauseKey = tx.pauseKey._ToProtoKey()
   730  	}
   731  
   732  	if tx.metadataKey != nil {
   733  		body.MetadataKey = tx.metadataKey._ToProtoKey()
   734  	}
   735  
   736  	if tx.freezeDefault != nil {
   737  		body.FreezeDefault = *tx.freezeDefault
   738  	}
   739  
   740  	if tx.metadata != nil {
   741  		body.Metadata = tx.metadata
   742  	}
   743  
   744  	return body
   745  }
   746  
   747  func (tx *TokenCreateTransaction) getMethod(channel *_Channel) _Method {
   748  	return _Method{
   749  		transaction: channel._GetToken().CreateToken,
   750  	}
   751  }
   752  
   753  func (tx *TokenCreateTransaction) preFreezeWith(client *Client) {
   754  	if tx.autoRenewAccountID == nil && tx.autoRenewPeriod != nil && client != nil && !client.GetOperatorAccountID()._IsZero() {
   755  		tx.SetAutoRenewAccount(client.GetOperatorAccountID())
   756  	}
   757  }
   758  
   759  func (tx *TokenCreateTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
   760  	return tx.buildScheduled()
   761  }