
Prerequisites
- Get a Hedera Testnet account here.
- Set up your environment and create a client here.
Get the example code on GitHub:
Get the example code on GitHub:
Table of Contents
- Create Treasury Account
- Create FTs and NFT Collection
- Create Bob’s ECDSA Public Key Alias
- Return New Account ID
Create Treasury Account
We create the treasury account, which will be the holder of the fungible and non-fungible tokens. The treasury account will be created with an initial balance of 5 HBAR.Set Up Helper Functions
We will create the functions necessary to create a new account, create fungible tokens, and create a new NFT collection. Use the tabs to see the helper functions.Create FTs and an NFT Collection
Leverage the createFungibleToken helper function defined above to create 10000 “Hip-542 example” fungible tokens. Use the code tab switch on the upper left of the code block to see how we use createNewNftCollection to create our new NFT collection consisting of 5 NFTs.Create Bob’s ECDSA Public Key Alias
An alias is an initial public key that will convert into a Hedera account through auto-account creation. An alias consists of <shard>.<realm>.<bytes>. To learn more about accounts created via an account alias go here.
Set up helper functions for transferring HTS tokens
Once we have our treasury account with FT and a new NFT collection created, our next step is to transfer them to Bob using their alias. We’ll create the sendToken helper function to send fungible tokens and create transferNft to send a single NFT. A quick reminder to use the tab on the left of the code block to switch between the two helper functions.Transfer FT and an NFT to Bob using their alias
Transfer 5 fungible tokens to Bob using their alias and the helper function sendToken. Transfer the NFT with serial number 1 to Bob using the helper function transfertNFT.Return New Account ID
Create a helper function to return the corresponding account Id to the given an alias.
Show Bob’s new account owns the 5 FT tokens
Complete an AccountBalanceQuery to show that Bob’s new account owns the 5 fungible tokens the treasury account sent.
Show Bob’s new account owns the NFT
First, create a helper function that creates a TokenNftInfoQuery transaction and returns the account id of the NFT owner for a specific NFT serial number.
Console Output ✅
