DEV Community

Latricia Nickelberry
Latricia Nickelberry

Posted on

Smart Contracts

Lets discuss what a smart contract is and how to write a simple one. Smart Contracts are simply programs stored on a blockchain that run when predetermined conditions are met. They typically are used to automate the execution of an agreement so that all participants can be immediately certain of the outcome, without any intermediary's involvement or time loss. This is a great definition given by IBM.

Smart contracts are pretty cool. You do not need a middle person to conduct business. Instead all you need to do is implement all the terms and conditions within the contract and it will be executed. You can create contracts for pretty much anything that you can think of, such as for selling something, for finances, the thing is that the contract will never be lost or tampered with and it will be permanent on the blockchain.

Here is a sample of an actual contract using the programing language solidity.

enter image description here
You have to make sure that you start your contract with pragma and the version. Since solidity is a statically typed language you have to define the key words such as with the next line the key word contract followed by the name of the contract. We have contracts that are excepted and used widely, such as Erc-20 token and Erc-721 tokens. I am going to discuss what is needed to create a Erc-20 Token.
Erc-20 requirements:
- Events

  • Transfer event
    • approve event

- Mandatory Functions

  • totalSupply ( ) function
    • balanceOf ( ) function
    • transfer ( ) function
    • transferFrom ( ) function
    • approve ( ) function
    • allowance ( ) function

This is what has to be in every Erc-20 token in order for it to be valid.

Top comments (0)