Skip to content

aarnavnaga/GreenGold

Repository files navigation

GreenGold (GGC)

ERC-20 token with two ways to acquire: (1) purchase with ETH at a fixed price, (2) mint via oracle-verified sustainability data (signature-based, mini carbon-credit style).

Setup

npm install
npm run compile

Tests

npm test

Deployment

Local (Hardhat network)

Uses the deployer as the sustainability verifier (for testing only):

npm run deploy:local

Sepolia testnet

  1. Set environment variables (never commit these):

    • PRIVATE_KEY – deployer wallet private key (hex, no 0x prefix or with)
    • SUSTAINABILITY_VERIFIER_ADDRESS – address that will sign sustainability claims (can be an EOA or another wallet you control for testing)
    • Optional: SEPOLIA_RPC_URL (default: https://rpc.sepolia.org)
    • Optional: ETHERSCAN_API_KEY – for contract verification on Etherscan
    • Optional: INITIAL_SUPPLY – e.g. 1000000 (default: 1,000,000 tokens, 18 decimals)
    • Optional: TOKEN_PRICE_WEI – wei per token (default: 0.001 ETH)
  2. Deploy:

npm run deploy
  1. (Optional) Verify on Etherscan:
npx hardhat verify --network sepolia <CONTRACT_ADDRESS> <INITIAL_SUPPLY> <TOKEN_PRICE_WEI> <SUSTAINABILITY_VERIFIER_ADDRESS>

Use the same constructor args as in your deploy (e.g. initial supply and token price as raw wei/ether values).

Verifier key handling (sustainability oracle)

  • The sustainability verifier is the address set at deploy (SUSTAINABILITY_VERIFIER_ADDRESS). Only signatures from this address are accepted by claimWithSustainabilityData.
  • The verifier runs off-chain (script or backend). It receives claim data (e.g. renewable energy or emissions proof), checks it, then signs the claim so the user can submit it on-chain.
  • Never commit the verifier’s private key. Use env vars or a secrets manager. The verifier key should be stored and used only on the server/script that issues signatures.
  • The signed message is: keccak256(abi.encodePacked(claimant, amount, nonce, claimType, chainId)), with the standard Ethereum signed-message prefix. The contract checks that the signer equals sustainabilityVerifier and that the claim (by message hash) has not been used (replay protection).
  • For local/testing, you can set SUSTAINABILITY_VERIFIER_ADDRESS to a test wallet and use that wallet’s key in the signing script.

Signing a sustainability claim (verifier script)

Use the helper script to produce a signature for a claim (for testing or as a reference for your backend):

PRIVATE_KEY=<verifier_private_key> node scripts/signClaim.js <claimant_address> <amount_wei> <nonce> <claimType> [chainId]

Example (Sepolia chainId 11155111):

PRIVATE_KEY=0x... node scripts/signClaim.js 0x1234... 1000000000000000000 1 0 11155111

The output is the signature hex to pass to claimWithSustainabilityData(amount, nonce, claimType, signature).

Frontend (UI)

A React app in frontend/ lets you connect a wallet, view GGC balance and token price, buy with ETH, claim with a sustainability signature, transfer, and burn.

  1. Deploy the contract (local or Sepolia) and note the contract address.
  2. Run the UI:
cd frontend
npm install
npm run dev
  1. Open the URL (e.g. http://localhost:5173), paste the GreenGold contract address and click Save, then Connect wallet (MetaMask). Switch MetaMask to the same network you deployed to (e.g. Sepolia or Localhost 8545).
  2. Use Buy with ETH, Claim, Transfer, and Burn as needed. For Claim, get a signature from the repo root: PRIVATE_KEY=<verifier_key> node scripts/signClaim.js <your_address> <amount_wei> <nonce> <claimType> [chainId], then paste the hex into the signature field.

Optional: set VITE_CONTRACT_ADDRESS in frontend/.env to pre-fill the contract address.

About

ERC-20 token (GGC) with ETH purchase and oracle-verified sustainability claims (mini carbon credit). Solidity, Hardhat, Sepolia.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors