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).
npm install
npm run compilenpm testUses the deployer as the sustainability verifier (for testing only):
npm run deploy:local-
Set environment variables (never commit these):
PRIVATE_KEY– deployer wallet private key (hex, no0xprefix 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.001ETH)
-
Deploy:
npm run deploy- (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).
- The sustainability verifier is the address set at deploy (
SUSTAINABILITY_VERIFIER_ADDRESS). Only signatures from this address are accepted byclaimWithSustainabilityData. - 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 equalssustainabilityVerifierand that the claim (by message hash) has not been used (replay protection). - For local/testing, you can set
SUSTAINABILITY_VERIFIER_ADDRESSto a test wallet and use that wallet’s key in the signing 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 11155111The output is the signature hex to pass to claimWithSustainabilityData(amount, nonce, claimType, signature).
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.
- Deploy the contract (local or Sepolia) and note the contract address.
- Run the UI:
cd frontend
npm install
npm run dev- 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).
- 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.