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.
- HederaTokenService.sol
- HederaResponseCodes.sol
- IHederaTokenService.sol
- ExpiryHelper.sol
- FeeHelper.sol
- KeyHelper.sol
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.
{% code title="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);
...
}
{% endcode %}
{% hint style="info" %} 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. {% endhint %}
{% hint style="info" %} HIP-358: Token create precompile is live on previewnet and testnet. The TokenCreateContract example contains four examples for how to create a token using the token create solidity libraries. {% endhint %}
A transaction that creates a fungible token. Returns the new token address.
Param | Type | Description |
---|---|---|
token |
IHederaTokenService.HederaToken memory | The basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc. |
initialTotalSupply |
uint | 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. |
decimals |
uint | The number of decimal places a token is divisible by. |
A transaction that creates a fungible token with custom fees. Returns the new token address.
Param | Type | Description |
---|---|---|
token |
IHederaTokenService.HederaToken memory | The basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc. |
initialTotalSupply |
uint | 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. |
decimals |
uint | The number of decimal places a token is divisible by. |
fixedFees |
IHederaTokenService.FixedFee[] | List of fixed fees to apply to the token. |
fractionalFees |
IHederaTokenService.FractionalFee[] | List of fractional fees to apply to the token. |
Creates a non fungible token. Returns the new token address.
Param | Type | Description |
---|---|---|
token |
IHederaTokenService.HederaToken memory | The basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc. |
Creates a non fungible token with custom fees. Returns the new token address.
Param | Type | Description |
---|---|---|
token |
IHederaTokenService.HederaToken memory | The basic properties of the token being created. This includes the token name, symbol, treasury account, keys, expiry, etc. |
fixedFees |
IHederaTokenService.FixedFee[] | List of fixed fees to apply to the token. |
fractionalFees |
IHederaTokenService.FractionalFee[] | List of fractional fees to apply to the token. |
A transaction that transfers the provided list of tokens.
ABI Version: 2
Param | Type | Description |
---|---|---|
tokenTransfers |
IHederaTokenService.TokenTransferList[] memory | The list of token transfers |
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
Param | Type | Description |
---|---|---|
token |
address | The token ID to transfer to/from. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
sender |
address | The address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
receiver |
address | The 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. |
amount |
int64 | Non-negative value of the token to send. A negative value will result in a failure. |
Initiates a fungible token transfer. Not applicable to non-fungible tokens.
ABI Version: 1
Param | Type | Description |
---|---|---|
token |
address | The token ID to transfer. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
accountIds |
address[] memory | Hedera 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. |
amounts |
int64[] memory | Non-negative value to send. A negative value will result in a failure. |
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
Param | Type | Description |
---|---|---|
token |
address | The token to transfer to/from. |
sender |
address | The address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
receiver |
address | The 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. |
serialNum |
int64 | The serial number of the NFT to transfer. |
Initiates a non-fungible token transfer
ABI Version: 1
Param | Type | Description |
---|---|---|
token |
address | The ID of the token to transfer. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
sender |
address[] memory | The address sending the token. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
receiver |
address[] memory | The 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. |
serialNumber |
int64 | The serial number of the nft sent by the same index at sender. |
Mints an amount of the token to the defined treasury account.
ABI Version: 2
Param | Type | Description |
---|---|---|
token |
address | The Hedera token to mint. The address is a mapping of shard.realm.number (0.0.x) into a 20 byte Solidity address. |
amount |
|
Applicable to FUNGIBLE TOKENS ONLY. |
metadata |
bytes[] memory | Applicable to NON-FUNGIBLE TOKENS ONLY. |
Burns an amount of the token from the defined treasury account.
ABI Version: 2
Param | Type | Description |
---|---|---|
token |
address | The token to burn. 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. |
serialNumbers |
int64[] | Applicable to NON-FUNGIBLE TOKENS ONLY. The list of serial numbers to be burned. |
Associates the provided account with the provided tokens. Must be signed by the account that is being associated with the token.
ABI Version: 2
Param | Type | Description |
---|---|---|
account |
address | The 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. |
token |
address[] memory | The list of tokens to be associated with the provided account.
|
Dissociates the provided account with the provided token. Must be signed by the provided Account's key.
ABI Version: 2
Param | Type | Description |
---|---|---|
account |
address | The Hedera account to be dissociated from the provided token. |
token |
address | The token to be dissociated from the provided account. |
Dissociates the provided account with the provided token. Must be signed by the account the token is being dissociated from.
ABI Version: 2
Param | Type | Description |
---|---|---|
account |
address | The account to be dissociated from the provided tokens |
tokens |
address[] memory | The list of tokens to be dissociated from the provided account. |
{% content-ref url="../../../core-concepts/smart-contracts/gas-and-fees.md" %} gas-and-fees.md {% endcontent-ref %}
{% content-ref url="../../../getting-started/try-examples/deploy-a-contract-using-the-hedera-token-service.md" %} deploy-a-contract-using-the-hedera-token-service.md {% endcontent-ref %}