Intro to VeChain
II. Deploying the Contract
Compile and deploy your contract to VeChain using the preconfigured Hardhat setup.
Hardhat on VeChain
You will use Hardhat to compile and deploy the smart contract to VeChain. The Hardhat project is already configured in the example repository with network settings for VeChain’s Solo, Testnet, and Mainnet.
Run Hardhat’s compile task to ensure the Solidity code compiles without errors:
This uses the Solidity compiler specified in your Hardhat config (for example, Solidity 0.8.17). It will output the contract’s ABI and bytecode into the ./packages directory. A successful compilation is required before deployment.
Note:
If everything is already compiled, you may see a message like "Nothing to compile". That’s totally fine, it just means there have been no changes since the last compilation.
You have a few options:
VeChain Thor Solo (local node): Ideal for development and testing without using real networks. If you have Docker, you can launch a Solo node easily. Make sure it’s running on localhost:8669 and that your wallet is connected to it (VeWorld allows adding a custom network pointing to the Solo node URL and port). Solo node gives you a private blockchain and typically comes funded with some test VET/VTHO.
Setting up a Solo node goes beyond the scope of this course, but you can learn more about it in the official VeChain Documentation.
VeChain Testnet: To test on a public test network, you’ll need a funded testnet wallet (use the faucet as mentioned earlier) and network config for the testnet RPC. VeWorld has Testnet available in its network list by default (or you can add it)
VeChain Mainnet: This is for production deployment. Mainnet requires real VET/VTHO and typically should be done only after thorough testing. (You’ll focus on Solo and Testnet here)
Your hardhat.config.ts should look like this. The snippet above can be found on apps/contracts/hardhat.config.ts
The example project uses environment variables for private keys. You may use your wallet's mnemonic.
Make sure the deploying account’s private key is provided so Hardhat can sign the deployment transaction. Never share your private keys, and use a test key for testnet.
In the repository’s apps/contracts/scripts directory, you’ll find a deployment script (e.g. deploy.ts). This script uses Hardhat’s runtime environment to deploy the compiled smart contract.
Example deploy script:
You can run the script in testnet with the following command:
Hardhat will compile the contract (if not already compiled), then send the transaction. If you're deploying with a private key, it signs the transaction automatically.
After deployment, Hardhat will print the contract address; make sure to copy it, you'll need it to connect the frontend (although this process is done automatically in this example app).
It’s a good idea to verify that the contract is deployed and functioning correctly:
Check the contract’s balance (on testnet explorer or by calling eth_getBalance via Hardhat). It should be 0 initially, since no tips have been sent yet.
Test calling getSales(). It should first return an empty array.
If using Solo, you can test buyCoffee via the Hardhat console or a small script to confirm it works.
If you followed all the steps, your smart contract is now live on VeChain!
In the next module, you’ll find an in-depth lesson with more details about the smart contract. It's encouraged to go through the contract details to fully understand the basics of this process.
Join our Telegram