This project demonstrates a setup using Hardhat, a development environment to compile, deploy, test, and debug Ethereum software. It includes various smart contracts such as HelloWorld
, Lock
, MultiSigExample
, MyGovernor
, and VotingToken
.
HelloWorld
: A simple contract that stores a greeting and allows it to be changed.Lock
: A time-locked contract that only allows withdrawals after a certain date.MyGovernor
: A governance contract based on OpenZeppelin's Governor contract.VotingToken
: An ERC20 token that supports voting with additional extensions.MultiSig
: A contract that enables multi-signature transaction approval for increased security and control, requiring multiple signatures from confirmed owners before executing transactions.
Clone the repository and install dependencies:
git clone <repository-url>
cd hardhat-example
npm install
Compile the contracts:
npx hardhat compile
Deploy the contracts to the desired network:
npx hardhat run scripts/deploy_hello_world.js --network <network-name>
The scripts
directory contains JavaScript files that are used to deploy and interact with the smart contracts.
Run the test suite with:
npx hardhat test
The ignition
directory includes modules and deployment scripts for contract deployment orchestration.
Configure your environment variables in a .env
file and update the hardhat.config.js
as needed.
This project is unlicensed and free for anyone to use.## Command History
Below are the commands used throughout the project's lifecycle:
npx hardhat init
: Initialize a new Hardhat project.npx hardhat accounts
: List available accounts.npx hardhat compile
: Compile the smart contracts.npx hardhat run <script>
: Run a script to deploy contracts or interact with them.npx hardhat test
: Run the contract tests.npx hardhat node
: Start a local Ethereum node.npx hardhat vars set <key> <value>
: Set an environment variable for the project.npx hardhat size-contracts
: Output the size of the compiled contracts.npx hardhat ignition <command>
: Use Hardhat Ignition for advanced deployment scripting.
HelloWorld.sol
: Demonstrates a basic contract with a greeting variable that can be read and set.Lock.sol
: Implements a locking mechanism that restricts withdrawals to after a certain time.MyGovernor.sol
: An example of a governance contract that interacts with a voting token for proposal voting.VotingToken.sol
: An ERC20 token that includes voting capabilities, used with the MyGovernor contract for governance.MultiSig.sol
: Facilitates a multi-signature wallet that requires multiple confirmations for transactions, enhancing security and control.
Multi-Signature (MultiSig) Wallets are integral to the Ethereum ecosystem, enhancing security and governance capabilities by requiring multiple approvals before executing any transaction. These wallets are particularly useful for managing complex operations such as executing ERC20 token functions, for example, minting new tokens, which demand a high level of security and consensus among stakeholders.
-
Initiating a Transaction Proposal: Transactions in a MultiSig typically start with an owner proposing an action through a method
submitTransaction
. For instance, to mint new ERC20 tokens, an owner would prepare and submit a transaction proposal by encoding the mint function along with its intended parameters. This stage sets the foundation for a secure and consensual operation within the blockchain framework.Function: submitTransaction Parameters: - destination address (address of the ERC20 token contract) - value (typically 0 for token minting calls) - data (encoded function, e.g., the mint function and its parameters)
The transaction is then logged with a unique ID, facilitating traceability and reference in the confirmation process.
-
Confirmation by Multiple Owners: The proposal must be confirmed according to predetermined wallet configurations, typically by a minimum number of wallet owners. These owners review and approve the transaction using the
confirmTransaction
function by citing the transaction ID.Function: confirmTransaction Parameters: - transactionId (uint): ID of the transaction that requires confirmation.
In essence, this step reinforces the security by ensuring multiple validations on the proposed action. After the required number of confirmations is reached, the transaction is automatically executed, reflecting the consensus-driven operation of MultiSig Wallets.
-
Automated Execution upon Meeting Confirmation Requirements: One of the pivotal features of MultiSigs is the automatic execution of transactions once they receive the requisite number of confirmations. This streamlined feature ensures that actions, like minting tokens, are carried out efficiently without the need for manual intervention once approval consensus is achieved.
To securely manage private keys in your Hardhat project, it's recommended to use environment variables rather than hardcoding them in your hardhat.config.js
file. This approach keeps sensitive information out of your source code.
- Open the Start menu and search for 'Environment Variables'.
- Click on 'Edit the system environment variables'.
- In the System Properties window, click 'Environment Variables'.
- Click 'New' under the 'System variables' section.
- Enter
AURORIA_PRIVATE_KEY
andHOLESKY_PRIVATE_KEY
as the variable names and your respective private keys as the values.
- Open your terminal.
- Edit your shell's profile file (e.g.,
~/.bash_profile
,~/.zshrc
, etc.) with a text editor. - Add the following lines to set your environment variables:
export AURORIA_PRIVATE_KEY="your_auroria_private_key_here" export HOLESKY_PRIVATE_KEY="your_holesky_private_key_here"
- Save the file and run
source ~/.bash_profile
(or equivalent) to apply the changes.
In your hardhat.config.js
, reference these environment variables as follows:
const AURORIA_PRIVATE_KEY = process.env.AURORIA_PRIVATE_KEY;
const HOLESKY_PRIVATE_KEY = process.env.HOLESKY_PRIVATE_KEY;
module.exports = {
// Configuration details
networks: {
auroria: {
accounts: [AURORIA_PRIVATE_KEY],
// Other network configurations
},
holesky: {
accounts: [HOLESKY_PRIVATE_KEY],
// Other network configurations
},
},
// Other configurations
};