15 Tips to Write Better Smart Contracts
Start by defining the purpose and end by making sure it works

1. Define the Purpose
Before starting, make sure you have a clear understanding of what your smart contract is supposed to do. What value does it add? How should it be used? Consider the question of whether or not it even needs to be a blockchain application. Would it be better implemented on more well-established technology platforms?
Have a clear view of the purpose of your smart contract.
2. Check if It Has Been Done Before
Never spend the time rewriting something that already exists. If what you’re trying to create is a different flavour of an existing concept, consider extending work that has been done by others.
Openzeppelin provides a library of contracts that implement EIPs like ERC-20, and ERC-721. Utilise these by extending their functionality instead of writing your own from scratch.
3. Name It
Having a clear purpose should make naming your smart contract easy. If you have experience developing in object-oriented languages, name it as you would a class.
Names should be clear, descriptive, and succinct. It should have as few words as possible, ideally one or two. It should describe what the contract is, what it does, and indicate what it’s responsible for.
4. Chose Your Development Environment
If you’ve had experience developing software already, you’ll likely have a preferred IDE to code in. Multiple IDEs support Solidity development. My favourite is VS Code, a free text editor created by Microsoft, with the Solidity extension.
If you’re less experienced and don’t want to have to worry about setting up your environment, Ethereum provides a great online IDE called Remix. It allows you to start coding, compiling, and deploying immediately.
5. Is It a Standalone Smart Contract?
Sometimes smart contracts get very long and very complicated. If your contract has so many responsibilities that the name doesn’t describe everything it does, consider separating concerns and using multiple smart contracts.
If you expect your project to span across multiple smart contracts, consider using Truffle Suite as the framework for your project. Truffle makes it easy to write DApps on top of your contract.
6. Chose Solidity Version
Find out the latest stable version of Solidity and familiarise yourself with its syntax. If you’re extending libraries, make sure your chosen version isn’t ahead of the version that the libraries support.
For example, Openzeppelin contracts library version 0.2.5 supports Solidity version 0.5.5, but not 0.6.x.
7. Does It Do Any Maths?
If you expect your smart contract to perform mathematical calculations, refrain from using arithmetic operators like plus(+), minus(-), multiply(*), divide(/), and modulus (%). Without proper checks, they have the potential to introduce underflow and overflow vulnerabilities.
Use Openzeppelin’s SafeMath library for unsigned integer operations.






