Overview
The Chainlink Functions Demo App is designed to run on the Mumbai testnet (Polygon). It uses Chainlink Functions. The functionality allows users to donate POL to their favorite GitHub creators. Authors of those repositories can then claim their donations. Donations are made in an amount of POL per amount of Stars the repository has.
Chainlink Functions is used to determine the total donation amount by multiplying the POL amount by the star count. There's no back-end involved in the whole donation process.
Objective
You will create and manage a ledger contract to be used by the dApp. Tracking interaction between accounts gives a better insight into how the dApp functions. Using a different wallet for contract creation and dApp usage is preferable.
Before you begin
Before you start this tutorial, complete the following items:
- If you are new to smart contract development, learn how to Deploy Your First Smart Contract.
- Set up a cryptocurrency wallet such as MetaMask.
- To deploy this contract on testnets, ensure the deployer account has testnet ERC-677 LINK. Use the LINK faucet to retrieve testnet LINK.
- Get testnet POL from faucet.polygon.technology to pay for your onchain transactions.
- Get at least 2 ERC-677 testnet LINK from faucets.chain.link/mumbai.
- Install Node.js.
- Install pnpm:
npm install -g pnpm - Optional: If you want to verify your contracts onchain, create an account on Polygonscan and get an API key. Note that you'll need to create an account for the main network, which also works for the testnet.
Steps to implement
Run these from the project directory where you've cloned this repo.
-
Clone the repo and change directories:
git clone https://github.com/smartcontractkit/chainlink-functions-demo-app.git && cd chainlink-functions-demo-app -
Install the dependencies using
pnpm:pnpm install -
Create a
.envfile from the template:cp .env.example .env -
In the
.envfile specify the following variables:PRIVATE_KEY- Private key of your wallet used for deploying contracts.NEXT_PUBLIC_GA_TRACKING_ID- Optional - Set to your Google Analytics tracking id to enable GA.POLYGONSCAN_API_KEY- Optional - API key for Polygonscan to verify and read contracts.
-
Generate and build all required files:
pnpm build -
Deploy the Ledger contract:
npx hardhat project:deploy -
The deployment script prints the deployed contract address to your terminal. Add the address in the
NEXT_PUBLIC_CONTRACT_ADDRESSenvironment variable to your.envfile. -
Optionally, you can verify the contract. This allows you to decode the bytecode on Polygonscan. Verify the contract with
npx hardhat verify:npx hardhat verify --constructor-args arguments.js $NEXT_PUBLIC_CONTRACT_ADDRESSReplace
$NEXT_PUBLIC_CONTRACT_ADDRESSwith your contract address if you don't have the address in your shell environment. -
Create a Chainlink Functions subscription and fund it using the
project:fundscript:npx hardhat project:fundFor more information on how to manage your subscription, read the official documentation.
-
Store the subscription ID in the
NEXT_PUBLIC_SUBSCRIPTION_IDenvironment variable in your.envfile.
Run the example
-
Run the dev server:
pnpm dev -
In the terminal output, you'll see a URL with a port number. Open this URL in your browser to see the UI running locally.