diff --git a/README.md b/README.md index a072d31..1d29d60 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,34 @@ -# 3c +coincoincoin - an exploration of the ethereum blockchain and smart contracts -coincoincoin \ No newline at end of file +- [Introduction](#introduction) +- [Getting Started](#getting-started) + +## Introduction + +> What's an Ethereum? +> Ethereum is a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, fraud or third party interference. These apps run on a custom built blockchain, an enormously powerful shared global infrastructure that can move value around and represent the ownership of property. + +**Ether** is the currency of the Ethereum blockchain. It is a form of payment made by the clients of the platform to the machines executing the requested operations. To put it another way, ether is the incentive ensuring that developers write quality applications (wasteful code costs more), and that the network remains healthy (people are compensated for their contributed resources). + +> Smart contracts? + +Smart contracts are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code. The code and the agreements contained therein exist across a distributed, decentralized blockchain network. Smart contracts permit trusted transactions and agreements to be + +Types of smart contracts include: + +| Name | Buzzwords | Real explanation | +| -------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| ERC-20 | Fungible tokens, DeFi, Utility Tokens | The standard for fungible tokens on Ethereum. Used for cryptocurrencies like USDC and DAI. Tokens are interchangeable, meaning each unit is the same as another (e.g., 1 USDC = 1 USDC). | +| ERC-721 | NFTs, Unique assets, Digital collectibles | The standard for **Non-Fungible Tokens (NFTs)**. Each token is unique, making it perfect for digital art, real estate, and in-game items. Used in platforms like [OpenSea](https://opensea.io). | +| ERC-1155 | Multi-token standard, Gas-efficient, Hybrid tokens | Supports **both** fungible and non-fungible tokens in a single contract. More gas-efficient for batch transfers. Popular in gaming (e.g., [Enjin](https://enjin.io)). | +| ERC-4626 | Yield-bearing vaults, DeFi, Tokenized Vaults | A standard for tokenized yield vaults in DeFi. It makes it easier to deposit assets into lending/staking platforms and get interest-bearing tokens in return. | +| ERC-777 | Advanced ERC-20, Hooks, Gas-efficient | An improved version of ERC-20 with **hooks** (allowing smart contract interactions on transfers). Enables more efficient token transactions and is backwards-compatible with ERC-20. | +| ERC-2981 | NFT Royalties, Creator earnings, Marketplace standard | Adds royalty information to NFTs, allowing creators to automatically receive a percentage of sales when their NFTs are resold on marketplaces. | +| ERC-6059 | Nested NFTs, Composable assets, On-chain hierarchies | Allows NFTs to own other NFTs (nested ownership). Useful for metaverse projects, gaming, and dynamic NFT structures (e.g., a character NFT that owns weapon NFTs). | + + +## Getting Started + +Read how to set up the environment like I did [here](doc/01_environment.md) + +Are you done with that? Check out the [minimal example](doc/02_minimal.md) to deploy a smart contract to the Ethereum blockchain. diff --git a/doc/01_environment.md b/doc/01_environment.md new file mode 100644 index 0000000..8d28215 --- /dev/null +++ b/doc/01_environment.md @@ -0,0 +1,59 @@ +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Getting a test Ethereum wallet](#getting-a-test-ethereum-wallet) +- [Writing the contract](#writing-the-contract) + + +## Prerequisites +- Node.js and npm + +## Installation + +```bash +npm init -y +npm install --save-dev hardhat +npx hardhat +``` + +> What's Hardhat? + +It's a development environment to compile, deploy, test, and debug your Ethereum software. It helps developers manage and automate the recurring tasks that are inherent to the process of building smart contracts and dApps[^1]. + + +## Getting a test Ethereum wallet +>[!IMPORTANT] +> In order to do this you need to have 0.0001 ETH in your **Mainnet** wallet (for some fucking reason) which is ~25 real cents. Everything else is free. + +1. Go to [MetaMask](https://metamask.io/) +2. Install the browser extension +3. Go to Advanced settings, click "Show Test Networks" +4. Click this button and select "Sepolia" from the dropdown (should be at the bottom) + + +![the button](assets/instruction_test.png) + +## Writing the contract + +Create a new file in the `contracts` directory called `CoinCoinCoin.sol` (or whatever) and paste the following code: + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +contract TheTokenName is ERC20 { + constructor(uint256 initialSupply) ERC20("TheTokenName", "TTN") { + _mint(msg.sender, initialSupply * 10 ** decimals()); // This is the initial supply of the token + } +} +``` + +- This code creates a new ERC20 token with the name `TheTokenName` and the symbol `TTN`. +- It uses [OpenZeppelin](https://openzeppelin.com/solidity-contracts)'s `ERC20` contract to do so. + + +You're ready to [deploy the contract](02_minimal.md)! I don't want to add the fucking emojis but this is where you'd do the 🚀✨ and whatnot. + +[^1]: Decentralized applications (lmao) + diff --git a/doc/02_minimal.md b/doc/02_minimal.md new file mode 100644 index 0000000..ffced2c --- /dev/null +++ b/doc/02_minimal.md @@ -0,0 +1,48 @@ + +- [Compiling and deploying](#compiling-and-deploying) +- [Interacting with the contract](#interacting-with-the-contract) + +This document focuses on the minimal setup required to deploy a smart contract to the Ethereum blockchain. It assumes you have already set up your development environment and have a test Ethereum wallet. + + +## Compiling and deploying +First, modify `scripts/deploy.js` in the Hardhat project: + +```js +const hre = require("hardhat"); + +async function main() { + const initialSupply = hre.ethers.parseUnits("1000", 18); // 1000 MTK tokens + const MyToken = await hre.ethers.deployContract("MyToken", [initialSupply]); + await MyToken.waitForDeployment(); + + console.log(`MyToken deployed to: ${MyToken.target}`); +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); +``` + +then, deploy like this: +```bash +npx hardhat run scripts/deploy.js --network sepolia +``` + +## Interacting with the contract + +You can see it on your favorite block explorer (e.g., [Etherscan](https://etherscan.io/)) by pasting the contract address. + +You can send it via the MetaMask extension by clicking "Send" and pasting the contract address. + +You can also interact with it programmatically using the Hardhat console: + +```bash +npx hardhat console --network sepolia +``` + +```js +const MyToken = await ethers.getContract("WhateverYouNamedIt", "0xYourContractAddress"); +await MyToken.totalSupply(); +``` \ No newline at end of file diff --git a/doc/assets/instruction_test.png b/doc/assets/instruction_test.png new file mode 100644 index 0000000..1064ec4 Binary files /dev/null and b/doc/assets/instruction_test.png differ