Skip to content
/ Raffle Public

A Solidity project which allows users to participate in a Raffle

License

Notifications You must be signed in to change notification settings

BigAlQ/Raffle

Repository files navigation

Raffle

Raffle is a smart contract which conducts a raffle and which is written on Solidity

Installation

Run this comman in your terminal to create a new folder called Raffle in your directory, and to move to the Raffle directory

git clone https://github.com/BigAlQ/Raffle.git  
cd Raffle  

Run the command below to install all the neccessary dependencies for the raffle contract

make install

Usage

make anvil

Deploy

make deploy

Deploy - Other Network

See below

Deployment to a testnet or mainnet

  1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL and PRIVATE_KEY as environment variables. You can add them to a .env file, similar to what you see in .env.example.

  • PRIVATE_KEY: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.
  • SEPOLIA_RPC_URL: This is url of the sepolia testnet node you're working with. You can get setup with one for free from Alchemy

Optionally, add your ETHERSCAN_API_KEY if you want to verify your contract on Etherscan.

  1. Get testnet ETH

Head over to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your metamask.

  1. Deploy

make sure you change the account name in the deploy-sepolia command in the make file

forge script script/DeployRaffle.s.sol:DeployRaffle --rpc-url $(SEPOLIA_RPC_URL) --account PUT_YOUR_ACCOUNT_NAME_HERE --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv

(to find your accounts, type this in the CLI)

cast wallet list
make deploy ARGS="--network sepolia"

This will setup a ChainlinkVRF Subscription for you. If you already have one, update it in the scripts/HelperConfig.s.sol file. It will also automatically add your contract as a consumer.

  1. Register a Chainlink Automation Upkeep

You can follow the documentation if you get lost.

Go to automation.chain.link and register a new upkeep. Choose Custom logic as your trigger mechanism for automation. Your UI will look something like this once completed:

Automation

Scripts

After deploying to a testnet or local net, you can run the scripts.

source .env

Using cast deployed locally example:

create a .env file and add your own spepolia rpc url and private key and etherscan API key like this

SEPOLIA_RPC_URL=https://YOUR_SEPOLIA_RPC_URL
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_API_KEY
PRIVATE_KEY=YOUR_PRIVATE_KEY

cast send <RAFFLE_CONTRACT_ADDRESS> "enterRaffle()" --value 0.1ether --private-key <PRIVATE_KEY> --rpc-url $SEPOLIA_RPC_URL

or, to create a ChainlinkVRF Subscription:

make createSubscription ARGS="--network sepolia"

Estimate gas

You can estimate how much gas things cost by running:

forge snapshot

And you'll see an output file called .gas-snapshot

Formatting

To run code formatting:

forge fmt

Have nice day!

About

A Solidity project which allows users to participate in a Raffle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published