Skip to content

Latest commit

 

History

History
150 lines (112 loc) · 13.5 KB

define-a-token.md

File metadata and controls

150 lines (112 loc) · 13.5 KB

Create a token

{% hint style="info" %} Check out the "Getting Started with the Hedera Token Service" video tutorial in JavaScript here. {% endhint %}

Create a new fungible or non-fungible token (NFT) on the Hedera network. After you submit the transaction to the Hedera network, you can obtain the new token ID by requesting the receipt.

You can also create, access, or transfer HTS tokens using smart contracts - see Hedera Service Solidity Libraries and Supported ERC Token Standards.

{% hint style="warning" %}

Token Keys

  • If any of the token key types (KYC key, Wipe key, Metadata key, etc) are not set during the creation of the token, you will not be able to update the token and add them in the future
  • If any of the token key types (KYC key, Wipe key, Metadata key, etc) are set during the creation of the token, you will not be able to remove them in the future {% endhint %}

NFTs

For non-fungible tokens, the token ID represents an NFT class. Once the token is created, you must mint each NFT using the token mint operation.

{% hint style="warning" %} Note: The initial supply for an NFT is required to be set to 0. {% endhint %}

Token Properties

PropertyDescription
NameSet the publicly visible name of the token. The token name is specified as a string of UTF-8 characters in Unicode. UTF-8 encoding of this Unicode cannot contain the 0 byte (NUL). The token name is not unique. Maximum of 100 characters.
Token TypeThe type of token to create. Either fungible or non-fungible.
SymbolThe publicly visible token symbol. Set the publicly visible name of the token. The token symbol is specified as a string of UTF-8 characters in Unicode. UTF-8 encoding of this Unicode cannot contain the 0 byte (NUL). The token symbol is not unique. Maximum of 100 characters.
DecimalThe number of decimal places a token is divisible by. This field can never be changed.
Initial SupplySpecifies the initial supply of fungible tokens to be put in circulation. The initial supply is sent to the Treasury Account. The maximum supply of tokens is 9,223,372,036,854,775,807(2^63-1) tokens and is in the lowest denomination possible. For creating an NFT, you must set the initial supply to 0.
Treasury AccountThe account which will act as a treasury for the token. This account will receive the specified initial supply and any additional tokens that are minted. If tokens are burned, the supply will decreased from the treasury account.
Admin KeyThe key which can perform token update and token delete operations on the token. The admin key has the authority to change the supply key, freeze key, pause key, wipe key, and KYC key. It can also update the treasury account of the token. If empty, the token can be perceived as immutable (not being able to be updated/deleted).
KYC KeyThe 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.
Freeze KeyThe key which can sign to freeze or unfreeze an account for token transactions. If empty, freezing is not possible.
Wipe KeyThe key which can wipe the token balance of an account. If empty, wipe is not possible.
Supply KeyThe key which can change the total supply of a token. This key is used to authorize token mint and burn transactions. If this is left empty, minting/burning tokens is not possible.
Fee Schedule KeyThe key which can change the token's custom fee schedule. It must sign a TokenFeeScheduleUpdate transaction. A custom fee schedule token without a fee schedule key is immutable.
Pause KeyThe key which has the authority to pause or unpause a token. Pausing a token prevents the token from participating in all transactions.
Custom FeesCustom fees to charge during a token transfer transaction that transfers units of this token. Custom fees can either be fixed, fractional, or royalty fees. You can set up to a maximum of 10 custom fees.
Max SupplyFor tokens of type FUNGIBLE_COMMON - the maximum number of tokens that can be in circulation.
For tokens of type NON_FUNGIBLE_UNIQUE - the maximum number of NFTs (serial numbers) that can be minted. This field can never be changed.
You must set the token supply type to FINITE if you set this field.
Supply TypeSpecifies the token supply type. Defaults to INFINITE.
Freeze DefaultThe 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.
Expiration TimeThe 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. The default expiration time is 7,890,000 seconds (90 days).
Auto Renew AccountAn account which will be automatically charged to renew the token's expiration, at autoRenewPeriod interval. This key is required to sign the transaction if present. Currently, rent is not enforced for tokens so auto-renew payments will not be made.
Auto Renew PeriodThe interval at which the auto-renew account will be charged to extend the token's expiry. The default auto-renew period is 7,890,000 seconds. Currently, rent is not enforced for tokens so auto-renew payments will not be made.

NOTE: The minimum period of time is approximately 30 days (2592000 seconds) and the maximum period of time is approximately 92 days (8000001 seconds). Any other value outside of this range will return the following error: AUTORENEW_DURATION_NOT_IN_RANGE.
MemoA short publicly visible memo about the token.
Metadata KeyThe key which can update the metadata of an NFT. This key is used to sign and authorize the transaction to update the metadata of dynamic NFTs. This value can be null.
MetadataThe metadata of the token. The admin key or the metadata key can be used to update this property.

Transaction Signing Requirements

  • Treasury key is required to sign
  • Admin key, if specified
  • Transaction fee payer key

Transaction Fees

  • For fungible tokens, a CryptoTransfer fee is added to transfer the newly created token to the treasury account
  • Please see the transaction and query fees table for the base transaction fee
  • Please use the Hedera fee estimator to estimate your transaction fee cost

Methods

MethodTypeRequirement
setTokenName(<name>)StringRequired
setTokenType(<tokenType>)TokenTypeOptional
setTokenSymbol(<symbol>)StringRequired
setDecimals(<decimal>)intOptional
setInitialSupply(<initialSupply>)intOptional
setTreasuryAccountId(<treasury>)AccountIdRequired
setAdminKey(<key>)KeyOptional
setKycKey(<key>)KeyOptional
setFreezeKey(<key>)KeyOptional
setWipeKey(<key>)KeyOptional
setSupplyKey(<key>)KeyOptional
setPauseKey(<key>)KeyOptional
setFreezeDefault(<freeze>)booleanOptional
setExpirationTime(<expirationTime>)InstantOptional
setFeeScheduleKey(<key>)KeyOptional
setCustomFees(<customFees>)List<CustomFee>Optional
setSupplyType(<supplyType>)TokenSupplyTypeOptional
setMaxSupply(<maxSupply>)longOptional
setTokenMemo(<memo>)StringOptional
setAutoRenewAccountId(<account>)AccountIdOptional
setAutoRenewPeriod(<period>)DurationOptional
setMetadataKey(<key>)KeyOptional
setMetadata(<bytes>)bytesOptional

{% hint style="info" %} Note: Where the Admin, Pause, Freeze, and Wipe keys are left blank, the Supply key will be required as a minimum. {% endhint %}

{% tabs %} {% tab title="Java" %}

//Create the transaction
TokenCreateTransaction transaction = new TokenCreateTransaction()
        .setTokenName("Your Token Name")
        .setTokenSymbol("F")
        .setTreasuryAccountId(treasuryAccountId)
        .setInitialSupply(5000)
        .setAdminKey(adminKey.getPublicKey())
        .setMetadataKey(metadataKey)
        .setMetadata(metadata)
        .setMaxTransactionFee(new Hbar(30)); //Change the default max transaction fee

//Build the unsigned transaction, sign with admin private key of the token, sign with the token treasury private key, submit the transaction to a Hedera network
TransactionResponse txResponse = transaction.freezeWith(client).sign(adminKey).sign(treasuryKey).execute(client);

//Request the receipt of the transaction
TransactionReceipt receipt = txResponse.getReceipt(client);

//Get the token ID from the receipt
TokenId tokenId = receipt.tokenId;

System.out.println("The new token ID is " + tokenId);

//v2.0.1

{% endtab %}

{% tab title="JavaScript" %}

//Create the transaction and freeze for manual signing
const transaction = await new TokenCreateTransaction()
     .setTokenName("Your Token Name")
     .setTokenSymbol("F")
     .setTreasuryAccountId(treasuryAccountId)
     .setInitialSupply(5000)
     .setAdminKey(adminPublicKey)
     .setMetadataKey(metadataKey)
     .setMetadata(metadata)
     .setMaxTransactionFee(new Hbar(30)) //Change the default max transaction fee
     .freezeWith(client);

//Sign the transaction with the token adminKey and the token treasury account private key
const signTx =  await (await transaction.sign(adminKey)).sign(treasuryKey);

//Sign the transaction with the client operator private key and submit to a Hedera network
const txResponse = await signTx.execute(client);

//Get the receipt of the transaction
const receipt = await txResponse.getReceipt(client);

//Get the token ID from the receipt
const tokenId = receipt.tokenId;

console.log("The new token ID is " + tokenId);

//v2.0.5

{% endtab %}

{% tab title="Go" %}

//Create the transaction and freeze the unsigned transaction
tokenCreateTransaction, err := hedera.NewTokenCreateTransaction().
      SetTokenName("Your Token Name").
        SetTokenSymbol("F").
        SetTreasuryAccountID(treasuryAccountId).
        SetInitialSupply(1000).
        SetAdminKey(adminKey).
        SetMetadataKey(metadataKey).
        SetMetadata(metadata)
        SetMaxTransactionFee(hedera.NewHbar(30)). //Change the default max transaction fee
        FreezeWith(client)

if err != nil {
    panic(err)
}

//Sign with the admin private key of the token, sign with the token treasury private key, sign with the client operator private key and submit the transaction to a Hedera network
txResponse, err := tokenCreateTransaction.Sign(adminKey).Sign(treasuryKey).Execute(client)

if err != nil {
    panic(err)
}

//Request the receipt of the transaction
receipt, err := txResponse.GetReceipt(client)
if err != nil {
    panic(err)
}

//Get the token ID from the receipt
tokenId := *receipt.TokenID

fmt.Printf("The new token ID is %v\n", tokenId)

//v2.1.0

{% endtab %} {% endtabs %}