• Stars
    star
    209
  • Rank 188,325 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fully-fledged Hardhat project template based on TypeScript.

Fully-Fledged Hardhat Project Template Based on TypeScript

Test smart contracts License: MIT

Installation

It is recommended to install Yarn through the npm package manager, which comes bundled with Node.js when you install it on your system. It is recommended to use a Node.js version >= 18.0.0.

Once you have npm installed, you can run the following both to install and upgrade Yarn:

npm install --global yarn

After having installed Yarn, simply run:

yarn install

Running Deployments

Example Goerli:

yarn deploy:goerli

The deployment script deploy.ts includes the tenderly Hardhat Runtime Environment (HRE) extension with the verify method. Please consider uncommenting and configuring the Tenderly project, username, forkNetwork, privateVerification, and deploymentsDir attributes in the hardhat.config.ts file before deploying or remove this call. Also, for this plugin to function you need to create a config.yaml file at $HOME/.tenderly/config.yaml or %HOMEPATH%\.tenderly\config.yaml and add an access_key field to it. For further information, see here.

For the deployment on the zkSync Era test network, you must add your to-be-deployed contract artifact to deploy-zksync.ts, enable zksync in the hardhat.config.ts file, and then run yarn compile. Next, fund your deployer account on zkSync Era Testnet, configure your .env file accordingly, and simply run yarn deploy:zksynctestnet. Eventually, to verify the contract you can invoke: npx hardhat verify --network zkSyncTestnet --constructor-args arguments.js <YOUR_CONTRACT_ADDRESS>. The same approach applies if you want to deploy on the production network, except that you need to run yarn deploy:zksyncmain and use --network zkSyncMain for the contract verification.

Running CREATE2 Deployments

yarn xdeploy

This template uses the xdeploy Hardhat plugin. Check out the documentation for more information on the specifics of the deployments.

.env File

In the .env file, place the private key of your wallet in the PRIVATE_KEY variable. This allows secure access to your wallet to use with both testnet and mainnet funds during Hardhat deployments. For more information on how this works, please read the documentation of the npm package dotenv.

Using a Ledger Hardware Wallet

This template implements the hardhat-ledger plugin. In the .env file, place your Ledger account in the LEDGER_ACCOUNT variable.

Using the Truffle Dashboard

Truffle developed the Truffle Dashboard to provide an easy way to use your existing MetaMask wallet for your deployments and for other transactions that you need to send from a command line context. Because the Truffle Dashboard connects directly to MetaMask it is also possible to use it in combination with hardware wallets like Ledger or Trezor.

First, it is recommended that you install Truffle globally by running:

npm install -g truffle

If you have already installed Truffle, you need to ensure that you have at least version 5.11.3 installed and otherwise upgrade.

To start a Truffle Dashboard, you need to run the following command in a separate terminal window:

truffle dashboard

By default, the command above starts a Truffle Dashboard at http://localhost:24012 and opens the Dashboard in a new tab in your default browser. The Dashboard then prompts you to connect your wallet and confirm that you're connected to the right network. You should double check your connected network at this point, since switching to a different network during a deployment can have unintended consequences.

Eventually, in order to deploy with the Truffle Dashboard, you can simply run:

yarn deploy:dashboard

Mainnet Forking

You can start an instance of the Hardhat network that forks the mainnet. This means that it will simulate having the same state as the mainnet, but it will work as a local development network. That way you can interact with deployed protocols and test complex interactions locally. To use this feature, you need to connect to an archive node.

This template is currently configured via the hardhat.config.ts as follows:

forking: {
    url: process.env.ETH_MAINNET_URL || "",
    // The Hardhat network will by default fork from the latest mainnet block
    // To pin the block number, specify it below
    // You will need access to a node with archival data for this to work!
    // blockNumber: 14743877,
    // If you want to do some forking, set `enabled` to true
    enabled: false,
}

Contract Verification

Change the contract address to your contract after the deployment has been successful. This works for both testnet and mainnet. You will need to get an API key from etherscan, snowtrace etc.

Example:

npx hardhat verify --network fantomMain --constructor-args arguments.js <YOUR_CONTRACT_ADDRESS>

Contract Interaction

This template includes an example script that shows how to interact programmatically with a deployed contract. You must customise it according to your contract's specifications. The script can be simply invoked via:

npx hardhat run scripts/interact.ts --network <network_name>

Foundry

This template repository also includes the Foundry toolkit.

If you need help getting started with Foundry, I recommend reading the ๐Ÿ“– Foundry Book.

Dependencies

make update

or

forge update

Compilation

make build

or

forge build

Testing

To run only TypeScript tests:

yarn test:hh

To run only Solidity tests:

yarn test:forge

or

make test-forge

To additionally display the gas report, you can run:

make test-gasreport

Deployment and Etherscan Verification

Inside the scripts/ folder are a few preconfigured scripts that can be used to deploy and verify contracts via Foundry. These scripts are required to be executable meaning they must be made executable by running:

make scripts

More Repositories

1

reentrancy-attacks

A chronological and (hopefully) complete list of reentrancy attacks to date.
1,287
star
2

snekmate

State-of-the-art, highly opinionated, hyper-optimised, and secure ๐ŸVyper smart contract building blocks.
Solidity
493
star
3

xdeployer

Hardhat plugin to deploy your smart contracts across multiple EVM chains with the same deterministic address.
Solidity
434
star
4

createx

Factory smart contract to make easier and safer usage of the `CREATE` and `CREATE2` EVM opcodes as well as of `CREATE3`-based (i.e. without an initcode factor) contract creations.
Solidity
293
star
5

create2deployer

Helper smart contract to make easier and safer usage of the `CREATE2` EVM opcode.
TypeScript
274
star
6

malleable-signatures

This repository implements a simplified PoC that demonstrates how signature malleability attacks using compact signatures can be executed.
Solidity
105
star
7

ecdsa-nonce-reuse-attack

This repository implements a Python function that recovers the private key from two different signatures that use the same random nonce during signature generation.
Python
84
star
8

tornado-cash-exploit

This repository implements a simplified PoC that showcases how a contract can morph. A similar approach was used as part of the governance attack on Tornado Cash in May 2023.
Solidity
48
star
9

metatx

A smart contract to enable ERC-20 token meta-transactions on Ethereum.
JavaScript
45
star
10

escrow-contract

A simple multilateral escrow smart contract for ETH and ERC-20 tokens governed by Cobie.
TypeScript
37
star
11

raw-tx

Three scripts to ordinary generate, EIP-4844-type generate, and execute a signed raw transaction with `ethers`.
TypeScript
30
star
12

torn-detector

Detect if a contract has been deployed in the latest (or predefined) block from an address that was previously funded through Tornado.Cash.
TypeScript
22
star
13

solidity-games

A repository for Solidity-based smart contract games.
Solidity
21
star
14

meth

The moment you Rust, you should look for your Mojo ๐Ÿ”ฅ.
21
star
15

batch-distributor

Helper smart contract for batch sending both native and ERC-20 tokens.
TypeScript
20
star
16

p256-verifier-vyper

P256 (a.k.a. secp256r1 elliptic curve) signature verification ๐ŸVyper contract.
Vyper
19
star
17

create-util

Helper smart contract to make easier and safer usage of the `CREATE` EVM opcode.
TypeScript
19
star
18

mnemonic-to-private-key

A JavaScript script that converts the mnemonic phrase into a wallet private key using the ethers.js library.
JavaScript
15
star
19

ethereum-key-generation-python

Generating Ethereum addresses in Python.
Python
13
star
20

pcaversaccio

My public profile.
12
star
21

fork-testing-evm-compatibility

This repository implements a simple fork test on Optimism that proves that the EVM behaviour of the forked chain is not identically replicated locally.
Solidity
12
star
22

erc20-permit-upgradeable

Permit-enabled, upgradeable ERC20 smart contract template.
TypeScript
11
star
23

erc20-oz-sdk

How to deploy an ERC20 smart contract using OpenZeppelin SDK and write a TokenExchange smart contract.
Solidity
7
star
24

zksync-vyper-sandbox

A sandbox environment for ZKsync Era Vyper compiler testing.
TypeScript
7
star
25

mass-key-generation

A repository for mass public-private key generation (Bitcoin & Ethereum).
Java
7
star
26

tornado-cash-ether-withdrawal-decipherer

Deciphering the ether transactions in the Tornado.Cash withdrawals.
JavaScript
7
star
27

bitsquatting

Helper script for generating permutations of an ENS domain that differ by 1-bit from the original domain.
Python
7
star
28

gpg-sign-and-encrypt

This guide explains how to sign and encrypt an email using the `gpg` (GNU Privacy Guard) tool from the command line.
7
star
29

ethereum-key-generation

A repository that shows how to generate a private / public key pair using web3.js or HD wallets.
JavaScript
5
star
30

tokenbridge-helium-ethereum

A tokenbridge between the Helium blockchain (native network) and the Ethereum blockchain (foreign network).
4
star
31

chainlink-price-feed

Retrieve the ETH/USD price feed from Chainlink's oracle using Infura.
JavaScript
4
star
32

connection-vscode-to-google-colab-gpus

A step-by-step guide to connecting the local Visual Studio Code to Google Colab's GPU runtime.
4
star
33

pool-viewer

Similar to an ETH2 block explorer, but focused only on recent data.
2
star
34

pcaversaccio.github.io

My personal website.
HTML
2
star
35

payfoot-token-contract

This is PayFoot's ERC-20 smart contract, whose tokens are used as stablecoins in their ecosystem.
JavaScript
2
star
36

configurations

Monorepo for my personal configurations.
Shell
2
star
37

startfeld-token-contract

This is Startfeld's ERC-20 smart contract, whose tokens are used as vouchers in their ecosystem.
JavaScript
2
star
38

randao-distribution

Empirical distribution of the randomness beacon (=RANDAO) provided by the Beacon chain.
Python
2
star
39

porini-community-token-contract

This is Porini's ERC-20 smart contract, whose tokens can activate communities to support conservation activities and learn about blockchain technology.
JavaScript
2
star
40

impact-dollar-token-contract

This is Impact Dollar's ERC-20 smart contract, whose tokens can deliver a demonstrable contribution to conservation and protected areas through digital collectibles.
JavaScript
2
star
41

block-explorer-swissdlt

A block explorer for the Swiss DLT blockchain.
TypeScript
1
star
42

interface-solc-test

Solidity
1
star
43

saentis-gulden-token-contract

This is Sรคntis Gulden's ERC-20 smart contract, whose tokens are used as vouchers in their ecosystem.
JavaScript
1
star
44

ath-erc20-token

Smart contract of the Alethena (ATH) token.
1
star
45

telegram-group-counter

A simple Python script to check how many Telegram groups a user is in.
Python
1
star