seeu-inspace / soliditytoken

This project aims to create and distribute a token called "SolidityToken $STK"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SolidityToken

Final project for "Alchemy University, The Ethereum Developer Bootcamp". Took also inspiration from the "ERC20 Tokens by Block Explorer" series.

This project aims to create a token called "SolidityToken $STK". The tokens are then distributed to users who request them from the faucet. Contracts built with Hardhat. UI built with Ethers and Browserify.

Index
Project Layout
Gas optimizations
Tests
Deploy the contracts
SolidityToken Faucet UI

Project Layout

There are three main folders:

  1. contracts/contract - contains the solidity contracts
  2. contracts/test - contains test for the solidity contract of the ERC20 token
  3. stkfaucet-ui/ - contains the ui

Gas optimizations

The following gas optimizations were implemented in the contracts.

  • x += y costs more gas than x = x + y for state variables
  • Use of assembly to check for address(0)
    • Description: By checking for address(0) using assembly language, you can avoid the use of more gas-expensive operations such as calling a smart contract or reading from storage. This can save 6 gas per instance.
    • Reference:
  • Mark payable functions guaranteed to revert when called by normal users
    • Description: If a function modifier, like onlyOwner, is applied, the function will revert if a regular user attempts to pay it. Making the function payable will save valid callers money on gas since the compiler won't do checks to see if a payment was made. The extra opcodes avoided are CALLVALUE(2), DUP1(3), ISZERO(3), PUSH2(3), JUMPI(10), PUSH1(3), DUP1(3), REVERT(0), JUMPDEST(1), POP(2) which costs an average of about 21 gas per call to the function, in addition to the extra deployment cost.
    • Reference:

Tests

  • Install dependencies using the following command
    npm install
  • Add a .env file using either the dummy keys provided in .env.example or your own
  • To run all the tests for the contracts, use the following command
    npx hardhat test --network hardhat

Deploy the contracts

  1. From the contracts folder, follow the following steps
  2. Use the following command to deploy SolidityToken.sol on the Sepolia testnet
    npx hardhat run --network sepolia scripts/deploySolidityToken.js
  3. Copy the address displayed in the terminal as a result. Paste it in deployFaucet.js in
    5: 	const contract = await Contract.deploy("ADDR-SOLIDITYTOKEN");
  4. Use the following command to deploy Faucet.sol on the Sepolia testnet
    npx hardhat run --network sepolia scripts/deployFaucet.js

A version of Faucet is already deployed at 0x8e830f030a1a9094bbb6ae779879177f65a47f81 and a version of SolidityToken is deployed at 0x16e41846e3be94bd529afa9b475899bd15d88bc1 on the Sepolia testnet.

SolidityToken Faucet UI

Host the project in the stkfaucet-ui directory on a server. If you're using Visual Studio, you can use the Live Server extension.

Browserify

dist/bundle.js is generated using Browserify with the following command

browserify src/index.js --standalone bundle -o dist/bundle.js

About

This project aims to create and distribute a token called "SolidityToken $STK"


Languages

Language:JavaScript 56.1%Language:Solidity 29.1%Language:HTML 12.3%Language:CSS 2.5%