HTS x EVM - Part 2: KYC & Update
In Part 1 of the series, you saw how to mint, transfer, and burn an NFT using Hedera'a EVM and Hedera Token Service (HTS) System Smart Contracts. In this guide, you’ll learn the basics of how to configure / permission native Hedera Tokens via a Smart Contract. Specifically, you will learn how to:
Create and configure an NFT.
Grant and revoke a Know Your Customer (KYC) flag.
Update the KYC key with an Admin (to rotate compliance keys, for example)
Prerequisites
ECDSA account from the Hedera Portal.
Basic understanding of Solidity.
Table of Contents
Step 1: Project Setup
Clone the repository
Install dependencies
Create
.env
file set up environment variables
Edit the .env
file to include your Hedera Testnet account's private key. Use your ECDSA Hex Encoded Private Key when interacting with Hedera's EVM via the JSON-RPC relay.
Run the test script
This script deploys and tests all of the functionality inside the KYCandUpdateNFT
Smart Contract. We'll deep dive into the Smart Contract's functions and corresponding tests below!
Step 2. Creating an NFT
Function: createNFT(string memory name, string memory symbol, string memory memo)
createNFT(string memory name, string memory symbol, string memory memo)
Purpose: Deploy an HTS non-fungible token (NFT) via a Solidity contract call to HederaTokenService.createNonFungibleToken
.
Key Code Snippet:
Test Implementation:
We call createNFT(...)
and expect it to emit an NFTCreated
event with a valid token address.
Step 3. Minting an NFT
The previous tutorial covered minting NFTs. Nothing's changed, but if you want a deep dive into how it's done, check it out there!
HTS x EVM - Part 1: How to Mint NFTsStep 4. Granting KYC
Function: grantKYC(address account)
grantKYC(address account)
Purpose: Enable KYC for a specific account. If a token is configured to enforce KYC, that account must be “granted” KYC before it can receive or send the token.
Key Code Snippet:
Test Implementation:
Without this step, the account won’t be able to receive or transact the NFT.
Step 5. Revoking KYC
Function: revokeKYC(address account)
revokeKYC(address account)
Purpose: Disable KYC for a specific account. After revocation, that account can no longer receive or transfer the token.
Key Code Snippet:
Test Implementation:
Step 6. Transferring NFTs and Enforcing KYC
Function: transferNFT(address receiver, uint256 serialNumber)
Purpose: Transfer an NFT from the treasury (address(this)
) to another account. The receiving account must have KYC because this token has a KYC key.
Key Code Snippet:
Test Implementation:
The first test expects the transfer to fail when KYC hasn’t been granted.
The second test demonstrates a successful transfer once grantKYC(...)
has been called.
Step 7. Updating the KYC Key
Function: updateKYCKey(bytes memory newKYCKey)
Purpose: Change the KYC key on the token. This could be a “key rotation” to maintain compliance or to assign another entity control over KYC status.
Key Code Snippet:
Test Implementation:
After this key rotation, the contract's key is no longer able to perform KYC operations. In the snippet above, we immediately demonstrate that KYC attempts signed by the contract itself will revert.
Account 1 will now be able to grant/revoke KYC using the SDK.
Token Association in the Tests
Because we’re using a hybrid approach of EVM and the Native Hedera Token Service, you’ll see special logic to:
Associate the newly created token with the signers’ accounts (via
TokenAssociateTransaction
).Fetch the signers’ Hedera account IDs from EVM addresses with
AccountId.fromEvmAddress(...)
.Use the
PrivateKey.fromStringECDSA
call to instantiate a Hedera client for executing SDK transactions.
This is due to a nuance: In order to grant KYC to an account, it must have the token associated with it. This is the case even if the account has unlimited auto associations.
Conclusion
Using a Solidity Smart Contract on Hedera, you can replicate many of the native HTS functionalities—granting and revoking KYC, updating token keys, minting and transferring NFTs—while retaining the benefit of contract-driven logic and on-chain state. This approach may be preferable if:
You want advanced business logic in a self-contained contract.
You prefer standard Solidity patterns and tooling for your Web3 workflows.
You plan to modularize or integrate your token behavior with other smart contracts.
Check out Part 3: How to Pause, Freeze, Wipe, and Delete NFTs to learn more about configuring Native Tokens with Smart Contracts.
HTS x EVM - Part 3: How to Pause, Freeze, Wipe, and Delete NFTsAdditional Resources
Check out our GitHub repo to find the full contract and Hardhat test scripts, along with the configuration files you need to deploy and test on Hedera!
Last updated
Was this helpful?