项目作者: smartcontractkit
项目描述 :
Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
高级语言:
项目地址: git://github.com/smartcontractkit/full-blockchain-solidity-course-py.git
Big Update: New Sepolia Faucet Located Here.
\Kovan, Ropsten, and Rinkeby have been deprecated. Goerli Still works but we highly recommend Sepolia as its proof of stake based.
You’ll need to verify via Twitter to get ETH & LINK.
You can find Backup Faucets here.
Additionally, lesson 7 uses Chainlink VRF v1 instead of v2, you can find the docs for Chainlink VRFv1 here.
YouTube Video

Welcome to the repository for the Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition FreeCodeCamp course!
Table of Contents
Resources For This Course
Questions
Windows Support
- @cromewar/how-to-setup-windows-10-11-for-smart-contract-development-and-brownie-e7d8d13555b3">Setup your windows environment
- Learn how to install all the tools you will need for this course on a windows machine
Hiccups/Issues from the Video
Lesson 0: Welcome To Blockchain
What is a Blockchain?
Making Your First Transaction
How Do Blockchains Work?
Consensus
The Future
Miscellaneous
💻 Code: https://github.com/PatrickAlphaC/simple_storage
Everything in this section can be read about in the Solidity Documentation
Basic Solidity
- Versioning
- Compiling
- Contract Declaration
- Types & Declaring Variables
uint256
, int256
, bool
, string
, address
, bytes32
- Default Initializations
- Comments
- Functions
- Deploying a Contract
- Calling a public state-changing Function
- Visibility
- Scope
- View & Pure Functions
- Structs
- Intro to Storage
- Arrays - Dynamic & Fixed sized
- Compiler Errors and Warnings
- Memory
- Mappings
- SPDX License
- Recap
Deploying to a “Live” network
- A testnet or mainnet
- Find a faucet here
- Connecting Metamask
- Interacting with Deployed Contracts
- The EVM
💻 Code: https://github.com/PatrickAlphaC/storage_factory
Inheritance, Factory Pattern, and Interacting with External Contracts
- Factory Pattern
- Imports
- Deploy a Contract From a Contract
- Interact With a Deployed Contract
- Recap
💻 Code: https://github.com/PatrickAlphaC/fund_me
Payable, msg.sender, msg.value, Units of Measure
Chainlink Oracles
- Decentralized Oracle Network Chainlink
- Blockchains can’t make API calls
- Centralized Nodes are Points of Failure
- data.chain.link
- Getting External Data with Chainlink Oracles
Importing from NPM and Advanced Solidity
- Decimals/Floating Point Numbers in Solidity
- latestRoundData
- Importing from NPM in Remix
- Interfaces
- Getting Price Feed Addresses
- getPrice
- Tuples
- Matching Units (WEI/GWEI/ETH)
- getConversionRate
- Matching Units (Continued)
- SafeMath & Integer Overflow
- Setting a Threshold
- Require
- Revert
- Withdraw Function
- Transfer
- Balance
- this
- Contract Owners
- Constructor
- ==
- Modifiers
- Resetting
- for loop
- Array Length
- Forcing a Transaction
- Recap
💻 Code: https://github.com/PatrickAlphaC/web3_py_simple_storage
Installing VSCode, Python, and Web3
Our First Python Script with Web3.py - Deploying a Contract
- Reading our solidity file
- Running a Python Script in the Terminal
- MaxOS Shortcuts
- Windows Shortcuts
- Linux Shortcuts
- Compiling in Python
- py-solc-x
- Colorized Brackets
- JSON ABI
- Saving Compiled Code
- Formatting JSON
- Deploying in Python
- Get Bytecode
- Get ABI
- Choose Blockchain to Deploy To
- Web3.py
- HTTP / RPC Provider
- Private Keys MUST start with “0x”
- Contract Object
- Building a Transaction
- Account Nonce
- Calling “Constructor”
- Transaction Parameters
- Signing the Transaction
- NEVER put your private key directly in your code
- Setting Environment Variables (Windows, Linux, MacOS)
- Exported Environment Variables Only Last the Duration of the Shell/Terminal
- Private Key PSA
- .env file
- .gitignore
- Loading .env File in Python
- Viewing our Transaction / Deployment in Ganache
- Waiting for Block Confirmations
Interacting with Our Contract in Python & Web3.py
- 2 Things you always need
- Contract Address
- Contract ABI
- Getting address from transaction receipt
- Calling a view function with web3.py
- Updating State with Web3.py
- ganache-cli
- Working with ganache-cli
- Open a new terminal in the same window
- Deploying to a testnet
- Infura
- Alchemy
- Using Infura RPC URL / HTTP Provider
- Chain Ids
- Wow this seems like a lot of work… Is there a better way?
💻 Code: https://github.com/PatrickAlphaC/brownie_simple_storage
Brownie Introduction
Installing Brownie
Brownie Simple Storage Project
- A new Brownie project with
brownie init
- Project Basic Explanation
- Adding
SimpleStorage.sol
to the contracts
folder - Compiling with
brownie compile
- Brownie deploy script
def main
is brownie’s entry point
- brownie defaults to a
development
ganache
chain that it creates - Placing functions outside of the
main
function - brownie
accounts
- 3 Ways to Add Accounts
accounts[0]
: Brownie’s “default” ganache accounts
- Only works for local ganache
accounts.load("...")
: Brownie’s encrypted command line (MOST SECURE)
- Run
brownie accounts new <name>
and enter your private key and a password
accounts.add(config["wallets"]["from_key"])
: Storing Private Keys as an environment variable, and pulling from our brownie-config.yaml
- You’ll need to add
dotenv: .env
to your brownie-config.yaml
and have a .env
file
- Importing a Contract
- Contract.Deploy
- View Function Call in Brownie
- State-Changing Function Call in Brownie / Contract Interaction
transaction.wait(1)
Testing Basics
test_simple_storage.py
- Arrange, Act, Assert
assert
brownie test
test_updating_storage
- Pytest / Brownie Test Tips
- Deploy to a Testnet
brownie networks list
- Development vs Ethereum
- Development is temporary
- Ethereum networks persist
- RPC URL / HTTP Provider in Brownie
- The network flag
get_account()
networks.show_active()
- build/deployments
- Accessing previous deployments
- Interacting with contracts deployed in our brownie project
[Brownie console]
💻 Code: https://github.com/PatrickAlphaC/brownie_fund_me
Introduction
Dependencies, Deploying, and Networks
- Dependencies
- chainlink-brownie-contracts
- remappings
- Deploy Script (V1)
helpful_scripts.py
__init__.py
- Deploy to Rinkeby
- Contract Verification (
publish_source
)
- The Manual Way
- The Programmatic Way
- Interacting with Etherscan
- Deploying to Local Chains
- Introduction to Mocking
- Constructor Parameters
networks
in our brownie-config.yaml
- Copying Mock Contracts from chainlink-mix
- Deploying and using our mock
- Refactoring
- Deploying to a persistent ganache
- brownie attach
- Adding a persistent brownie network
- resetting a network build
Funding and Withdrawing Python Scripts
- Whoops! Let’s fix an issue…
- Fund Script
- Withdraw Script
Testing across networks
test_can_fund_and_withdraw
- default networks
- pytest
pip install pytest
- pytest.skip
- brownie exceptions
mainnet-fork
- Custom mainnet fork
- Adding a development brownie network
brownie networks add development mainnet-fork-dev cmd=ganache-cli host=http://127.0.0.1 fork='https://infura.io/v3/$WEB3_INFURA_PROJECT_ID' accounts=10 mnemonic=brownie port=8545
- Alchemy
brownie test --network mainnet-fork
- brownie ganache vs local ganache vs mainnet-fork vs testnet…
Git
Compatibility with Ganache UI
test_only_owner_can_withdraw()
gives below error if the selected network is Ganache UI::
E ValueError: Execution reverted during call: 'VM Exception while processing transaction: revert'. This transaction will likely revert. If you wish to broadcast, include `allow_revert:True` as a transaction parameter.
More information here.
💻 Code: https://github.com/PatrickAlphaC/smartcontract-lottery
Chainlink VRF v1 docs
Introduction
- Add a
README.md
- Defining the project
- Is it decentralized?
Lottery.sol
Testing Lottery.sol
deploy_lottery.py
get_account()
refactoredget_contract
contract_to_mock
Contract.from_abi
- Adding the parameters to deploying to lottery
vrfCoordinatorMock
and adding mocksLinkToken
and Mocks- Successful Ganache Deployment!
- Python Lottery Scripts/Functions
start_lottery
- Brownie tip: Remember to
tx.wait(1)
your last transaction enter_lottery
end_lottery
- Funding with LINK
- brownie interfaces
- Waiting for callback
- Integration Tests & Unit Tests
- Test all lines of code
test_get_entrance_fee
pytest.skip
(again)test_cant_enter_unless_started
test_can_start_and_enter_lottery
test_can_pick_winner_correctly
- Events and Logs
callBackWithRandomness
Lottery.sol Testnet Deployment
💻 Code: https://github.com/smartcontractkit/chainlink-mix
💻 Code: https://github.com/PatrickAlphaC/erc20-brownie-py
*NOTE: This repo is now archived as kovan is no longer supported. You can still follow along with the learning, but know the code may not work the same on a different testnet.
💻 Code: https://github.com/PatrickAlphaC/aave_brownie_py_freecode
Defi Intro
Aave UI
Testing
Lesson 11: NFTs
💻 Code: https://github.com/PatrickAlphaC/nft-demo
Non-Technical Explainer
Simple NFT
SimpleCollectible Testing
Advanced NFT
Advanced deploy_and_create
- Move
OPENSEA_URL
to helpful_scripts
- Deploying AdvancedCollectible
- Opensea testnet is only compatible with Rinkeby
- Rinkeby Chainlink VRF Contract Addresses
- Speeding through adding functions from previous projects
- Deploy to Rinkeby
create_collectible.py
- A quick unit test
- A quick integration test
create_metadata.py
get_breed
- Metadata Folder
metadata_template
- NFT Metadata Attributes
- Checking if Metadata file already exists
- Uploading to IPFS
- Setting the TokenURI
- End-To-End Manual Testnet Test
- Viewing on Opensea
💻 Code: https://github.com/PatrickAlphaC/upgrades-mix
Introduction to upgrading smart contracts
- Original Video
- Smart Contracts can be upgraded!
- Does this mean they are not immutable?
- Trail of Bits on Upgradeable Smart Contracts
- The “Not Really Upgrading” / Parameterization Method
- The Social Yeet / Migration Method
- Contract Migration
- Proxies
- DelegateCall
- Terminology:
- Implementation Contract
- Proxy Contract
- User
- Admin
- Gotchas:
- Storage Clashes
- Function Selector
- Function Selector Clashes
- Proxy Patterns:
Upgrades-mix and code
- Setup
Box.sol
BoxV2.sol
- Getting the proxy contracts
- Openzeppelin Proxy Github
01_deploy_box.py
- Hooking up a proxy to our implementation contract
- (Optional) Creating a Gnosis Safe
- Initializers
- Encoding Initializer Function
- Assigning ABI to a proxy
- Running the script
- Upgrade Python Function
Testing Upgrades
- Testing our proxy
- Testing our upgrades
Upgrades on a testnet
Note: This section is archived as kovan is now deprecated. If you’re looking to learn more Full-stack, check out the full stack portions of the hardhat/javascript video.
Link to hardhat/javascript video with more full-stack examples: https://github.com/smartcontractkit/full-blockchain-solidity-course-js
💻 Code: https://github.com/PatrickAlphaC/defi-stake-yield-brownie-freecode
- FreeCodeCamp React
- What are we building?
- Setup
DappToken.sol
TokenFarm.sol
tokenIsAllowed
addAllowedTokens
- mapping of a mapping
stakeTokens
issueTokens
getUserTotalValue
getUserSingleTokenValue
getTokenValue
setPriceFeedContract
unStakeTokens
- Can this be reentrancy attacked?
Defi Stake Yield Brownie Scripts & Tests
deploy.py
- Deploying DappToken
- Deploying TokenFarm
- Adding allowed tokens
- ERC20 Kovan Faucet
- If the link above does not work, you can get another ERC20 token using this faucet: Weenus ERC20 Faucet
- Mocking our ERC20s
Testing our Defi Stake Yield Brownie Dapp
test_set_price_feed_contract
test_stake_tokens
- Fixtures
test_issue_tokens
- Now you try on tests!
Front End / Full Stack
- Front End Introduction
- Typescript
- React
- useDapp
- npx
- yarn
create-react-app
- Testing Front End
- yarn && yarn start
- Connecting our wallets
- Install useDapp
- Header Component
- Connect Button
- Material-UI
- Making our button nicer
Main.tsx
- Sending
brownie-config
& build
folder to our UI - Helper Config
- TypeScript error suppression
- Getting addresses
- Ethers
- Only support kovan
YourWallet
supportedTokens
- State Hooks
- Showing tokens
WalletBalance
- @ethersproject/units">
ethersproject/units
BalanceMsg
- Stake Form
- Calling
approve
useContractFunction
useEffect
- Notifications
- Make it pretty
- Alerts
Shoutout to Matt for the help on the front end!
Closing and Summary
Security
Where do I go now?
Learning More
Hackathons
Be sure to check out project grant programs!
Vyper
From solidity course to vyper
And make today an amazing day!