Skip to content

Commit

Permalink
Merge branch 'main' into bsilagani/main
Browse files Browse the repository at this point in the history
  • Loading branch information
zeuslawyer committed Mar 27, 2024
2 parents f66775e + 1b8dd75 commit c1eac6c
Show file tree
Hide file tree
Showing 13 changed files with 2,176 additions and 149 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ Install **both** of the following:
- Node.js version [20](https://nodejs.org/en/download/)
- Deno version [1.36](https://deno.land/[email protected]/getting_started/installation) (or the latest release of Deno v1 if a later one is available)

## Steps on live testnet
## Steps on Live (Public) Testnets

1. Clone this repository to your local machine<br><br>
1. Clone this repository to your local machine<br><br>. Also ensure that the testnet your wanting to deploy on is [supported](https://docs.chain.link/chainlink-functions/supported-networks) by Chainlink Functions.
2. Open this directory in your command line/terminal app, then run `npm install` to install all dependencies.<br><br>
3. Obtain the values for following environment variables:
3. Obtain the values for following environment variables (examples only - please see `./env.enc.example` for env vars you may need):
- `PRIVATE_KEY` for your development wallet - `POLYGON_MUMBAI_RPC_URL`, `ETHEREUM_SEPOLIA_RPC_URL`, or `AVALANCHE_FUJI_RPC_URL`
- `POLYGONSCAN_API_KEY`, `ETHERSCAN_API_KEY`, or `FUJI_SNOWTRACE_API_KEY` blockchain explore API keys depending on which network you're using
- `COINMARKETCAP_API_KEY` (from [here](https://pro.coinmarketcap.com/))
<br><br>
4. Set the required environment variables. For improved security, Chainlink provides the NPM package [@chainlink/env-enc](https://www.npmjs.com/package/@chainlink/env-enc) which can be used to keep environment variables in a password encrypted `.env.enc` file instead of a plaintext `.env` for additional security. More detail on environment variable management and the tooling is provided in the [Environment Variable Management](#environment-variable-management) section.
4. Set the required environment variables (see `./env.enc.example` for the correctly capitalized names of environment variables used in this repo). For improved security, Chainlink provides the NPM package [@chainlink/env-enc](https://www.npmjs.com/package/@chainlink/env-enc) which can be used to keep environment variables in a password encrypted `.env.enc` file instead of a plaintext `.env` for additional security. More detail on environment variable management and the tooling is provided in the [Environment Variable Management](#environment-variable-management) section.
1. Set an encryption password for your environment variables to a secure password by running `npx env-enc set-pw`. This password needs to be set each time you create or restart a terminal shell session.<br>
2. Use the command `npx env-enc set` to set the required environment variables.
3. Set any other values you intend to pass into the _secrets_ object in _Functions-request-config.js_ .<br><br>
Expand Down Expand Up @@ -124,6 +124,8 @@ This repo uses the NPM package `@chainlink/env-enc` for keeping environment vari

By default, all encrypted environment variables will be stored in a file named `.env.enc` in the root directory of this repo. This file is `.gitignore`'d.

For a full list of the Env Var names (keys) that this repo uses and has defined please look at `./env.enc.example`.

First, set the encryption password by running the command `npx env-enc set-pw`.

> **NOTE:** On Windows, this command may show a security confirmation.
Expand Down Expand Up @@ -377,6 +379,13 @@ Additionally, you can manually set a hardcoded transaction gas price in the Hard

# Troubleshooting

1. When running Chainlink Functions make sure your subscription ID has your consumer contract added as an authorized consumer. Also make sure that your subscription has enough LINK balance. You do this by calling `npx hardhat functions-sub-info --network network_name_here --subid subscription_id_here`
1. If you get strange (and scary large) error output in your terminal because a transaction failed, it is super helpful to use [tenderly.co](https://tenderly.co). Once you create an account, and a project look for "Transactions" in the tab list on the left, and past in your Transaction Hash. Tenderly will look across various networks for it. It will then show you the causes for the error especially if the contract has been verified. Here is a useful video on how to debug transactions with Tenderly:
<iframe width="360" height="215" src="https://www.youtube.com/embed/90GN9Ut8LhU?si=iLhHegpG1Mq59qtJ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

2. When running Chainlink Functions make sure your subscription ID has your `FunctionsConsumer` contract added as an authorized consumer. Also make sure that your subscription has enough LINK balance. You do this by calling `npx hardhat functions-sub-info --network network_name_here --subid subscription_id_here` to see your subscription details. If the Functions Router calculates that your subscription's balance is insufficient it will revert with a `InsufficientBalance` custom Solidity error.

3. When running Chainlink Functions with Automation you also need to ensure the Chainlink Automation upkeeps are funded to run the automation calls. The fastest way to maintain your Automation LINK subscription balance is through the Chainlink Automation web app here: [https://automation.chain.link/](https://automation.chain.link/)

4. If you get a transaction failure when calling `npx hardhat functions-request` and its an out of gas error (you can tell from the block explorer or from [Tenderly](https://tenderly.co)) then you may need to add the optional `---requestgaslimit` flag with a value higher than than the default which is 1_500_000. For example: `npx hardhat functions-request --requestgaslimit 1750000`. Note that `./tasks/Functions-consumer/request.js` already has some logic around this that applies to some networks that require higher gas.

2. When running Chainlink Functions with Automation you also need to ensure the Chainlink Automation upkeeps are funded to run the automation calls. The fastest way to maintain your Automation LINK subscription balance is through the Chainlink Automation web app here: [https://automation.chain.link/](https://automation.chain.link/)
5. <b>BASE Sepolia / Optimism Sepolia:</b> if you see an error like `ProviderError: transaction underpriced: tip needed 50, tip permitted 0` then wait a few seconds and re-try. This can happen due to network spikes. Also double check the `./networks.js` file configs to make sure that `gasPrice` is set to `1000_000` as these networks can require higher request gas.
5 changes: 3 additions & 2 deletions contracts/AutomatedFunctionsConsumer.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol";
import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/FunctionsClient.sol";

import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsRequest.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol";
import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol";

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/FunctionsConsumer.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol";
import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/FunctionsClient.sol";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsRequest.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol";

/**
* @title Chainlink Functions example on-demand consumer contract example
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/LinkToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.24;
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.4/LinkToken.sol";
import "@chainlink/contracts/src/v0.8/shared/token/ERC677/LinkToken.sol";
4 changes: 2 additions & 2 deletions contracts/test/MockV3Aggregator.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.7/tests/MockV3Aggregator.sol";
import "@chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol";
20 changes: 20 additions & 0 deletions env.enc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// The following environment variables are used in this example repo. When setting
// them using the npm env-enc package, please make sure you use the same names and casing for the
// keys, as this codebase uses them as follows.
// Reference: https://github.com/smartcontractkit/functions-hardhat-starter-kit?tab=readme-ov-file#environment-variable-management

GITHUB_API_TOKEN
PRIVATE_KEY
SECOND_PRIVATE_KEY
ETHEREUM_SEPOLIA_RPC_URL
ETHERSCAN_API_KEY
POLYGONSCAN_API_KEY
POLYGON_MUMBAI_RPC_URL
AVALANCHE_FUJI_RPC_URL
BASESCAN_API_KEY
ARBITRUM_RPC_URL
ARBISCAN_API_KEY
OPTIMISM_API_KEY
OPTIMISM_SEPOLIA_RPC_URL
BASE_SEPOLIA_RPC_URL
COINMARKETCAP_API_KEY
28 changes: 28 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,35 @@ module.exports = {
avalancheFujiTestnet: networks.avalancheFuji.verifyApiKey,
arbitrum: networks.arbitrum.verifyApiKey,
arbitrumSepolia: networks.arbitrumSepolia.verifyApiKey,
baseSepolia: networks.baseSepolia.verifyApiKey,
optimismSepolia: networks.optimismSepolia.verifyApiKey,
},
customChains: [
{
network: "arbitrumSepolia",
chainId: 421614,
urls: {
apiURL: "https://api-sepolia.arbiscan.io/api",
browserURL: "https://sepolia.arbiscan.io/",
},
},
{
network: "baseSepolia",
chainId: 84532,
urls: {
apiURL: "https://api-sepolia.basescan.org/api",
browserURL: "https://sepolia-explorer.base.org",
},
},
{
network: "optimismSepolia",
chainId: 11155420,
urls: {
apiURL: "https://api-sepolia-optimistic.etherscan.io/api", // https://docs.optimism.etherscan.io/v/optimism-sepolia-etherscan
browserURL: "https://sepolia-optimistic.etherscan.io/",
},
},
],
},
gasReporter: {
enabled: REPORT_GAS,
Expand Down
40 changes: 38 additions & 2 deletions networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (SECOND_PRIVATE_KEY) {
const networks = {
ethereum: {
url: process.env.ETHEREUM_RPC_URL || "UNSET",
gasPrice: undefined,
gasPrice: undefined, // gas price for the functions request - default's to auto as per HH https://hardhat.org/hardhat-network/docs/reference#eth_gasprice
nonce: undefined,
accounts,
verifyApiKey: process.env.ETHERSCAN_API_KEY || "UNSET",
Expand Down Expand Up @@ -98,7 +98,7 @@ const networks = {
},
polygonMumbai: {
url: process.env.POLYGON_MUMBAI_RPC_URL || "UNSET",
gasPrice: 20_000_000_000,
gasPrice: 20_000_000_000, // gas price for the functions request
nonce: undefined,
accounts,
verifyApiKey: process.env.POLYGONSCAN_API_KEY || "UNSET",
Expand Down Expand Up @@ -167,6 +167,42 @@ const networks = {
"https://02.functions-gateway.testnet.chain.link/",
],
},
baseSepolia: {
url: process.env.BASE_SEPOLIA_RPC_URL || "UNSET", // https://docs.basescan.org/v/sepolia-basescan/
gasPrice: undefined,
nonce: undefined,
accounts,
verifyApiKey: process.env.BASESCAN_API_KEY || "UNSET",
chainId: 84532,
confirmations: DEFAULT_VERIFICATION_BLOCK_CONFIRMATIONS,
nativeCurrencySymbol: "ETH",
linkToken: "0xE4aB69C077896252FAFBD49EFD26B5D171A32410",
linkPriceFeed: "0x56a43EB56Da12C0dc1D972ACb089c06a5dEF8e69", // https://docs.chain.link/data-feeds/price-feeds/addresses?network=base&page=1
functionsRouter: "0xf9B8fc078197181C841c296C876945aaa425B278",
donId: "fun-base-sepolia-1",
gatewayUrls: [
"https://01.functions-gateway.testnet.chain.link/",
"https://02.functions-gateway.testnet.chain.link/",
],
},
optimismSepolia: {
url: process.env.OPTIMISM_SEPOLIA_RPC_URL || "UNSET", // https://docs.optimism.io/chain/networks#op-sepolia
gasPrice: undefined,
nonce: undefined,
accounts,
verifyApiKey: process.env.OPTIMISM_API_KEY || "UNSET",
chainId: 11155420,
confirmations: DEFAULT_VERIFICATION_BLOCK_CONFIRMATIONS,
nativeCurrencySymbol: "ETH",
linkToken: "0xE4aB69C077896252FAFBD49EFD26B5D171A32410",
linkPriceFeed: "0x98EeB02BC20c5e7079983e8F0D0D839dFc8F74fA", //https://docs.chain.link/data-feeds/price-feeds/addresses?network=optimism&page=1#optimism-sepolia
functionsRouter: "0xC17094E3A1348E5C7544D4fF8A36c28f2C6AAE28",
donId: "fun-optimism-sepolia-1",
gatewayUrls: [
"https://01.functions-gateway.testnet.chain.link/",
"https://02.functions-gateway.testnet.chain.link/",
],
},
// localFunctionsTestnet is updated dynamically by scripts/startLocalFunctionsTestnet.js so it should not be modified here
localFunctionsTestnet: {
url: "http://localhost:8545/",
Expand Down
Loading

0 comments on commit c1eac6c

Please sign in to comment.