Salud Capital
Internal Dev Guide

Smart Contract Environment Setup  ·  April 2026
Developer Operations · Step-by-Step Reference · Salud Capital LLC

Polygon Smart Contract Dev Environment — Complete Setup Guide

Everything needed to go from zero to a deployed Hardhat smart contract on Polygon Amoy testnet. Covers Git Bash, private keys, .env configuration, Polygonscan API, faucet funding, wallet address retrieval, and deployment. Built from the actual Salud Vault setup session April 2026.

Hardhat + TypeScript Polygon Amoy Testnet Git Bash on Windows Node.js v24+ OpenZeppelin v5
Table of Contents
01Prerequisites & Tools
06hardhat.config.ts Reference
02Project Directory & Shell
07Get Your Wallet Address
03Create the .env File
08Fund with Amoy MATIC (Faucet)
04Private Key Setup
09Deploy to Polygon Amoy
05Polygonscan API Key
10Troubleshooting Reference

01   Prerequisites & Tools

What You Need Installed Before Starting

ToolVersionWhere to GetNotes
Node.jsv20+ (v24 confirmed)nodejs.orgIncludes npm automatically
Git + Git BashAny recentgit-scm.comUse Git Bash, NOT PowerShell
VS CodeAny recentcode.visualstudio.comFor editing .env and config files
Hardhatv2 (npm install)hardhat.orgInstalled per-project, not globally
⚠ Always Use Git Bash — Never PowerShell

PowerShell handles paths and Node.js commands differently and causes Hardhat errors. Right-click your project folder in Windows Explorer and select "Git Bash Here" to open it in the right directory automatically. All commands in this guide assume Git Bash.

02   Project Directory & Shell

Finding and Navigating to Your Hardhat Project

Key Fact
Claude Code Desktop creates projects inside a worktree subdirectory
The Salud Vault Hardhat project lives at:

C:\Users\Admin\Documents\ai coding\salud\.claude\worktrees\romantic-morse

Future Claude Code projects will be in a similar .claude\worktrees\[branch-name] path. Check the Claude Code conversation for the exact branch name if starting a new project.
Navigate to the project in Git Bash
# Git Bash uses forward slashes and /c/ instead of C:\
cd "/c/Users/Admin/Documents/ai coding/salud/.claude/worktrees/romantic-morse"

# Confirm you are in the right place
ls
# You should see: hardhat.config.ts  package.json  contracts/  scripts/  test/  .env
Path Format Differences Between Shells

PowerShell: C:\Users\Admin\Documents\ai coding\salud

Git Bash: /c/Users/Admin/Documents/ai coding/salud

Always use the Git Bash format (forward slashes, /c/). Wrap paths with spaces in double quotes.

03   Create the .env File

Environment File — Your Keys Live Here

The .env file stores private keys and API keys. It must be in the same folder as hardhat.config.ts. The project ships with a .env.example template — copy it to create your real file.

Create .env from the example template
# Copy the template
cp .env.example .env

# Verify it exists
ls -la | grep .env
# Should show: .env  and  .env.example

# Open in VS Code to fill in your keys
code .env
Complete .env file — fill in every value
# Wallet (see Section 04 for formatting rules)
PRIVATE_KEY=yourprivatekeyhere64charsno0xprefix

# Polygon RPC Endpoints
POLYGON_AMOY_RPC_URL=https://rpc-amoy.polygon.technology
POLYGON_MAINNET_RPC_URL=https://polygon-rpc.com

# Block Explorer Verification (see Section 05)
POLYGONSCAN_API_KEY=yourapikeyfrometherscan

# Alchemy (optional but more reliable than public RPC)
ALCHEMY_AMOY_URL=https://polygon-amoy.g.alchemy.com/v2/yourkey
ALCHEMY_MAINNET_URL=https://polygon-mainnet.g.alchemy.com/v2/yourkey
⚠ Add .env to .gitignore Immediately

Run this right after creating your .env file. If a private key is ever pushed to GitHub, consider that wallet compromised — generate a new one immediately.

echo ".env" >> .gitignore
cat .gitignore    # verify .env appears in the list
How to Know .env Is Loading Correctly

Every Hardhat command prints a confirmation line. Look for:

◇ injected env (8) from .env  —  the number must be greater than 0

If you see injected env (0), your .env is missing from the current folder. Fix it with: cp "/c/Users/Admin/Documents/ai coding/salud/.env" .

04   Private Key Setup

Getting and Correctly Formatting Your Private Key

⚠ Use a Dedicated Dev Wallet — Never Your Main Wallet

Create a separate wallet exclusively for development. It holds testnet MATIC only. Never store a private key in a file on your computer for a wallet that holds real funds.

Where to Get Your Private Key

MetaMask: Account menu → Export Private Key

Or Hardhat generates one during project setup. The key is a 64-character hex string that looks like random letters and numbers.

Formatting Rules — Critical

Remove the 0x prefix if present
No quotes around the value
No spaces around the = sign
Exactly 64 characters long
Hardhat adds 0x automatically

Correct format in .env
# WRONG - has 0x prefix
PRIVATE_KEY=0xabc123yourkeyhere

# CORRECT - raw 64-char hex, no prefix
PRIVATE_KEY=abc123yourkeyhere64characterstotal

05   Polygonscan API Key

Generating Your Etherscan / Polygonscan API Key

Since mid-2025 Etherscan uses a unified API key across all chains. One key works for Polygon Amoy testnet, Polygon mainnet, Ethereum, and others.

Step by Step
How to Generate the Key at etherscan.io
  1. Go to etherscan.io and create an account
  2. Verify your email (check inbox — required before API keys appear)
  3. Log in fully, then go to etherscan.io/myapikey
  4. Click the "Add" button at the top right of the API Keys table
  5. Name it anything — e.g. SaludVault
  6. Click "Create New API Key"
  7. Copy the 34-character key from the table
Can't See the API Keys Table?

You must verify your email first. Check your inbox for the Etherscan confirmation email. Unverified accounts cannot access API key generation. Make sure you are fully logged in, not just registered. X (Twitter) login also works if you prefer.

Paste key directly into .env — no quotes, no angle brackets
# WRONG - angle brackets are just placeholders, remove them entirely
POLYGONSCAN_API_KEY=<your_api_key_here>

# CORRECT - raw key value right after the equals sign
POLYGONSCAN_API_KEY=ABC123DEF456youractualkey

06   hardhat.config.ts Reference

The Complete Working Config for Salud Vault

Network Name Is polygonAmoy — Not amoy

The network is named polygonAmoy (camelCase). Using --network amoy throws HH100 error. Always use --network polygonAmoy in every command.

hardhat.config.ts — complete working configuration
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as dotenv from "dotenv";
dotenv.config();

// Accepts private key with or without 0x prefix
function normalizeKey(pk: string | undefined): string[] {
  if (!pk || pk.trim() === "") return [];
  const trimmed = pk.trim();
  return [trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`];
}

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.28",
    settings: {
      optimizer: { enabled: true, runs: 200 },
      evmVersion: "cancun",
    },
  },
  networks: {
    hardhat: {},
    polygonAmoy: {                    // always use this exact name
      url: process.env.POLYGON_AMOY_RPC_URL || "https://rpc-amoy.polygon.technology",
      accounts: normalizeKey(process.env.PRIVATE_KEY),
      chainId: 80002,
      gasPrice: "auto",
    },
    polygon: {
      url: process.env.POLYGON_MAINNET_RPC_URL || "https://polygon-rpc.com",
      accounts: normalizeKey(process.env.PRIVATE_KEY),
      chainId: 137,
    },
  },
  etherscan: {
    apiKey: {
      polygonAmoy: process.env.POLYGONSCAN_API_KEY || "",
      polygon:     process.env.POLYGONSCAN_API_KEY || "",
    },
    customChains: [{
      network: "polygonAmoy",
      chainId: 80002,
      urls: {
        apiURL:     "https://api-amoy.polygonscan.com/api",
        browserURL: "https://amoy.polygonscan.com",
      },
    }],
  },
  sourcify: { enabled: true },
};

export default config;

07   Get Your Wallet Address

Retrieving Your Deployer Address from the Private Key

Your private key and your wallet address are two different things. The address is public (safe to share with the faucet). The private key is secret. Hardhat derives the address from your key automatically.

Method 1 — Hardhat console (recommended)
# Open the Hardhat console
npx hardhat console --network polygonAmoy

# Type each line separately and press Enter after each
const [deployer] = await ethers.getSigners()
console.log(deployer.address)
# Prints: 0x742d35Cc6634C0532925a3b8D4C9C2...

# Exit the console when done
.exit
undefined After the First Line Is Normal

When you run const [deployer] = await ethers.getSigners() the console prints undefined. This is correct — it means the assignment worked with no return value. Type console.log(deployer.address) on the next line to see your address.

No MetaMask? No Problem

You do not need MetaMask. The Hardhat console derives your address directly from the private key in .env. MetaMask is optional for this workflow entirely.

08   Fund with Amoy MATIC (Faucet)

Getting Testnet MATIC from the Polygon Faucet

You need at least 1 MATIC on Polygon Amoy to pay gas for testnet deployments. The faucet gives 0.5 MATIC per request — submit twice to reach 1 MATIC.

Faucet Steps
faucet.polygon.technology
  1. Go to faucet.polygon.technology
  2. Log in with X (Twitter) — GitHub login gives a 404 (known issue, use X)
  3. Select Polygon Amoy from the network dropdown
  4. Paste your wallet address from Section 07 (the 0x... value)
  5. Click Submit — receive 0.5 MATIC
  6. Repeat once more to reach 1.0 MATIC total
⚠ Paste the ADDRESS — Not Your Private Key

The faucet wants your wallet address (~42 characters, starts with 0x, from Section 07). Your private key is 64 characters and is secret — never paste it anywhere except your .env file.

Verify MATIC arrived before deploying
npx hardhat console --network polygonAmoy

const [deployer] = await ethers.getSigners()
const bal = await ethers.provider.getBalance(deployer.address)
console.log(ethers.formatEther(bal))
# Should print "1.0" or "0.5" -- anything above 0 and you are ready

.exit

09   Deploy to Polygon Amoy

Running the Full Deploy Sequence

Complete deploy sequence — run in order
# 1. Navigate to project root
cd "/c/Users/Admin/Documents/ai coding/salud/.claude/worktrees/romantic-morse"

# 2. Compile all contracts
npx hardhat compile

# 3. Run the full test suite -- all tests should pass before deploying
npx hardhat test

# 4. Deploy to Amoy testnet
npx hardhat run scripts/deploy.ts --network polygonAmoy

# 5. Verify contracts on Polygonscan (paste the address printed by deploy)
npx hardhat verify --network polygonAmoy 0xYourDeployedContractAddress
Successful Deploy Output Looks Like This

◇ injected env (8) from .env
Deploying SaludTokens with account: 0x742d35...
SaludTokens deployed to: 0x8a3f91Dd7745D164...
SaludID deployed to: 0xB2c4e1Ff8834A297...
Deployment manifest saved to deployments/amoy.json

10   Troubleshooting Reference

Common Errors and Their Fixes

ErrorCauseFix
HH100: Network amoy doesn't existWrong network nameUse --network polygonAmoy (camelCase)
injected env (0) from .env.env missing from current foldercp "/c/Users/Admin/Documents/ai coding/salud/.env" .
Invalid address from private key0x prefix in PRIVATE_KEYRemove 0x from start of key in .env. Key = 64 chars.
command not found with bracketsPasted with rich text formattingType commands manually, do not paste. Brackets are paste artefacts.
Faucet GitHub login gives 404Known faucet OAuth issueUse X (Twitter) login instead — works reliably
ls is not defined in consoleRan bash command inside Node.js consoleType .exit first, then run bash commands
undefined after getSigners()Normal — not an errorAssignment worked. Run console.log(deployer.address) next.
hardhat.config.ts not foundWrong directoryNavigate to /c/Users/Admin/Documents/ai coding/salud/.claude/worktrees/romantic-morse
Insufficient funds for gasNo Amoy MATIC in walletfaucet.polygon.technology → X login → Polygon Amoy → 0.5 MATIC x2
PowerShell path errorsWrong shellSwitch to Git Bash. Right-click project folder → "Git Bash Here"

Pre-Deploy Checklist

  • .env exists in worktree root — ls -la | grep .env shows it
  • PRIVATE_KEY has no 0x prefix, is exactly 64 characters
  • POLYGONSCAN_API_KEY is set from etherscan.io/myapikey
  • POLYGON_AMOY_RPC_URL is set
  • Hardhat shows injected env (N) where N is greater than 0
  • Wallet address retrieved via Hardhat console (Section 07)
  • Wallet funded with at least 1 MATIC via Polygon Amoy faucet
  • npx hardhat compile runs with no errors
  • npx hardhat test passes all tests
  • .env is listed in .gitignore
  • Using Git Bash — not PowerShell
Quick Reference — Most-Used Commands

Navigate: cd "/c/Users/Admin/Documents/ai coding/salud/.claude/worktrees/romantic-morse"

Console: npx hardhat console --network polygonAmoy

Get address: const [d] = await ethers.getSigners(); console.log(d.address)

Check balance: console.log(ethers.formatEther(await ethers.provider.getBalance(d.address)))

Compile: npx hardhat compile

Test: npx hardhat test

Deploy: npx hardhat run scripts/deploy.ts --network polygonAmoy

Faucet: faucet.polygon.technology → X login → Polygon Amoy → paste wallet address