Skip to content

Commit

Permalink
Sepolia migration (#52)
Browse files Browse the repository at this point in the history
* Set Sepolia as default testnet instead of Goerli

* Chainlink Keepers is now Chainlink Automation
  • Loading branch information
andrejrakic authored Feb 8, 2023
1 parent f5a7516 commit 9547384
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 71 deletions.
72 changes: 39 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> NOTE: With Rinkeby and Kovan being deprecated, the new default is goerli.
> NOTE: The new default is Sepolia.
# chainlink-mix

Expand Down Expand Up @@ -28,7 +28,7 @@ You can also check out the more advanced Chainlink tutorials there as well.
- [Chainlink Price Feeds](#chainlink-price-feeds)
- [Chainlink VRF](#chainlink-vrf)
- [Chainlink API Call](#chainlink-api-call)
- [Chainlink Keeper Deployment](#chainlink-keeper-deployment)
- [Chainlink Automation Deployment](#chainlink-automation-deployment)
- [Local Development](#local-development-1)
- [Testing](#testing)
- [To test development / local](#to-test-development--local)
Expand All @@ -43,8 +43,8 @@ You can also check out the more advanced Chainlink tutorials there as well.

Please install or have installed the following:

- [nodejs and npm](https://nodejs.org/en/download/)
- [python](https://www.python.org/downloads/)
- [nodejs and npm](https://nodejs.org/en/download/)
- [python](https://www.python.org/downloads/)

## Installation

Expand Down Expand Up @@ -86,7 +86,7 @@ Set your `WEB3_INFURA_PROJECT_ID`, and `PRIVATE_KEY` [environment variables](htt

You can get a `WEB3_INFURA_PROJECT_ID` by getting a free trial of [Infura](https://infura.io/). At the moment, it does need to be infura with brownie. If you get lost, you can [follow this guide](https://ethereumico.io/knowledge-base/infura-api-key-guide/) to getting a project key. You can find your `PRIVATE_KEY` from your ethereum wallet like [metamask](https://metamask.io/).

You'll also need testnet ETH and LINK. You can get LINK and ETH into your wallet by using the [faucets located here](https://faucets.chain.link/). If you're new to this, [watch this video.](https://www.youtube.com/watch?v=P7FX_1PePX0). Look at the `goeli` section for those specific testnet faucets.
You'll also need testnet ETH and LINK. You can get LINK and ETH into your wallet by using the [faucets located here](https://faucets.chain.link/). If you're new to this, [watch this video.](https://www.youtube.com/watch?v=P7FX_1PePX0). Look at the `sepolia` section for those specific testnet faucets.

You can add your environment variables to a `.env` file. You can use the [.env.exmple](https://github.com/smartcontractkit/chainlink-mix/blob/master/.env.example) as a template, just fill in the values and rename it to '.env'. Then, uncomment the line `# dotenv: .env` in `brownie-config.yaml`

Expand Down Expand Up @@ -134,19 +134,25 @@ This mix provides a simple template for working with Chainlink Smart Contracts.

> NOTE: It's highly encouraged that you work with a local chain before testing on a testnet. You'll be a much faster developer!
If Sepolia network is not added to brownie by default, run:

```
brownie networks add Ethereum sepolia host=https://sepolia.infura.io/v3/$WEB3_INFURA_PROJECT_ID chainid=11155111 explorer=https://sepolia.etherscan.io/
```

### Chainlink Price Feeds

This will deploy a smart contract to goerli and then read you the latest price via [Chainlink Price Feeds](https://docs.chain.link/docs/get-the-latest-price).
This will deploy a smart contract to Sepolia and then read you the latest price via [Chainlink Price Feeds](https://docs.chain.link/docs/get-the-latest-price).

```
brownie run scripts/price_feed_scripts/01_deploy_price_consumer_v3.py --network goerli
brownie run scripts/price_feed_scripts/02_read_price_feed.py --network goerli
brownie run scripts/price_feed_scripts/01_deploy_price_consumer_v3.py --network sepolia
brownie run scripts/price_feed_scripts/02_read_price_feed.py --network sepolia
```

Or, you can use [ENS](https://docs.chain.link/docs/ens)

```
brownie run scripts/price_feed_scripts/02_read_price_feed_with_ens.py --network goerli
brownie run scripts/price_feed_scripts/02_read_price_feed_with_ens.py --network sepolia
```

Otherwise, you can fork mainnet and use that in a local ganache development environment.
Expand All @@ -165,39 +171,39 @@ You can also use [ENS](https://docs.chain.link/docs/ens) to get prices. See the

### Chainlink VRF

This will deploy a smart contract to goerli and get a Random number via [Chainlink VRF](https://docs.chain.link/docs/get-a-random-number).
This will deploy a smart contract to Sepolia and get a Random number via [Chainlink VRF](https://docs.chain.link/docs/get-a-random-number).

If you haven't created and funded a subscription on [vrf.chain.link](https://vrf.chain.link/) you can do so on the UI, or by running:

```
brownie run scripts/vrf_scripts/create_subscription.py --network goerli
brownie run scripts/vrf_scripts/create_subscription.py --network sepolia
```

Before running the next scripts. Running `01_deploy_vrf` will also add your consumer contract to the registry.

```
brownie run scripts/vrf_scripts/01_deploy_vrf.py --network goerli
brownie run scripts/vrf_scripts/02_request_randomness.py --network goerli
brownie run scripts/vrf_scripts/03_read_random_number.py --network goerli
brownie run scripts/vrf_scripts/01_deploy_vrf_consumer.py --network sepolia
brownie run scripts/vrf_scripts/02_request_randomness.py --network sepolia
brownie run scripts/vrf_scripts/03_read_random_number.py --network sepolia
```

### Chainlink API Call

This will deploy a smart contract to goerli and then make an API call via [Chainlink API Call](https://docs.chain.link/docs/make-a-http-get-request).
This will deploy a smart contract to Sepolia and then make an API call via [Chainlink API Call](https://docs.chain.link/docs/make-a-http-get-request).

```
brownie run scripts/chainlink_api_scripts/01_deploy_api_consumer.py --network goerli
brownie run scripts/chainlink_api_scripts/02_request_api.py --network goerli
brownie run scripts/chainlink_api_scripts/03_read_data.py --network goerli
brownie run scripts/chainlink_api_scripts/01_deploy_api_consumer.py --network sepolia
brownie run scripts/chainlink_api_scripts/02_request_api.py --network sepolia
brownie run scripts/chainlink_api_scripts/03_read_data.py --network sepolia
```

### Chainlink Keeper Deployment
### Chainlink Automation Deployment

This is just to show you how to deploy the Keepers, you can learn more about registering them in the [Chainlink Keeper](https://docs.chain.link/docs/chainlink-keepers/compatible-contracts/) documentation.
This is just to show you how to deploy the Automation Compatible contracts, you can learn more about registering & using them in the [Automate Contracts](https://docs.chain.link/chainlink-automation/compatible-contracts/) section of the Chainlink documentation.

```
brownie run scripts/keeper_scripts/01_deploy_keeper_counter.py --network goerli
brownie run scripts/keeper_scripts/02_check_upkeep.py --network goerli
brownie run scripts/automation_scripts/01_deploy_automation_counter.py --network sepolia
brownie run scripts/automation_scripts/02_check_upkeep.py --network sepolia
```

### Local Development
Expand Down Expand Up @@ -232,10 +238,10 @@ brownie test --network mainnet-fork

### To test a testnet

Goerli is currently supported. Please check the Chainlink docs for which products are supported on which chains.
Sepolia is currently supported. Please check the Chainlink docs for which products are supported on which chains.

```bash
brownie test --network goerli
brownie test --network sepolia
```

## Adding additional Chains
Expand Down Expand Up @@ -265,10 +271,10 @@ If you're using [vscode](https://code.visualstudio.com/) and the [solidity exten

```json
{
"solidity.remappings": [
"@chainlink/=[YOUR_HOME_DIR]/.brownie/packages/smartcontractkit/[email protected]",
"@openzeppelin/=[YOUR_HOME_DIR]/.brownie/packages/OpenZeppelin/[email protected]"
]
"solidity.remappings": [
"@chainlink/=[YOUR_HOME_DIR]/.brownie/packages/smartcontractkit/[email protected]",
"@openzeppelin/=[YOUR_HOME_DIR]/.brownie/packages/OpenZeppelin/[email protected]"
]
}
```

Expand All @@ -278,11 +284,11 @@ This will quiet the linting errors it gives you.

To get started with Brownie:

- [Chainlink Documentation](https://docs.chain.link/docs)
- Check out the [Chainlink documentation](https://docs.chain.link/docs) to get started from any level of smart contract engineering.
- Check out the other [Brownie mixes](https://github.com/brownie-mix/) that can be used as a starting point for your own contracts. They also provide example code to help you get started.
- ["Getting Started with Brownie"](https://medium.com/@iamdefinitelyahuman/getting-started-with-brownie-part-1-9b2181f4cb99) is a good tutorial to help you familiarize yourself with Brownie.
- For more in-depth information, read the [Brownie documentation](https://eth-brownie.readthedocs.io/en/stable/).
- [Chainlink Documentation](https://docs.chain.link/docs)
- Check out the [Chainlink documentation](https://docs.chain.link/docs) to get started from any level of smart contract engineering.
- Check out the other [Brownie mixes](https://github.com/brownie-mix/) that can be used as a starting point for your own contracts. They also provide example code to help you get started.
- ["Getting Started with Brownie"](https://medium.com/@iamdefinitelyahuman/getting-started-with-brownie-part-1-9b2181f4cb99) is a good tutorial to help you familiarize yourself with Brownie.
- For more in-depth information, read the [Brownie documentation](https://eth-brownie.readthedocs.io/en/stable/).

Any questions? Join our [Discord](https://discord.gg/2YHSAey)

Expand Down
30 changes: 15 additions & 15 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ autofetch_sources: true
compiler:
solc:
remappings:
- "@chainlink=smartcontractkit/chainlink-brownie-contracts@0.4.0"
- "@chainlink=smartcontractkit/chainlink-brownie-contracts@0.6.1"
- "@openzeppelin=OpenZeppelin/[email protected]"
dependencies:
- smartcontractkit/chainlink-brownie-contracts@0.4.0
- smartcontractkit/chainlink-brownie-contracts@0.6.1
- OpenZeppelin/[email protected]
networks:
default: development
Expand All @@ -23,25 +23,25 @@ networks:
keyhash: "0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4"
update_interval: 60
verify: false
goerli:
eth_usd_price_feed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e"
fee: 100000000000000000
fund_amount: 5000000000000000000
gas_lane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15"
jobId: ca98366cc7314957b8c012c72f05aeeb
keyhash: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15"
link_token: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB"
oracle: "0xCC79157eb46F5624204f47AB42b3906cAA40eaB7"
update_interval: 60
subscription_id: 1562
verify: false
vrf_coordinator: "0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D"
mumbai:
eth_usd_price_feed: "0x0715A7794a1dc8e42615F059dD6e406A6594651A"
fee: 1000000000000000000
keyhash: "0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4"
link_token: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB"
vrf_coordinator: "0x8C7382F9D8f56b33781fE506E897a4F1e2d17255"
sepolia:
eth_usd_price_feed: "0x694AA1769357215DE4FAC081bf1f309aDC325306"
fee: 100000000000000000
fund_amount: 5000000000000000000
gas_lane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c"
jobId: ca98366cc7314957b8c012c72f05aeeb
keyhash: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c"
link_token: "0x779877A7B0D9E8603169DdbD7836e478b4624789"
oracle: "0x6090149792dAAeE9D1D568c9f9a6F6B46AA29eFD"
subscription_id: 20
update_interval: 60
verify: false
vrf_coordinator: "0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625"
reports:
exclude_contracts:
- SafeMath
Expand Down
37 changes: 18 additions & 19 deletions contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";
import "@chainlink/contracts/src/v0.8/AutomationCompatible.sol";

contract Counter is KeeperCompatibleInterface {
contract Counter is AutomationCompatibleInterface {
/**
* Public counter variable
*/
* Public counter variable
*/
uint public counter;


/**
* Use an interval in seconds and a timestamp to slow execution of Upkeep
*/
* Use an interval in seconds and a timestamp to slow execution of Upkeep
*/
uint public immutable interval;
uint public lastTimeStamp;


constructor(uint updateInterval) {
interval = updateInterval;
lastTimeStamp = block.timestamp;
interval = updateInterval;
lastTimeStamp = block.timestamp;

counter = 0;
counter = 0;
}


function checkUpkeep(bytes calldata checkData) external override returns (bool upkeepNeeded, bytes memory performData) {
function checkUpkeep(
bytes calldata checkData
) external override returns (bool upkeepNeeded, bytes memory performData) {
upkeepNeeded = (block.timestamp - lastTimeStamp) > interval;

// We don't use the checkData in this example
Expand All @@ -34,14 +33,14 @@ contract Counter is KeeperCompatibleInterface {
}

function performUpkeep(bytes calldata performData) external override {
lastTimeStamp = block.timestamp;
counter = counter + 1;
//We highly recommend revalidating the upkeep in the performUpkeep function
if ((block.timestamp - lastTimeStamp) > interval) {
lastTimeStamp = block.timestamp;
counter = counter + 1;
}

// We don't use the performData in this example
// performData is generated by the Keeper's call to your `checkUpkeep` function
// performData is generated by the Automation Node's call to your `checkUpkeep` function
performData;

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from brownie import Counter, config, network


def deploy_keeper_counter():
def deploy_automation_counter():
account = get_account()
return Counter.deploy(
config["networks"][network.show_active()]["update_interval"],
Expand All @@ -13,4 +13,4 @@ def deploy_keeper_counter():


def main():
deploy_keeper_counter()
deploy_automation_counter()
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_api_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_send_api_request_local(

def test_send_api_request_testnet(deploy_api_contract, chainlink_fee):
# Arrange
if network.show_active() not in ["kovan", "rinkeby", "goerli", "mainnet"]:
if network.show_active() not in ["sepolia", "mainnet"]:
pytest.skip("Only for testnet testing")
api_contract = deploy_api_contract

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_vrf_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_returns_random_number_local():

def test_returns_random_number_testnet():
# Arrange
if network.show_active() not in ["goerli"]:
if network.show_active() not in ["sepolia", "mainnet"]:
pytest.skip("Only for testnet testing")
# Arrange
account = get_account()
Expand Down

0 comments on commit 9547384

Please sign in to comment.