Ethereum - the future of transactions

Ethereum - the future of transactions

By Matthew Loong

While Bitcoin is the pioneer cryptocurrency that harnessed blockchain technology for money and payments, Ethereum is arguably dominating in decentralized applications (dapp). Ethereum dapps have many use cases, from immutable ledgers for payments and fund transfers to smart contracts and commodity trading; dapps can also be used for everyday purposes like voting, balloting and even global healthcare records.

Starting with the Basics

Before we talk about the details of ethereum implementation, let's understand the concept of blockchain. Generally speaking, a blockchain relies on the continuous block hashing of a nonce along with given data and the hash of the previous block, thereby forming a chain. Each node in the blockchain competes to solve an algorithmic problem to earn the right to create the new block. The generation of a new block by a node is known as mining, and the node that mines the fastest is rewarded with a cryptocurrency token e.g. ether (ETH). This is known as proof of work (POW). Additionally, peer nodes in the blockchain validate with each other that the hash value of a block is the same, verifying its authenticity; if a peer has a block (and consequently its subsequent chain) of different hash value from majority of the other peers, that peer is rejected. The website below by Anders Brownsworth provides an excellent explanation and demo on this concept.

Transactions made on-chain are not free. Every on-chain transaction e.g. mining a new block, deploying a smart contract, transferring funds etc. expends a small fee, known as gas. The currency for ethereum is ETH. ETH has multiple denominations, the most common being wei and gwei. 1 ETH equals 1e18 wei, while 1 gwei equals 1e9 wei.

Similarly, every transaction can be tracked. For example, if you input an address or transaction hash into Etherscan below, you can trace the details of that particular address and transaction.

Integrated Development Environments (IDE)

Now that we have briefly touched on the basics of blockchain, let's talk about how we can implement smart contracts and dapps using ethereum.

Remix

The simplest IDE for ethereum is Remix, as can be found in the documentation page below.

Ethereum smart contracts are written in an OOP language called Solidity. You first define the compiler version i.e.

pragma solidity [insert compiler version number]        

Followed by the class and functions with defined variables i.e.


contract A {


   function name() public {

    ...........................
   
    }

}        

Functions can be either public or private.

For example, a simple solidity program for a contract that stores a number can be seen below. You must compile the program before deploying or transacting.

No alt text provided for this image

After compiling, you can deploy the contract (in the example below to the VM environment) and begin transacting. In the screenshot below on the bottom left corner, you can see that the number "23" is stored and retrieved; you can see respective messages on the store and retrieve transactions in terminal on the bottom right.

No alt text provided for this image

Alternatively, you can select to deploy to an Injected Web3 environment and the transaction will be made on a browser wallet like Metamask. You can then track the details on Etherscan (Note: for example, in the screenshot below, the contract was deployed on Ethereum Rinkeby test network so you would have to use rinkeby.etherscan.io)

No alt text provided for this image

Web3.py

Alternatively, if you prefer engineering ethereum smart contract deployment with Python, you can use Web3.py.

The Solidity code is compiled into json format.

No alt text provided for this image
No alt text provided for this image

Before being parsed and deployed by the Python code.

No alt text provided for this image

(Credits to Patrick Collins for source code)

Brownie

The most robust method of deploying ethereum smart contracts is to use Brownie, which is a Python-based development and testing framework for smart contracts. Nonetheless Brownie relies heavily on Web3.py but is much easier to use.

Brownie uses a list of commands to manage the project. With these commands

No alt text provided for this image

For example, running Python script with Brownie, we can immediately deploy and transact with the blockchain. In the terminal we can see the block number, as well as the gas used to retrieve initial stored value of 0 and updated value of 15.

No alt text provided for this image

(Credits to Patrick Collins for source code)

Ganache

You can see from the terminal messages in the earlier screenshot above, showing deployment with Brownie, that Ganache was launched. Ganache is a development environment for developing, deploying and testing your dapps in a personal blockchain.

You are given 10 accounts, each with a balance of 100 ETH. With that, you can deploy your smart contracts and test transactions. Ganache comes in two flavors - Ganache UI and Ganache CLI.

No alt text provided for this image

(Ganache UI)

No alt text provided for this image

(Ganache-CLI)

ERC-20 / EIP-20

Similar to Bitcoin's Bitcoin Improvement Proposals (BIPs), the community has also established a set of Ethereum standards known as Ethereum Improvement Proposals (EIPs). A proposal is initially an Ethereum Request for Comments (ERC) before it becomes an EIP. One important standard is a EIP-20, the standard API for tokens within smart contracts, providing the basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party.

For example, for a transfer function, _value?amount of tokens is transferred to address?_to, and this must fire the?transfer?event. The function should also?throw?if the message caller’s account balance does not have enough tokens to spend. This ensures that there is no double spending.

function transfer(address _to, uint256 _value) public returns (bool success)        

It is even possible to borrow liquidity in cryptocurrency. Aave is an open source decentralized finance (DeFi) protocol that allows for depositing of assets to earn interest and borrowing for additional liquidity. Of course the downside is that if you are unable to pay back what you borrowed, you have to repay with collateral from your deposit.

ERC-721 / EIP-721

Lately, there has also been a trend of Non-Fungible Tokens (NFT). NFTs represent attesting ownership of digital assets using blockchain. These include artwork, music, trading cards, virtual game characters, virtual worlds etc. Storing media on chain would be to costly i.e. it would require too much gas, hence Inter Planetary File Storage Protocol (IPFS) is used to store the files, only the metadata goes on chain.

A popular marketplace for ethereum NFTs is OpenSea.

Prices for NFTs can go up to insane values (albeit virtual, which nonetheless can still possibly be converted to fiat). For example, the artwork below is priced at 9999.9999 ETH which is approximately USD 28 million.

No alt text provided for this image

DefiLlama displays the total volume and daily volume of NFT collections. For example as shown in the dashboard below, the top collection CryptoPunks has a total volume of $2.33 billion with 3,373 owners.

No alt text provided for this image

Ethereum 2.0

Another shift driving the potential adoption of ethereum over other currencies like Bitcoin is its shift from POW to proof of stake (POS). POW is highly costly in terms of energy since nodes have to compete in mining. With POS, validator of the next block in the chain is chosen depending on the stake of the node. The higher the stake, the higher the chance of being selected as the validator. If the selected node validates a fraudulent transaction, the node's stake is confiscated. This reduces the overall consumption of energy required for the blockchain to grow. Although there are challenges, it seems that it will improve ethereum's popularity in the long run.

DAOs

Ultimately, I would like to think that ethereum will be used for more than financial speculation. In an ideal world, it will be used to establish Decentralized Autonomous Organizations (DAOs). DAOs are fully transparent, publicly verifiable, internet native businesses owned and managed by its members, with no need for CEOs, CFOs etc. and no fear of breach of trust. I quote Ben Schecter from Future, "The future of work is not corporate - it's DAOs and crypto networks". While that might sound fanciful, dapps as described earlier, are certainly realistic in the near future.

No alt text provided for this image

(Source: ethereum.org)

No alt text provided for this image

(Image: Current DAO landscape. Source: Future)


要查看或添加评论,请登录

社区洞察

其他会员也浏览了