Build with Hardhat
Last updated
Was this helpful?
Was this helpful?
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;npm install --save @openzeppelin/contracts @openzeppelin/contracts-upgradeable @openzeppelin/hardhat-upgrades// 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);
}
}npx hardhat compileimport { 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;
});npx hardhat deploy --network vechain_testnet_gas_payer_url