Overview
HTS exposes a system contract at address 0x0000000000000000000000000000000000000167 implementing IHederaTokenService functions callable from user contracts (HTS system contract).
When to use this skill
- Orchestrating HTS mint/associate/transfer inside contract logic.
- Auditing hook/reentrancy interactions introduced by HIP-1195-style allowance behaviors.
Prerequisites
- Working Hardhat → Hashio setup (
hedera-smart-contract-evm). - Correct conversion between token ID / account ID and EVM address representations — validate utilities before production.
Workflow
Import official interface ABI from Hashgraph samples or vendor packages — demo uses contracts/IHederaTokenServiceMinimal.sol.
Route calls through address
HederaPrecompileAddresses.HTS.Decode response codes — success vs failure enums differ from raw
requirechecks; production code must branch on returnedint64.Reentrancy — external calls to HTS may invoke token hooks; treat like external calls in Checks-Effects-Interactions ordering.
Security history — read references/precompile-vuln-taxonomy.md for classes of failures including the 2023 HTS allowance incident.
Deploy demo: scripts/precompile-deploy.cjs.
Examples
Example 1
“Associate my contract’s callers with token X.”
Usually wrong pattern — association targets accounts, not transient callers; prefer explicit associate flows.
Example 2
“Mint inside contract after deposit.”
Ensure supplyKey authorizations align with contract-controlled keys or delegated signatures.
Example 3
“Why did ERC-20 transfer behave differently than HTS?”
ERC-20 facade paths still obey HTS association/KYC rules under the hood.
Troubleshooting
| Issue | Tip |
|---|---|
INVALID_TOKEN_ID |
Address conversion incorrect |
| Unexpected hook recursion | Audit HIP-1195 interactions |
References
- Local: references/precompile-addresses.md, references/precompile-vuln-taxonomy.md, references/solidity-htst-examples.md