The Hedera JSON RPC Relay enables developers to use their favorite EVM-compatible tools such as Truffle, Hardhat, Web3JS, EthersJS, to deploy and interact with smart contracts on the Hedera network. As highlighted in a previous article, the relay provides applications and tools seamless access to Hedera while masking implementation complexities and preventing reductions in performance, security, and scalability.
This tutorial shows you how to deploy smart contracts on Hedera using Truffle and the JSON RPC Relay with the following steps:
- Create an account that has ECDSA keys using the Javascript SDK
- Compile a contract using Truffle
- Deploy the smart contract to Hedera network through the JSON RPC Relay
You can find more examples using Truffle, Web3JS, and Hardhat in this GitHub repository.
Try It Yourself
- Get a Hedera testnet account
- This Codesandbox is already setup for you to try this example
- Fork the sandbox
- Remember to provide your testnet account credentials for the operator in the .env file
- Open a new terminal and run:
- npm install -g truffle (this installation may take a few minutes)
- node create-account.js
- Get the example code from GitHub
1. Grab Your ECDSA Keys from the Hedera Portal
Hedera supports two popular types of signature algorithms, ED25519 and ECDSA. Both are used in many blockchain platforms including Bitcoin and Ethereum. Currently, the JSON RPC Relay only supports Hedera accounts with an alias set (i.e. public address) based on its ECDSA public key.
To deploy a smart contract using Truffle, go to the Hedera portal, create a free Testnet account (if you haven't already), and copy the HEX Encoded Private Key for your account with ECDSA keys. Next, paste that value into the ETH_PRIVATE_KEY variable in the .env file (if you cloned the repository, you may need to rename the file from .env_sample to .env).
IMPORTANT NOTE: Private keys for Testnet are displayed here for educational purposes only. Never share your private key(s) with others, as that may result in lost funds, or loss of control over your account.
In case you’re interested in more details about auto account creation and alias, check out the documentation and HIP-32.