Skip to main content

Hedera Token Service

Hedera Token Service integration allows you to write token transactions natively in Solidity smart contracts. There are a few Solidity source files available to developers. The Hedera Token Service Solidity file provides the transactions to interact with tokens created on Hedera. The Hedera Response Codes contract provides the response codes associated with network errors. The IHedera Token Service is a supporting library for the Hedera Token Service Solidity file. You can grab these libraries here to add to your project and import them to your Solidity contract. Please see the example file below.
ContractExample.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

import "./HederaTokenService.sol";
import "./HederaResponseCodes.sol";

contract contractExample is HederaTokenService {
...
int response = HederaTokenService.transferToken(tokenAddress, msg.sender, address(this), amount);
...
}
Note: Although the IHederaTokenService.sol file is not imported in the contract, you will need it in your project directory for the supporting libraries to reference.

HederaTokenService.sol API Docs

Create Tokens

HIP-358: Token create precompile is live on previewnet and testnet. The TokenCreateContract example contains four examples of how to create a token using the token create solidity libraries.

createFungibleToken(token, initialTotalSupply, decimals)

A transaction that creates a fungible token. Returns the new token address.
ParamTypeDescription
tokenIHederaTokenService.HederaToken memoryThe basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc.
initialTotalSupplyuintSpecifies 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.
decimalsuintThe number of decimal places a token is divisible by.

createFungibleTokenWithCustomFees(token, initialTotalSupply, decimals, fixedFees, fractionalFees)

A transaction that creates a fungible token with custom fees. Returns the new token address.
ParamTypeDescription
tokenIHederaTokenService.HederaToken memoryThe basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc.
initialTotalSupplyuintSpecifies 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.
decimalsuintThe number of decimal places a token is divisible by.
fixedFeesIHederaTokenService.FixedFee[]List of fixed fees to apply to the token.
fractionalFeesIHederaTokenService.FractionalFee[]List of fractional fees to apply to the token.

createNonFungibleToken(token)

Creates a non fungible token. Returns the new token address.
ParamTypeDescription
tokenIHederaTokenService.HederaToken memoryThe basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc.

createNonFungibleTokenWithCustomFees(token, fixedFees, fractionalFees)

Creates a non fungible token with custom fees. Returns the new token address.
ParamTypeDescription
tokenIHederaTokenService.HederaToken memoryThe basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc.
fixedFeesIHederaTokenService.FixedFee[]List of fixed fees to apply to the token.
fractionalFeesIHederaTokenService.FractionalFee[]List of fractional fees to apply to the token.

Transfer Tokens

cryptoTransfer(tokenTransfers)

A transaction that transfers the provided list of tokens. ABI Version: 2
ParamTypeDescription
tokenTransfersIHederaTokenService.TokenTransferList[] memoryThe list of token transfers

transferToken(token, sender, receiver, amount)

Transfers tokens where the calling account/contract is implicitly the first entry in the token transfer list, where the amount is the value needed to zero balance the transfers. The account address sending the token is required to sign the transaction. ABI Version: 1
ParamTypeDescription
tokenaddressThe token ID to transfer to/from. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
senderaddressThe address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
receiveraddressThe address of the receiver of the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
amountint64Non-negative value of the token to send. A negative value will result in a failure.

transferTokens(token, accountIds, amount)

Initiates a fungible token transfer. This transaction accepts zero unit token transfer operations for fungible tokens (HIP-564). Not applicable to non-fungible tokens. ABI Version: 1
ParamTypeDescription
tokenaddressThe token ID to transfer. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
accountIdsaddress[] memoryHedera accounts to do a transfer to/from. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
amountsint64[] memoryNon-negative value to send. A negative value will result in a failure.

transferNFT(token, sender, receiver, serialNum)

Transfers tokens where the calling account/contract is implicitly the first entry in the token transfer list, where the amount is the value needed to zero balance the transfers. The address sending the token is required to sign the transaction. ABI Version: 1
ParamTypeDescription
tokenaddressThe token to transfer to/from.
senderaddressThe address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
receiveraddressThe address of the receiver of the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
serialNumint64The serial number of the NFT to transfer.

transferNFTs(token, sender, receiver, serialNumber)

Initiates a non-fungible token transfer ABI Version: 1
ParamTypeDescription
tokenaddressThe ID of the token to transfer. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
senderaddress[] memoryThe address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
receiveraddress[] memoryThe address of the receiver of the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
serialNumberint64The serial number of the NFT is sent by the same index of the sender.

Mint Tokens

mintToken(token, amount, metadata)

Mints an amount of the token to the defined treasury account. This transaction accepts zero-amount token mint operations for fungible tokens (HIP-564). ABI Version: 2
ParamTypeDescription
tokenaddressThe Hedera token to mint. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
amount


uint64

Applicable to FUNGIBLE TOKENS ONLY.

The amount to mint to the Treasury Account. Amount must be a positive non-zero number represented in the lowest denomination of the token. The new supply must be lower than 2^63.

metadatabytes[] memory

Applicable to NON-FUNGIBLE TOKENS ONLY.
Maximum allowed size of each metadata is 100 bytes

Burn Tokens

burnToken(token, amount, serialNumbers)

Burns an amount of the token from the defined treasury account. This transaction accepts zero amount token burn operations for fungible tokens (HIP-564). ABI Version: 2
ParamTypeDescription
tokenaddressThe token to burn. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
amountuint64

Applicable to FUNGIBLE TOKENS ONLY.

The amount to burn from the Treasury Account. Amount must be a positive non-zero number, not bigger than the token balance of the treasury account (0; balance], represented in the lowest denomination.

serialNumbersint64[]

Applicable to NON-FUNGIBLE TOKENS ONLY.

The list of serial numbers to be burned.

Associate Tokens

associateToken(account, tokens)

Associates the provided account with the provided tokens. Must be signed by the account that is associated with the token. ABI Version: 2
ParamTypeDescription
accountaddressThe account to be associated with the provided tokens. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.
tokenaddress[] memory

The list of tokens to be associated with the provided account.


In the case of non-fungible tokens, once an account is associated, it can hold any number of NFTs (serial numbers) of that token type.

The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.

Dissociate Tokens

dissociateToken(account, token)

Dissociates the provided account with the provided token. Must be signed by the provided Account’s key. ABI Version: 2
ParamTypeDescription
accountaddress

The Hedera account to be dissociated from the provided token.

The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.

tokenaddress

The token to be dissociated from the provided account.

The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address.

dissociateTokens(account, tokens)

Dissociates the provided account with the provided token. Must be signed by the account the token is being dissociated from. ABI Version: 2
ParamTypeDescription
accountaddressThe account is to be dissociated from the provided tokens.
tokensaddress[] memory

The list of tokens to be dissociated from the provided account.

The address is a mapping of shard.realm.number (0.0.x) into a 20-byte Solidity address.

allowance(token, owner, spender)

Returns the amount the spender is still allowed to withdraw from the owner. Only applicable to fungible tokens.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format to check the allowance of.
owneraddressThe owner account in Solidity format of the tokens to be spent.
spenderaddressThe spender account in Solidity format.

approve(token, spender, amount)

Allows spender to withdraw from your account multiple times, up to the value amount. If this function is called again it overwrites the current allowance.
ParamTypeDescription
tokenaddressThe Hedera token ID to approve in Solidity format.
spenderaddressThe spender account ID authorized to spend in Solidity format.
amountuint256The amount of tokens the spender is authorized to spend.

approveNFT(token, approved, serialNumber)

Allow or reaffirm the approved address to transfer an NFT the approved address does not own. Applicable to non-fungible tokens (NFTs).
ParamTypeDescription
tokenaddressThe Hedera NFT token ID in solidity format to approve.
approvedaddressThe Hedera account ID to approve in Solidity format. To revoke approvals pass in the zero address.
serialNumberuint256The NFT serial number to approve.

getApproved(token, serialNumber)

Get the approved Hedera accounts for a single NFT. Applicable to non-fungible tokens (NFTs).
ParamTypeDescription
tokenaddressThe Hedera token ID for the NFT in Solidity format.
serialNumberint64The NFT serial number.

isApprovedForAll(token, owner, operator)

Returns whether or not the operator account is approved to spend on behalf of the owner.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
owneraddressThe Hedera account ID in Solidity format
operatoraddressThe Hedera account ID in Solidity format

setApprovalForAll(token, operator, approved)

Enable or disable approval for a third party (“operator”) to manage all of msg.sender’s assets.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
operatoraddressThe Hedera account ID in Solidity format.
approvedboolThe Boolean data type in true or false.

isFrozen(token, account)

Returns whether or not the account was frozen. The response will return true is the account is frozen. This means the token cannot be transferred from the account until the account is unfrozen.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

isKyc(token, account)

Returns whether or not the token has been granted KYC.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

isToken(token)

Returns whether or not the token exists on Hedera.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

deleteToken(token)

Deletes the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

getTokenCustomFees(token)

Returns the custom fees for the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

getTokenDefaultFreezeStatus(token)

Returns the token freeze status on the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

getTokenDefaultKycStatus(token)

Returns the KYC status on the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

getTokenExpiryInfo(token)

Returns the token expiration for the specified token.
ParamTypeDescription
tokenaddressThe ID of the Hedera token in Solidity format.

getTokenInfo(token)

Retrieves general token entity information for the specified token.
ParamTypeDescription
tokenaddressThe ID of the Hedera token in Solidity format.

getFungibleTokenInfo(token)

Retrieves fungible specific token property information for a fungible token.
ParamTypeDescription
tokenaddressThe Hedera token ID of the fungible token in Solidity format.

getNonFungibleTokenInfo(token)

Retrieves non-fungible specific token info for a given NFT.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

getTokenKey(token, keyType)

Returns the token key for the specified key type. A key type can be be the KYC key, pause key, freeze key, etc.
ParamTypeDescription
tokenaddressThe ID of the token in solidity format to return the key value.
keyTypeuintThe keyType of the desired key value.

getTokenType(token)

Returns the token type (fungible or non-fungible) for the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

freezeToken(token, account)

Freezes the account from transacting the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

unfreezeToken(token, account)

Unfreezes the account from transacting the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

grantTokenKyc(token, account)

Grants KYC to the Hedera account for the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

revokeTokenKyc(token, account)

Revokes KYC to the Hedera account for the specified token.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.

pauseToken(token)

Prevents a token from being transacted if set.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

unpauseToken(token)

Unpauses a token from a previously paused state.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.

wipeTokenAccount(token, account, amount)

Wipes fungible tokens from the specified account. This transaction accepts zero amount token wipe operations for fungible tokens (HIP-564).
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.
amountuint32The amount of fungible tokens to wipe.

wipeTokenAccountNFT(token, token, serialNumbers)

Wipes a non-fungible token from the specified account.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
accountaddressThe Hedera account ID in Solidity format.
serialNumbersint64[] memoryThe NFT serial numbers to wipe from the account.

updateTokenInfo(token, tokenInfo)

Updates the properties of a token including the name, symbol, treasury account, memo, etc.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
tokenInfoIHederaTokenService.HederaToken memoryThe token properties to update.

updateTokenExpiryInfo(token, expiryInfo)

Update the token expiration time.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
expiryInfoIHederaTokenService.Expiry memoryThe expiry properties of a token.

updateTokenKeys(token, keys)

Update the keys set on a token. The key type is defined in the key parameter.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
keysIHederaTokenService.TokenKey[] memoryThe token key type.

updateTokenKeys(token, keys)

Update the keys set on a token. The key type is defined in the key parameter.
ParamTypeDescription
tokenaddressThe Hedera token ID in Solidity format.
keysIHederaTokenService.TokenKey[] memoryThe token key type.

Airdrop Tokens

airdropTokens(tokenTransfers)

Airdrop one or more tokens to one or more accounts.
ParamTypeDescription
tokenTransfersIHederaTokenService.TokenTransferList[] memoryThe list of token transfers

cancelAirdrop(pendingAirdrops)

Cancels pending airdrops that have not yet been claimed.
ParamTypeDescription
pendingAirdropsIHederaTokenService.PendingAirdrop[] memoryThe list of pending airdrops to cancel.

claimAirdrops(pendingAirdrops)

Claims pending airdrops that were sent to the calling account.
ParamTypeDescription
pendingAirdropsIHederaTokenService.PendingAirdrop[] memoryThe list of pending airdrops to claim.

rejectTokens(rejectAddress, ftAddresses, nftIds)

Airdrop one or more tokens to one or more accounts.
ParamTypeDescription
rejectingAddressaddressThe address rejecting the tokens
ftAddressesmemoryArray of fungible token addresses to reject
nftIdsIHederaTokenService.NftId[] memoryArray of NFT IDs to reject

Gas Cost

Fees

Examples