Apa fungsi approve pada menu write contract di etherscan

Ever since Ethereum was introduced in the blockchain space with its presence in 2015, Vitalik Buterin, a Canadian-Russian programmer, has brought forth new decentralized applications (dApps). However, Ethereum’s success is significantly attributed to the implementation of smart contracts.

Many people believe that smart contracts are a new concept and were invented with the Ethereum Blockchain Platform. But smart contracts date back to 1996 when computer scientist Nick Szabo coined the term “smart contracts” and explained them as:

I call these new contracts “smart”, because they are far more functional than their inanimate paper-based ancestors. No use of artificial intelligence is implied. A smart contract is a set of promises specified in digital form, including protocols within which the parties perform on these promises.

His work later inspired other scientists and researchers, as well as Vitalik, who developed Ethereum.

Before we go deeper into the creation and deployment of the Ethereum smart contract, it is essential to understand the Ethereum platform and how it works.

Ethereum, as a Blockchain Platform for developing decentralized applications

Blockchain platforms allow developers to create and run smart contracts. Ethereum is also one of the blockchain platforms that can execute arbitrary code so that you can perform any program on Ethereum.

The Ethereum Blockchain is a potential distributed infrastructure that facilitates you to complete projects using smart contracts.

  • Create your cryptocurrencies
    Ethereum, you can create a tradable token that you can use as a new currency. Tokens created with the Ethereum platform use a standard coin API to be compatible with any Ethereum blockchain wallet.
  • Develop virtual organizations
    You can write a smart contract to build a blockchain-based organization. You can then add more people to your organization and enable voting rules. Members of your organization can vote and if it reaches the required number of votes, the smart contract executes automatically.
  • Build dApps
    Ethereum allows developers to develop secure and fault-tolerant decentralized apps that eliminate intermediaries and offer transparency.
  • Raise funds
    You can also use Ethereum smart contracts for fundraising. With Ethereum, you can write a smart contract and a deadline. In case you fail to accomplish the goal, all donations will automatically be reimbursed to donors without disputes or commissions.

How Ethereum Blockchain Platform executes Smart Contracts

Before discussing how to create a smart contract on the Ethereum platform, you need to understand the Ethereum blockchain and how it runs smart contracts.

So, let’s understand the execution environment first.

Ethereum Virtual Machine (EVM)

The purpose of EVM is to serve as a runtime environment for smart contracts built on Ethereum. Consider it as a global supercomputer that executes all the smart contracts.

As the name indicates, Ethereum Virtual Machine is not physical but a virtual machine. The functionality of EVM is restricted to virtual machines; for example, it cannot make delayed calls on the internet or produce random numbers. Therefore, it is considered a simple state machine. Writing programs in assembly language do not make any sense, so, Ethereum required a programming language for the EVM.

Gas

In the Ethereum Virtual Machine, gas is a measurement unit used for assigning fees to each transaction with a smart contract. Each computation happening in the EVM needs some amount of gas. The more complex the computation is, the more the gas is required to run the smart contracts.

Transaction fee = Total gas used*gas price

Solidity

Solidity is a smart contract programming language on Ethereum. Developed on the top of the EVM, it is similar to the object-oriented programming language that uses class and methods. It allows you to perform arbitrary computations, but it is used to send and receive tokens and store states. When it comes to syntax, Solidity is greatly influenced by C++, Python, and Javascript so that developers can understand its syntax quickly.

It would be best to have a good understanding of Solidity programming language to efficiently write an Ethereum Smart Contract.

What is a Smart Contract?

Smart Contracts are the business logic or a protocol according to which all the transactions on a Blockchain happen. The smart contract’s general objective is to satisfy common contractual conditions like creating its own token on ethereum. We need to develop smart contracts according to which all the calculations on our token would happen.

It is a stand-alone script written in Solidity and compiled into JSON and deployed to a particular address on the blockchain. Just like we can call a URL endpoint of a RESTful API to run some logic through an HttpRequest, we can execute deployed smart contract similarly at a particular address by entering the accurate data along with Ethereum to call the compiled and deployed Solidity function.

Smart contracts are deployed to the decentralized database for a fee proportional to the containing code’s storage size. It can also be defined as a collection of code stored in the blockchain network, defining conditions to which all parties within the contract should agree.

We will be sharing the example of Ethereum smart contract creation using the Solidity programming language. So, it is first essential to understand what is Solidity.

What is Solidity?

Solidity is a Javascript-like language developed specifically for creating smart contracts. It is typed statically and supports libraries, inheritance and complex user-defined types.

Solidity compiler converts code into EVM bytecode which is sent to the Ethereum network as a deployment transaction.

Here’s a step-by-step guide to creating and deploying Ethereum Smart Contracts with Solidity

Installing Prerequisites

Meta-mask Chrome Extension

MetaMask acts both as an Ethereum browser and a wallet. It allows you to interact with smart contracts and dApps on the web without downloading the blockchain or installing any software. You only need to add MetaMask as a Chrome Extension, create a wallet and submit Ether.

Though MetaMask is currently available for Google Chrome browser, it is expected to launch for Firefox too in the coming years.

Download MetaMask chrome extension before you start writing smart contracts.

Once it is downloaded and added as a Chrome extension, you can either import an already created wallet or create a new wallet. You must have some ethers in your Ethereum wallet to deploy Ethereum smart contract on the network.

Apa fungsi approve pada menu write contract di etherscan

Steps to develop an Ethereum Smart Contract

Step 1: Create a wallet at meta-mask

Install MetaMask in your Chrome browser and enable it. Once it is installed, click on its icon on the top right of the browser page. Clicking on it will open it in a new tab of the browser.

Click on “Create Wallet” and agree to the terms and conditions by clicking “I agree” to proceed further. It will ask you to create a password.

After you create a password, it will send you a secret backup phrase used for backing up and restoring the account. Do not disclose it or share it with someone, as this phrase can take away your Ethers.

Apa fungsi approve pada menu write contract di etherscan

You should either write this phrase on a piece of paper securely or store it safely on an external encrypted hard drive where no one could find it.

The next step is to ensure that you are in the “Main Ethereum Network.” If you find a checkmark next to “Main Ethereum Network”, you are in the right place.

Step 2: Select any one test network

You might also find the following test networks in your MetaMask wallet:

  • Robsten Test Network
  • Kovan Test Network
  • Rinkeby Test Network
  • Goerli Test Network

Apa fungsi approve pada menu write contract di etherscan

The above networks are for testing purposes only; note that these networks’ ethers have no real value.

Step 3: Add some dummy Ethers to your wallet

In case you want to test the smart contract, you must have some dummy ethers in your MetaMask wallet.

For example, if you want to test a contract using the Robsten test network, select it and you will find 0 ETH as the initial balance in your account.

To add dummy ethers, click on the “Deposit” and “Get Ether” buttons under Test Faucet.