Ethereum
Last updated
Last updated
This README guides you through setting up a local Ethereum network using Hardhat, deploying an ERC20 token, and performing token and ETH transfers.
Node.js (v12.0.0 or later)
npm (usually comes with Node.js)
Clone the wallet-test-tools repo
Install the dependencies
Navigate to the eth directory and install the dependencies:
To start your local Ethereum network:
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
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.
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:
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:
A utility class for testing Ethereum transactions and smart contracts, designed to work with local Ethereum networks like Hardhat.
Here's a quick example of how to use EthTester:
EthTester
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
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 address
opts.amount
: Amount of Ether to send
sendToken(opts)
Sends ERC20 tokens to an address
opts.address
: Recipient's Ethereum address
opts.amount
: Amount of tokens to send
getNewAddress()
Returns the Ethereum address associated with the configured private key
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:
For more detailed information, refer to the .