VeChain Docs
  • Welcome to VeChain
  • Blockchain Basics
    • Introduction to blockchain
    • Introduction to digital property
    • The evolution of the internet
  • Introduction to VeChain
    • About the VeChain blockchain
      • Consensus Deep Dive
      • Governance
    • Dual-Token Economic Model
      • VeChain (VET)
      • VeThor (VTHO)
    • Acquire VeChain Assets
    • Sustainability
  • Core Concepts
    • Networks
      • Thor Solo Node
      • Testnet
      • Mainnet
    • Nodes
      • Node Rewards Programme
    • Blocks
      • Block Model
    • Transactions
      • Transaction Model
      • Transaction Fees
      • Transaction Calculation
      • Meta Transaction Features
        • Transaction Uniqueness
        • Controllable Transaction Lifecycle
        • Clauses (Multi-Task Transaction)
        • Fee Delegation
          • Multi-Party Payment (MPP)
          • Designated Gas Payer (VIP-191)
        • Transaction Dependency
    • Block Explorers
    • Wallets
      • VeWorld
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync2
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync
        • User Guide
          • Wallet
          • Ledger Device
          • Browser dApps and web
          • Interact with dApps
          • Activities
          • Settings
          • Report an Issue
          • Contributing
        • FAQ
    • EVM Compatibility
      • VeChain Modifications
      • Methodology
      • Test Coverage
        • Gas model
        • Raw transaction
        • hardhat specific
          • Ganache failures
          • evm_increaseTime
        • Failures in constructor
        • eth_sign
        • Contract address prediction
        • BadBeacon proxy address at 0x1
      • How to Recreate
      • Additional Information
        • Using Governance Contracts
        • ERC1820/ERC777 Testnet
        • Delegate Options
    • Account Abstraction
      • UserOperation
      • Bundler
      • EntryPoint Contract
      • Account Factory Contract
      • Paymaster Contract
    • Token Bound Accounts
  • How to run a node
    • Nodes
    • How to run a Thor Solo Node
    • Custom Network
    • Connect Sync2 to a Thor Solo Node
  • Developer Resources
    • Getting Started
    • How to build on VeChain
      • Connect to the Network
      • Read Data
        • Read Blocks
        • Read Transactions
        • Read Accounts
        • States & Views
        • Events & Logs
        • VET Transfers
      • Write Data
        • Transactions
        • Fee Delegation
      • Listen to Changes
        • Events
        • VET Transfers
        • Transactions
        • Blocks
        • Beats
      • Build with Hardhat
      • Utilities
        • BigInt and Unit-Handling
        • Name Service Lookups
    • Example dApps
      • Buy me a Coffee
      • Token Bound Accounts
      • PWA with Privy and Account Abstraction
    • EVM Compatibility for Developers
      • Key Architectural Differences and Optimizations
      • Practical Implications for Developers: Key Considerations
      • RPC Methods (Detailed Breakdown)
      • Frequently Asked Questions (FAQs)
      • VeChain Blockchain Specifications
      • Key Differences Between VeChain and Ethereum (Summary)
      • Best Practices for Developing on VeChainThor
    • How to verify Address-Ownership
      • Next.js Session Verification
    • Debug Reverted Transactions
    • Account Abstraction
    • VIP-191: Designated Gas Payer
      • How to Integrate VIP-191 (I)
      • How to Integrate VIP-191 (II)
      • How to Integrate VIP-191 (III)
    • Index with Graph Node
      • Setup with Docker
      • Index with OpenZeppelin
        • Create Subgraph Project
        • Configure Contracts
        • Deploy Subgraph and start Indexing
        • Track Subgraph Indexing
        • Access Subgraph
        • Update Subgraph
    • SDKs & Providers
      • SDK
        • Architecture
        • Accounts
        • Bloom Filter
        • Certificates
        • Contracts
        • Cryptography
        • Debug
        • Encoding
        • Polls
        • Subscriptions
        • Thor Client
        • Transactions
      • Thor DevKit
        • Installation
        • Usage
          • Cryptography
          • Accounts
          • Encoding
          • Transactions
          • Certificates
          • Bloom Filter
      • DApp Kit
        • v2
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
        • v1
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
          • Node Polyfills
          • V0 to V1
        • v0
          • Installation
          • Usage
          • React
            • Installation
            • Usage
          • Vanilla (UI)
            • Installation
            • Usage
          • Styles (UI)
          • i18n
      • DevPal
      • Web3-Providers-Connex
        • Installation
        • Usage
      • Connex
        • Installation
        • API Specification
    • Frameworks & IDEs
      • Hardhat
      • Remix
    • Built-in Contracts
    • VORJ
    • Useful Links
  • How to contribute
Powered by GitBook
On this page
  • Setup Hardhat
  • Setup
  • Install Hardhat Plugin
  • Configure
  • OpenZeppelin Contracts
  • Install
  • Create a ERC20 Token
  • Deployment Contract
  • Example

Was this helpful?

  1. Developer Resources
  2. How to build on VeChain

Build with Hardhat

Hardhat is a development environment to compile, deploy, test, and debug your EVM-compatible applications. It helps developers manage and automate the recurring tasks inherent to the process of building smart contracts, as well as easily integrating with various plugins to extend its functionality. With Hardhat, you can write and run tests, script deployments, and interact with your contracts.

VeChain's SDK provides a plugin to instantly enable connectivity.

The example project is relying on hardhat version 2.22.15 and the project initiated with npx hardhat init.

Setup Hardhat

Setup

To bootstrap a hardhat project:

npm install --save-dev hardhat
npx hardhat init

Install Hardhat Plugin

To add VeChain support, install the hardhat plugin:

npm install --save-dev @vechain/sdk-hardhat-plugin

Configure

Import or require the plugin in your hardhat.config.ts file:

import '@vechain/sdk-hardhat-plugin'

Add a network for TestNet or MainNet:

  1. The Hardhat plugin requires vechain in the network's name.

  2. Remote accounts are unsupported; therefore, provide account information.

Configure the solidity compile to Paris (or version that VeChain is compatible with)

A fully functional example configuration with:

  • defined accounts to use

  • fee delegation using vechain energy

  • networks for mainnet, testnet, solo and hardhard

import { type HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import '@vechain/sdk-hardhat-plugin';
import { HDKey } from '@vechain/sdk-core';
import { type HttpNetworkConfig } from 'hardhat/types';

// account to use
const accounts = ['0x2422eb37a0046d42e3c8d05c7d972de7fe1bb805e90b3a0dbc7d12b4d444c634']


const config: HardhatUserConfig = {
	solidity: {
		compilers: [
			{
				version: '0.8.20', // Specify the first Solidity version
				settings: {
				// Additional compiler settings for this version
					optimizer: {
					enabled: true,
					runs: 200
					},
				evmVersion: 'paris'
				}
			}
		]
	},
	networks: {

		/**
		* Example Mainnet configuration
		* No fee delegation
		*/
		vechain_mainnet: {
			// Mainnet
			url: 'https://mainnet.vechain.org',
			accounts,
			debug: false,
			gasPayer: undefined,
			gas: 'auto',
			gasPrice: 'auto',
			gasMultiplier: 1,
			timeout: 20000,
			httpHeaders: {}
		} satisfies HttpNetworkConfig,

		/**
		* Example Testnet configuration
		* With gasPayer url for fee delegation
		* Here a mnemonic is used to specify accounts
		*/
		vechain_testnet_gas_payer_url: {
			// Testnet
			url: 'https://testnet.vechain.org',
			accounts: {
				mnemonic:
					'vivid any call mammal mosquito budget midnight expose spirit approve reject system',
				path: HDKey.VET_DERIVATION_PATH,
				count: 3,
				initialIndex: 0,
				passphrase: 'vechainthor'
			},
			debug: true,
			gasPayer: {
				gasPayerServiceUrl:
					'https://sponsor-testnet.vechain.energy/by/269'
			},
			enableDelegation: true,
			gas: 'auto',
			gasPrice: 'auto',
			gasMultiplier: 1,
			timeout: 20000,
			httpHeaders: {}
		} satisfies HttpNetworkConfig,

		/**
		* Thor solo network configuration
		* Thor solo can be used for local deployment and testing
		*/
		vechain_solo: {
			// Thor solo network
			url: 'http://localhost:8669',
			accounts: [
			'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158'
			],
			debug: false,
			enableDelegation: false,
			gasPayer: undefined,
			gas: 'auto',
			gasPrice: 'auto',
			gasMultiplier: 1,
			timeout: 20000,
			httpHeaders: {}
		} satisfies HttpNetworkConfig,

		/**
		* Default hardhat network configuration
		*/
		hardhat: {
			accounts: {
				mnemonic:
					'vivid any call mammal mosquito budget midnight expose spirit approve reject system',
				path: HDKey.VET_DERIVATION_PATH,
				count: 3,
				initialIndex: 0

			},
			debug: true,
			gasPayer: undefined,
			gas: 'auto',
			gasPrice: 'auto',
			gasMultiplier: 1,
			timeout: 20000,
			httpHeaders: {}

		}

	}

};

export default config;

OpenZeppelin Contracts

Install

Install contract libraries and Hardhat helpers:

npm install --save @openzeppelin/contracts @openzeppelin/contracts-upgradeable @openzeppelin/hardhat-upgrades

Create a ERC20 Token

Create contracts/GLDToken.sol and save this example:

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;


// Importing the ERC20 contract from OpenZeppelin
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// Defining the GLDToken contract which inherits from ERC20
contract GLDToken is ERC20 {

	// Constructor to initialize the token with an initial supply
	// `initialSupply` is the amount of tokens that will be created at deployment

	constructor(uint256 initialSupply) ERC20("Gold", "GLD") {

		// Mint the initial supply of tokens and assign them to the contract deployer
		_mint(msg.sender, initialSupply);

	}
}

Run the following command to compile your contract:

npx hardhat compile

Deployment Contract

Create a deployment script in deploy/MyToken.ts:

import { ethers } from 'hardhat';

  
async function main(): Promise<void> {
	const erc20Contract = await ethers.deployContract('GLDToken', [100000]);
	await erc20Contract.waitForDeployment();
	const address = await erc20Contract.getAddress();
	console.log(`Gold contract deployed with address: ${address}`);
}

  
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
	console.error(error);
	process.exitCode = 1;
});

To execute the deploy script, specifying the network to deploy to:

npx hardhat deploy --network vechain_testnet_gas_payer_url

If a contract changes, deployment will automatically take place.

Example

PreviousBeatsNextUtilities

Last updated 2 months ago

Was this helpful?

Bootstrap your smart contract creation with contracts. A compilation of widely used standards and patterns can significantly speed up the development process.

provides an easy-to-use web interface for generating basic smart contracts.

With , deployments can be managed automatically without tracking the addresses of deployed contracts or manually upgrading contracts.

The status of deployments is stored in deployments/<network name>. Check out to learn more about its features and best practices.

The above steps are available in an example project with the SDK repository:

OpenZeppelin
https://wizard.openzeppelin.com
hardhat-deploy
hardhat-deploy
Example App