PatrickAlphaC / top-up-nft

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

top-up-nft

This demo shows how to use Chainlink Keepers to automate funding an NFT contract so random collectibles can be created in a decentralized manner.

Prerequisites

Please install or have installed the following:

Installation

  1. Install Brownie, if you haven't already. Here is a simple way to install brownie.
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# restart your terminal
pipx install eth-brownie

Or, if that doesn't work, via pip

pip install eth-brownie
  1. Download the mix and install dependancies.
brownie bake chainlink-mix
cd chainlink-mix
pip install -r requirements.txt

This will open up a new Chainlink project. Or, you can clone from source:

git clone https://github.com/PatrickAlphaC/top-up-nft
cd top-up-nft

Testnet Development

If you want to be able to deploy to testnets, do the following.

Set your WEB3_INFURA_PROJECT_ID, and PRIVATE_KEY environment variables.

You can get a WEB3_INFURA_PROJECT_ID by getting a free trial of Infura. At the moment, it does need to be infura with brownie. If you get lost, you can follow this guide to getting a project key. You can find your PRIVATE_KEY from your ethereum wallet like metamask.

You'll also need testnet ETH and LINK. You can get LINK and ETH into your wallet by using the faucets located here. If you're new to this, watch this video.. Look at the rinkeby and kovan sections for those specific testnet faucets.

You can add your environment variables to a .env file. You can use the .env.exmple as a template, just fill in the values and rename it to '.env'. Then, uncomment the line # dotenv: .env in brownie-config.yaml

Here is what your .env should look like:

export WEB3_INFURA_PROJECT_ID=<PROJECT_ID>
export PRIVATE_KEY=<PRIVATE_KEY>

AND THEN RUN source .env TO ACTIVATE THE ENV VARIABLES (You'll need to do this everytime you open a new terminal, or learn how to set them easier)

WARNING WARNING WARNING

DO NOT SEND YOUR PRIVATE KEY WITH FUNDS IN IT ONTO GITHUB

Otherwise, you can build, test, and deploy on your local environment.

Registering with Keepers

You'll need to register your contract with the Chainlink keeper network in order for this to function correctly on the keeper network.

Please see the Chainlink Keeper documentation on how to do this.

Local Development

For local testing install ganache-cli

npm install -g ganache-cli

or

yarn add global ganache-cli

Running Scripts and Deployment

brownie run scripts/collectible/deploy.py --network kovan

Then, after registering with the keeper network, you'll automatically add LINK token to your contract. Then you can create collectibles with:

brownie run scripts/collectible/create_collectible.py

Local Development

For local development, you might want to deploy mocks. You can run the script to deploy mocks. Depending on your setup, it might make sense to not deploy mocks if you're looking to fork a mainnet. It all depends on what you're looking to do though. Right now, the scripts automatically deploy a mock so they can run.

Testing

brownie test

For more information on effective testing with Chainlink, check out Testing Smart Contracts

Tests are really robust here! They work for local development and testnets. There are a few key differences between the testnets and the local networks. We utilize mocks so we can work with fake oracles on our testnets.

To test development / local

brownie test

Linting

pip install black
pip install autoflake
autoflake --in-place --remove-unused-variables --remove-all-unused-imports -r .
black .

Resources

To get started with Brownie:

Any questions? Join our Discord

License

This project is licensed under the MIT license.

About

License:MIT License


Languages

Language:Solidity 62.7%Language:Python 37.3%