Page cover

Writing a contract

WHAT IS A SMART CONTRACT?

A "smart contract" is simply a program that runs on the Ethereum blockchain and written in Solidity or Vyper. It's a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. They are not controlled by the user but deployed to the network and ran as programmed.

HOW DO THEY WORK? The easiest way to describe how a ethereum contract works is comparing them to a vending machine. 1 money + snack selection = 2 snack dispensed The logic of the programme is written into the contract.

WHAT CAN THEY DO? Almost anything really, Anyone can write a smart contract and deploy it to the network. You just need to learn how to code solidity or Vyper and have enough ETH to deploy your contract. Deploying a smart contract is technically a transaction, so you need to pay your Gas in the same way that you need to pay gas for a simple ETH transfer. Gas costs for contract deployment are far higher, however.

COMPOSABILITY Contracts can be used to assist you in writing other contracts as the whole blockchain is public and they can be though of as public API’s. That means you can integrate other smart contracts in your own smart contract to greatly extend what's possible. Contracts can even deploy other contracts.

LIMITATIONS The first limitation of a smart contract is that a smart contract can only be a maximum of 24KB or it will run out of gas.

SMART CONTRACT RESOURCES OpenZeppelin Contracts - Library for secure smart contract development. https://openzeppelin.com/contracts/arrow-up-right GitHub - https://github.com/OpenZeppelin/openzeppelin-contractsarrow-up-right Community Forum - https://forum.openzeppelin.com/c/general/16arrow-up-right DappSys - https://dappsys.readthedocs.io/en/latest/arrow-up-right

Further resources curated by myself: https://docs.google.com/document/d/12lL1i2x6tCP1WhmbLj6hS_eiGtCiedn_Lc2qHL4athI/editarrow-up-right

Last updated