Skip to content

Instantly share code, notes, and snippets.

@cblanquera
Created June 28, 2021 05:02
Show Gist options
  • Save cblanquera/43c54a75bc65caef42f3b112ecf672dd to your computer and use it in GitHub Desktop.
Save cblanquera/43c54a75bc65caef42f3b112ecf672dd to your computer and use it in GitHub Desktop.

1. Signup for Alchemy

Alchemy is a remote version of an Ethereum Node. Sign up and create an app. https://www.alchemy.com/

2. Load up some Ethereum

Switch your metamask to ropsten network and get some ETH from the faucet.

3. Connecting MetaMask to the project

$ npm init -y
$ npm i dotenv --save

Add a .env file

METAMASK_PRIVATE_KEY = "yourMetamaskPrivateKey"
API_URL = "https://eth-ropsten.alchemyapi.io/v2/your-api-key"

Get your metamask private key by opening up the MetaMask extension, click the three dots in the top right, and select the Account Details option. Next, click the Export Private Key button. Enter your password to see your private key, then copy it.

Get your alchemy key by going to your app (that you just created above).

4. Install Hard Hat

Hardhat let's you test smart contracts locally without deploying. Alternatives are truffle, brownie, embark, etherlime.

$ npm install --save-dev hardhat && npx hardhat
> Create a sample project

Edit hardhat.config.js

// Load the .env to memory
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");

// Itemize out the .env variables
const { API_URL, METAMASK_PRIVATE_KEY } = process.env;

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
   defaultNetwork: "ropsten",
   networks: {
      hardhat: {},
      ropsten: {
         url: API_URL,
         accounts: [`0x${METAMASK_PRIVATE_KEY}`]
      }
   },
   solidity: {
    version: "0.8.4",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
   paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts"
  },
  mocha: {
    timeout: 20000
  }
};

5. Test the Vanilla Build

$ npx hardhat run scripts/sample-script.js --network ropsten

Compiling 2 files with 0.7.3
Compilation finished successfully
Greeter deployed to: 0x1234567890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment