Hedera Service Solidity Libraries

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.

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

A transaction that creates a fungible token with custom fees. Returns the new token address.

createNonFungibleToken(token)

Creates a non fungible token. Returns the new token address.

createNonFungibleTokenWithCustomFees(token, fixedFees, fractionalFees)

Creates a non fungible token with custom fees. Returns the new token address.

Transfer Tokens

cryptoTransfer(tokenTransfers)

A transaction that transfers the provided list of tokens.

ABI Version: 2

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

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

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

transferNFTs(token, sender, receiver, serialNumber)

Initiates a non-fungible token transfer

ABI Version: 1

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

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

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

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

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

allowance(token, owner, spender)

Returns the amount the spender is still allowed to withdraw from the owner. Only applicable to fungible tokens.

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.

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).

getApproved(token, serialNumber)

Get the approved Hedera accounts for a single NFT. Applicable to non-fungible tokens (NFTs).

isApprovedForAll(token, owner, operator)

Returns whether or not the operator account is approved to spend on behalf of the owner.

setApprovalForAll(token, operator, approved)

Enable or disable approval for a third party ("operator") to manage all of msg.sender's assets.

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.

isKyc(token, account)

Returns whether or not the token has been granted KYC.

isToken(token)

Returns whether or not the token exists on Hedera.

deleteToken(token)

Deletes the specified token.

getTokenCustomFees(token)

Returns the custom fees for the specified token.

getTokenDefaultFreezeStatus(token)

Returns the token freeze status on the specified token.

getTokenDefaultKycStatus(token)

Returns the KYC status on the specified token.

getTokenExpiryInfo(token)

Returns the token expiration for the specified token.

getTokenInfo(token)

Retrieves general token entity information for the specified token.

getFungibleTokenInfo(token)

Retrieves fungible specific token property information for a fungible token.

getNonFungibleTokenInfo(token)

Retrieves non-fungible specific token info for a given NFT.

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.

getTokenType(token)

Returns the token type (fungible or non-fungible) for the specified token.

freezeToken(token, account)

Freezes the account from transacting the specified token.

unfreezeToken(token, account)

Unfreezes the account from transacting the specified token.

grantTokenKyc(token, account)

Grants KYC to the Hedera account for the specified token.

revokeTokenKyc(token, account)

Revokes KYC to the Hedera account for the specified token.

pauseToken(token)

Prevents a token from being transacted if set.

unpauseToken(token)

Unpauses a token from a previously paused state.

wipeTokenAccount(token, account, amount)

Wipes fungible tokens from the specified account. This transaction accepts zero amount token wipe operations for fungible tokens (HIP-564).

wipeTokenAccountNFT(token, token, serialNumbers)

Wipes a non-fungible token from the specified account.

updateTokenInfo(token, tokenInfo)

Updates the properties of a token including the name, symbol, treasury account, memo, etc.

updateTokenExpiryInfo(token, expiryInfo)

Update the token expiration time.

updateTokenKeys(token, keys)

Update the keys set on a token. The key type is defined in the key parameter.

updateTokenKeys(token, keys)

Update the keys set on a token. The key type is defined in the key parameter.

Gas Cost

Examples

Last updated