Flare users can now view their onchain carbon emissions, and offset them with Toucan carbon credits
Prize Pool
LayerGreen is a platform designed to measure and offset the carbon footprint generated by blockchain transactions. Users input an EVM-compatible wallet address, initially supporting the Flare Network, to view a dashboard.
This dashboard displays the wallet's transaction history, estimated carbon emissions based on gas usage, and the user's existing balance of Toucan Protocol's Nature Carbon Tonne (NCT) tokens on Polygon.
The core functionality allows users to offset their calculated emissions with a single action. This offsetting process involves a cross-chain transfer of funds (USDC) from the Flare Network to Polygon, where these funds are then automatically used to acquire NCT carbon credits. All acquired NCT balances are reflected on the dashboard for user verification. The project aims to provide a clear and verifiable method for individuals to address their on-chain environmental impact.
LayerGreen is composed of three interconnected repositories: CarbonOffset (frontend), CarbonHardhat (Flare smart contracts), and carbonswap (Polygon smart contracts).
The frontend (CarbonOffset) is built with Next.js, React, and TypeScript, styled with Tailwind CSS. It uses Privy for wallet connection and authentication, and Viem/Wagmi for blockchain interaction. TanStack Query manages state and data fetching, while GSAP provides an animated background. This frontend fetches transaction data from the Flare Network's public explorer API (Blockscout). Off-chain logic then calculates the estimated carbon footprint. The frontend also queries the Polygon blockchain to display the user's NCT balance.
When a user initiates an offset, the process involves two core smart contract repositories. CarbonHardhat contains the Solidity contracts deployed on the Flare Network. Specifically, MinimalFlareUSDTBridge.sol is used to bridge assets. It receives USDC from the user (or another contract), then utilizes LayerZero's OFT standard and Stargate's infrastructure to transfer these USDC tokens from Flare to a designated address on Polygon. This contract incorporates functions for estimating LayerZero messaging fees in native FLR.
This was a noteworthy hack: The destination address on Polygon is the TokenSwapComposer.sol contract from the carbonswap repository. This contract, written in Solidity and built with Foundry, implements LayerZero's ILayerZeroComposer interface. Its lzCompose function acts as the entry point for LayerZero messages. Upon receiving the bridged USDC and an associated compose message (which includes the original sender and target recipient for the NCT), it automatically executes a swap. This is done by directly interacting with a Uniswap V2-like DEX router (QuickSwap) on Polygon. The received USDC is swapped for NCT tokens, which are then sent to the original user's specified recipient address on Polygon. This entire multi-chain, multi-step process is orchestrated atomically across chains using LayerZero's composability features. Dependencies used include OpenZeppelin contracts, LayerZero's OApp/Protocol V2 libraries, and Stargate's OFT contracts. Blockscout is integrated for transaction history display and verification on both Flare and Polygon.