This is my repository to learn Ethereum, and Solidity Smart Contract
This project is managed by npm workspace to optimize dependency between different packages
List of workspaces:
inbox
A simple Smart Contract for getting started.lottery
A simple Lottery system that uses Smart Contract to manage winner, manager, and contibutors.lottery-web
A web interface for interacting withlottery
Contract.kickstart
A clone of Kickstarter but managed by Smart Contract to track where the money goes. This package contains Solidity and Next.js codebase.
-
Clone this repo
git clone https://github.com/ashalfarhan/learn-eth.git
-
Install all required dependency
npm install
-
Make sure that the current version of this repo doesn't break
# Build all the contracts to generate artifacts before test npm run -w inbox build npm run -w lottery build npm run -w kickstart build:contract # Run test for all packages npm run -ws test
-
Note that
lottery
andlottery-web
doesn't sync the artifacts, meaning when you change some of the Solidity Contract inlottery
and compile to generate artifacts (ABI and bytecode), thelottery-web
wouldn't reference the latest ABI, so you need to copy the generated ABI tolottery-web/src/abi.json
.
Additional steps for kickstart
:
- You need to have
NEXT_PUBLIC_INFURA_PROJECT_ID
env variable somewhere when developing thekickstart
package, this will be used for the fallback provider (JsonRPC).
Each contract (except for inbox
) have their dedicated deploy
script located in the scripts
directory. But is requires you to provide infura project id and project secret, also your wallet private key to deploy the contract.
-
After you have your infura project id and project secret, place them to .env
# Example for lottery contract touch .env echo "INFURA_PROJECT_ID = '<paste_project_id_here>'" >> .env echo "INFURA_PROJECT_SECRET = '<paste_project_secret_here>'" >> .env echo "MANAGER_PRIVATE_KEY = '<paste_exported_wallet_private_key_here>'" >> .env
-
Then you can run the deploy script
# Example for lottery contract yarn deploy
-
If deployment success, the output of the above command should be something like this
Contract address: 0x0000000000000000
-
Copy the contract address and save them somewhere to interact with that contract in the web interface, optionally to verify the deployment you can check the transaction hash in rinkeby etherscan.
-
Make sure to copy and paste the deployed contract address to the relative web interface.
For
lottery
contract// lottery-web/src/constants.ts export const LOTTERY_CONTRACT_ADDRESS = '<paste_contract_address_here>';
For
kickstart
contract// kickstart/utils/contract.ts const CAMPAIGN_FACTORY_ADDRESS = '<paste_contract_address_here>'; export function getCampaignFactoryContract( signer: Signer | Provider = getProvider() ) { return new Contract( CAMPAIGN_FACTORY_ADDRESS, CampaignFactoryAbi, signer ) as CampaignFactory; }
- Average Time Taken in seconds for a block in order to be included to the Ethereum blockchain https://etherscan.io/chart/blocktime
- Visualization and/or playground about Blockchain https://andersbrownworth.com/blockchain/hash
- Ether converter
- Ethereum Faucets