Skip to content

oooookk7/ico-token

Repository files navigation

📈 $ICO Token

Getting Started

  1. Install NodeJS, Yarn, and Ganache.
  2. Install truffle using yarn global add truffle.
  3. Download the Metamask wallet extension to connect to the test wallets.
  4. Install required dependencies using yarn install in this repository.
  5. (Optional) Install Ethereum syntax highlighter (this for sublime).

Favicon credits: @ipapun. Gifs created using gifcap.dev.

As answered by @Ismael on ethereum.stackexchange.com, the differences between using Truffle and GoETH is,

They both have different functionality.

Geth is a Ethereum network client. It connects to others networks clients to download and synchronize the Ethereum blockchain. Also it allows you to send transaction to other nodes and miners, so they will incorporate it in future blocks.

Truffle is a javascript framework to allow development and testing of smart contracts. It add extra functionality on top of the web3 javascript library. It makes the cycle compile and deploy of a smart contract faster. You can also create unit tests to automate testing.

Resources:

Basic Concepts

Cryptocurrency is a standard currency used for making or receiving payments on a blockchain.

Altcoins are alternative cryptocurrencies launched after the success achieved by Bitcoin (aka other than Bitcoin) (e.g. Litecoin, Dogecoin).

Tokens operate on top of a blockchain that act as a medium for the creation and execution of decentralized apps and smart contracts to facilitate the transactions.

What is ERC-20?

It is a list of rules that all Etherum-based tokens must follow, which tokens are used for transactions (e.g. smart contracts) on the Ethereum blockchain network. The token used within this chain is called the Etherum token.

This is the same thing similar to BIPS protocol used for Bitcoin, except that on Etherum network, one is able to build a decentralised app, unlike Bitcoin which serves as an asset.

(Source: Raj Jain et., 2018 - Overview of the entire blockchain network with nodes, that each contains blocks)

(Source: Jimi S., 2018 - Overview of blocks, which contains a string of transactions and hash)

(Source: @xcsob, 2018 - Overview of transactions that forms an entire block)

From Wikipedia,

It is growing list of records (called blocks) that are linked together using cryptography.

Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data (generally represented as a Merkle tree).

The timestamp proves that the transaction data existed when the block was published in order to get into its hash.

As blocks each contain information about the block previous to it, they form a chain, with each additional block reinforcing the ones before it.

Therefore, blockchains are resistant to modification of their data because once recorded, the data in any given block cannot be altered retroactively without altering all subsequent blocks.

Blockchains are typically managed by a peer-to-peer network for use as a publicly distributed ledger, where nodes collectively adhere to a protocol to communicate and validate new blocks

Here's an example of the Bitcoin (BTC) network,

(Source: Brian.Wu, 2019)

(Source: Michele D'Aliessi, 2016)

Here's an example of an Etherum transaction,

(Source: andryo.com, n.d.)

Smart contracts are self-executing, business automation applications that run on a decentralized network such as blockchain.

For example, an insurance company could use smart contracts to automate the release of claim money based on events such as large-scale floods, hurricanes or droughts. Or, once a cargo shipment reaches a port of entry and IoT sensors inside the container confirm the contents have been unopened and remained stored properly throughout the journey, a bill of lading can automatically be issued.

Decentralized apps (dapps) is an application built on a decentralized network that combines a smart contract and a frontend user interface. It has its own backend code running on a decentralized peer-to-peer network (unlike backend code running on centralized servers like AWS). It may have a frontend code which may be hosted on decentralized storage such as IPFS.

From Wikipedia,

A blockchain oracle is a third-party service that provides smart contracts with information from the outside world. It is the layer that queries, verifies, and authenticates external data sources, usually via trusted APIs and then relays that information.

Examples of data transmitted by oracles to smart contracts include price information, the successful completion of a payment, the temperature measured by a sensor, election outcomes etc.

Data can be supplied by other software (databases, servers, or essentially any online data source), or by hardware (sensors, barcode scanners etc.).

Note that the records data is centralized to oracles. It's akin to an extra record data tied to these transactions.

What are Wallets?

(Source: simplilearn.com, n.d.)

A cryptocurrency wallet allows users to manage different users to manage different kinds of cryptocurrencies (e.g. Bitcoin/Etherum).

It contains the user keys information (e.g. private and public keys) used for transactions.

Hot wallets are online wallets through which cryptocurrencies can be transferred quickly (e.g. Coinbase or Binance). Cold wallets are digital offline wallets where the transactions are signed offline and then disclosed online (e.g. Trezor or Ledger).

There are Software wallets that exists in the desktop, mobile or online (managed by 3rd parties), or Hardware wallets, a type of cold storage device, typically like a USB, that stores the user’s private key in a protected hardware device (e.g. Trezor).

Code Structure

There are 6 defined functions: balanceOf, totalSupply, transfer, transferFrom, approve, and allowance.

Below is an example code for an ERC-20 contract,

contract ERC20 {
   function totalSupply() constant returns (uint theTotalSupply);
   function balanceOf(address _owner) constant returns (uint balance);
   function transfer(address _to, uint _value) returns (bool success);
   function transferFrom(address _from, address _to, uint _value) returns (bool success);
   function approve(address _spender, uint _value) returns (bool success);
   function allowance(address _owner, address _spender) constant returns (uint remaining);
   event Transfer(address indexed _from, address indexed _to, uint _value);
   event Approval(address indexed _owner, address indexed _spender, uint _value);
}

(Source: @aunyks, 2015)

totalSupply()

This function allows an instance of the contract to calculate and return the total amount of the token that exists in circulation.

contract MyERCToken {
  // In this case, the total supply
  // of MyERCToken is fixed, but
  // it can very much be changed
  uint256 _totalSupply = 1000000;
  
  function totalSupply() constant returns (uint256 theTotalSupply) {
    // Because our function signature
    // states that the returning variable
    // is "theTotalSupply", we'll just set that variable
    // to the value of the instance variable "_totalSupply"
    // and return it
    theTotalSupply = _totalSupply;
    return theTotalSupply;
  }
}

(Source: @aunyks, 2015)

balanceOf()

This function allows a smart contract to store and return the balance of the provided address. It accepts an address as a parameter, to which its balance is known publically.

contract MyERCToken {
  // Create a table so that we can map addresses
  // to the balances associated with them
  mapping(address => uint256) balances;
  // Owner of this contract
  address public owner;
  
  function balanceOf(address _owner) constant returns (uint256 balance) {
    // Return the balance for the specific address
    return balances[_owner];
  }
}

(Source: @aunyks, 2015)

approve()

This function allows the owner of the contract to authorize or approve the given address to withdraw instances of the token from the owner's address.

This variable msg is an implicit field provided by external applications such as wallets to better interact with the contract.

The Ethereum Virtual Machine (EVM) allows external applications to store and process data in it.

The msg.sender is the address of the contract owner in the example below.

contract MyERCToken {
  // Create a table so that we can map
  // the addresses of contract owners to
  // those who are allowed to utilize the owner's contract
  mapping(address => mapping (address => uint256)) allowed;
  
  function approve(address _spender, uint256 _amount) returns (bool success) {
    allowed[msg.sender][_spender] = _amount;
    // Fire the event "Approval" to execute any logic
    // that was listening to it
    Approval(msg.sender, _spender, _amount);
    return true;
  }
}

(Source: @aunyks, 2015)

transfer()

This function lets the owner of the contract to send a given amount of the token to another address just like a cryptocurrency transaction.

contract MyERCToken {
  mapping(address => uint256) balances;
  
  // Note: This function returns a boolean value
  //       indicating whether the transfer was successful
  function transfer(address _to, uint256 _amount) returns (bool success) {
    // If the sender has sufficient funds to send
    // and the amount is not zero, then send to
    // the given address
    if (balances[msg.sender] >= _amount 
      && _amount > 0
      && balances[_to] + _amount > balances[_to]) {
      balances[msg.sender] -= _amount;
      balances[_to] += _amount;
      // Fire a transfer event for any
      // logic that's listening
      Transfer(msg.sender, _to, _amount);
        return true;
      } else {
        return false;
      }
   }
}

(Source: @aunyks, 2015)

transferFrom()

This function allows a smart contract to automate the transfer process and send a given amount of the token on behalf of the owner, instead of self like transfer().

contract MyERCToken {
  mapping(address => uint256) balances;
  
  function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
    if (balances[_from] >= _amount
      && allowed[_from][msg.sender] >= _amount
      && _amount > 0
      && balances[_to] + _amount > balances[_to]) {
    balances[_from] -= _amount;
    balances[_to] += _amount;
    Transfer(_from, _to, _amount);
      return true;
    } else {
      return false;
    }
  }
}

(Source: @aunyks, 2015)

Token Name (Optional Field)

For some wallets are able to identify the token.

contract MyERCToken {
  string public constant name = "My Custom ERC20 Token";
}

(Source: Steven McKie, 2017)

Token Symbol (Optional Field)

For some wallets to identify the token (e.g. BTC/ETH).

contract MyERCToken {
  string public constant symbol = "MET";
}

(Source: Steven McKie, 2017)

Number of Decimals (Optional Field)

Determine to what decimal place the amount of the token will be calculated. The most common number of decimals to consider is 18.

contract MyERCToken {
  uint8 public constant decimals = 18;
}

(Source: Steven McKie, 2017)

About

A ERC-20 token called $ICO that is created based on a YouTube playlist from "Dapp University" to understand the basic idea of smart contracts and tokens on the Ethereum network

Topics

Resources

Stars

Watchers

Forks