Choose-your-own-Adventure: Mint and Transfer tokens the EVM way and the Hedera-native way.
- Create a fungible token in Javascript using Hedera Token Service (HTS).
- Create an ERC20 token in Solidity using Hedera Smart Contract Service (HSCS).
- Discover how these 2 services can interoperate.
This is a hands-on session - all you need are a browser and a github account.
Watch video demonstrations walking through each task in this tutorial!
- Task (0) - Set up
- Task (1) - HTS FungibleCommon Token
- Task (2) - HSCS ERC20 Token
- Task (3) - Interoperability between HSCS and HTS
- Task (4) - Summary and Tear Down
This repo contains the code required for several different ways to create and transfer tokens on Hedera.
Detailed instruction for each of the tasks are provided here:
- Task (0) - Set up
- Task (1) - HTS FungibleCommon Token
- Task (2) - HSCS ERC20 Token
- Task (3) - Interoperability between HSCS and HTS
- Task (4) - Summary and Tear Down
Tasks (1), (2), and (3) may be completed in any order - choose your own adventure! If you are not familiar with web3/ EVM development, you are recommended to do task (1) right after task (0). If you are already familiar with web3/ EVM development, you are recommended to do task (2) right after task (0).
Alternatively, you may find summary instructions below
- Click on the "run on Gitpod" button above.
- Wait for Gitpod to load, this should take less than 10 seconds
- In the VS code terminal, you should see 3 terminals,
get_deps
,rpcrelay_run
, andmain
- You do not need to use the
get_deps
andrpcrelay_run
terminals, let them run in the background - In the
main
terminal, which is the one that displays by default, a script will interactively prompt you - Congratulations, you can now move on to the sequences! 🎉
What you will accomplish:
- Answer interactive prompts in a terminal to construct a
.env
file - Generate accounts using a BIP-39 seed phrase (optional)
- Fund one of those accounts using the Hedera Testnet Faucet (optional)
Steps:
- “Enter a BIP-39 seed phrase”
- “Enter a number of accounts to generate from your BIP-39 seed phrase”
- Leave blank to accept the default, which is to generate several accounts.
- “Enter your preferred JSON-RPC endpoint URL”
- Leave blank to accept the default,
- This value defaults to something that matches the patterns
https://7546-*.gitpod.io/
- “Enter your operator account private key”
- Leave blank to accept the default, is to use the first account generated from the seed phrase from earlier.
- Note that this needs to be an ECDSA secp256k1 private key, and it should be in hexadecimal encoded format
- “Please ensure that you have funded ${EVM_ADDRESS}”
- The value of
${EVM_ADDRESS}
will be0x
followed by hexadecimal characters - copy this value to your clipboard. - If you are using this EVM address for the first time, you will need to fund it. Otherwise just hit
[return]
right away, and move to the next step. - In a new browser window/ tab, visit
faucet.hedera.com
. - Paste the address into the text input field, press the “receive” button, pass the captcha challenge, press the “confirm” button, and wait for the transaction to complete.
- Switch back to the browser window/ tab with Gitpod running in it.
- Hit the
[return]
key
- The value of
- “Do you wish to overwrite the .env file with the above?”
- Type “y”, and hit the
[return]
key
- Type “y”, and hit the
- Open the
.env
file, and check that it has been updated.
What you will accomplish:
In this task, you will deploy a new fungible token on Hedera Token Service, and transfer it from one account to another. You will be using the Hedera SDK, and use Javascript. No Solidity or smart contracts necessary!
Steps:
cd token-hts
./script
[tab] [return]- Initial output
- Configuring new HTS token
- Transaction for new HTS token
- Configuring token association
- Submitting token association transaction
- Configuring token transfer
- Submitting token transfer transaction
- Summary metrics
What you will accomplish:
In this task, you will deploy a new fungible token on Hedera Token Service, and transfer it from one account to another. You will be using the Hedera SDK, and use Javascript. No Solidity or smart contracts necessary!
Steps:
cd token-hscs
npm run compile-smart-contract
./script
[tab] [return]- Initial output
- Checking Solidity smart contract source code
- Loading EVM bytecode + ABI (solc outputs)
- Checking JSON-RPC endpoint liveness
- Submit EVM transaction over RPC to deploy bytecode
- Submit EVM transaction over RPC to transfer token balance
- Submit EVM request over RPC to query token balance
- Summary metrics
What you will accomplish:
In this task, you will use the fungible token that you have previously deployed to Hedera Token Service, and interact with it via Hedera Smart Contract Service. You will be using viem and JSON-RPC to interact with the token, with interoperability provided through the HTS system contract.
Steps:
cd token-interop
./script
[tab] [return]- Reminder: Complete both the "tokenHts" and "tokenHscs" tasks before running this script
- Initial output
- Obtain EVM address of existing HTS fungible token
- Loading ABI (solc outputs)
- Checking JSON-RPC endpoint liveness
- Submit EVM transaction over RPC to transfer HTS token balance (HSCS interoperability)
- Submit EVM request over RPC to query token balance
- Summary metrics
- In the root dir of the existing demo repo, run
npm run update-from-base-template
- This copies several files from the base template into your existing demo repo
- See the implementation in
util/09-npx-bin.js
in the base template repo for the exact list of files that are copied
- Be sure to review all
diff
s prior to committing git commit
- The output of
npm run update-from-base-template
will include a suggested commit message
- The output of
git push
to your new git remote (your new repo)- Follow the steps in the tutorial above, and verify that the tutorial is functional in Gitpod.
- If there are are issues encountered on Gitpod that do not occur on your computer
- Investigate to find the underlying cause, and fix it
- Then reiterate to test if this has been resolved
MIT