Ethereum
Setting up a Local Ethereum Network with Hardhat
This README guides you through setting up a local Ethereum network using Hardhat, deploying an ERC20 token, and performing token and ETH transfers.
Table of Contents
Prerequisites
Node.js (v12.0.0 or later)
npm (usually comes with Node.js)
Installation
Clone the wallet-test-tools repo
Install the dependencies
Navigate to the eth directory and install the dependencies:
Project Structure
Setting Up the Local Network
To start your local Ethereum network:
For more detailed information, refer to the Hardhat documentation.
This command will start a local Ethereum network and display a list of available accounts with their private keys.
Keep this terminal window open while working with your local network.
IMPORTANT: closing this process will reset your blockchain, you would need to redo any transactions you may have done
Deploying the ERC20 Token
To deploy your ERC20 token to the local network:
This script will deploy your ERC20 token and output the contract address. Make note of this address for future use.
Performing ERC20 Token Transfers
To transfer ERC20 tokens:
Replace <recipient-address>
with the Ethereum address you want to send tokens to, and <amount>
with the number of tokens to send.
Example:
Performing ETH Transfers
To transfer ETH:
Replace <recipient-address>
with the Ethereum address you want to send ETH to, and <amount>
with the amount of ETH to send.
Example:
๐งช EthTester Class
A utility class for testing Ethereum transactions and smart contracts, designed to work with local Ethereum networks like Hardhat.
๐ Table of Contents
๐ง Usage
Here's a quick example of how to use EthTester:
๐ API
EthTester
EthTester
Constructor
new EthTester(config)
config.uri
: (optional) The Ethereum node URI (default: 'http://127.0.0.1:8545/')config.privateKey
: (optional) The private key to use for transactions
Methods
init()
Initializes the connection to the Ethereum network
mine(opts)
Mines new blocks
opts.blocks
: (optional) Number of blocks to mine (default: 1)
sendToAddress(opts)
Sends Ether to an address
opts.address
: Recipient's Ethereum addressopts.amount
: Amount of Ether to send
sendToken(opts)
Sends ERC20 tokens to an address
opts.address
: Recipient's Ethereum addressopts.amount
: Amount of tokens to send
getNewAddress()
Returns the Ethereum address associated with the configured private key
โ๏ธ Configuration
EthTester uses a configuration file erc20.config.json
for ERC20 token details. Ensure this file is present in the same directory with the following structure:
Last updated