If you’ve gone through a bunch of blogs riddled with code snippets and still have no clue about how to create a smart contract in Ethereum, you’re in the right place. We’ll help you sort it out without a single line of code — just the stuff a business owner needs to know.
To help you grasp the whole idea about developing smart contracts on Ethereum, let’s start off with an example.
Imagine an insurance company invents a new product — a blockchain-based travel insurance policy that compensates for delayed flights. Every passenger whose plane is late instantly gets a payout.
To pull this stunt, the company could build a smart contract application running on the Ethereum blockchain. Why not a regular web or mobile application?
Some would say it’s because smart contracts are smart — these mini-applications execute automatically when preprogrammed criteria are met. In our case, when a flight info API reports a delayed flight, a smart contract automatically initiates a payment to the insured.
Still, why not use a good old web (or mobile) app, working off a private server instead of the blockchain shenanigans? Keep reading to find out the answer and other details about how to develop a smart contract.
Table of Contents:
- Smart Contract Basics
- How Does a Smart Contract Work?
- The Benefits of Smart Contracts for Business
- Ethereum as a Platform for Creating dApps
- Programming Languages and Toolchain for Smart Contracts
- Develop a Smart Contract on Ethereum in 3 Steps
- How to Overcome Smart Contracts Shortcomings
- How Much Does it Cost to Develop a Smart Contract?
- How Long Does it Take to Create a Smart Contract?
- Time to Create an Ethereum Smart Contract
Smart Contract Basics
Don’t worry if you haven’t followed every detail in our headfirst intro. We’ll quickly recap the main concepts you need to know for creating and deploying smart contracts.
Blockchain. The place where smart contracts live. It’s like a distributed, global database that exists on countless nodes registering transactions and any other changes on the network based on consensus by appending data blocks.
There are different blockchains out there, but the one that’s most interesting to us in the light of smart contracts is Ethereum. It’s a so-called programmable blockchain. You can program it with smart contracts.
Eth — the Ethereum’s cryptocurrency generated (minted) by blockchain participants and required to carry out any transaction or execute a smart contract.
Smart contracts. These are programs written on a blockchain. You can code them on Ethereum, Hyperledger, EOS, and other blockchains. However, typically when their advantages are discussed, people talk about Ethereum-based smart contracts.
The apps that run on smart contracts are called decentralized apps (dapps) because when they run on a public blockchain, no single authority has control over them.
How Does a Smart Contract Work?
These apps are called smart contracts because they resemble written agreements, only rendered in code. They function on an if-then basis.
If predefined criteria are met, then a smart contract initiates an action. More often than not, it’s a payment, or it can be a transfer of ownership, or sometimes initiation of yet another smart contract.
Like any operation on a blockchain, every transaction performed by a smart contract is completely transparent and immutable, meaning it can’t be reversed.
The Benefits of Smart Contracts for Business
How can businesses benefit from smart contract application development? Let’s quickly review the most obvious advantages and mention a few questionable.
Since there are no intermediaries, and smart contract allows anyone to run its functions, companies don’t need to bear any additional cost usually associated with third parties involved in the process.
In other words, when you set up a smart contract, it’s almost like starting a non-stop engine generating revenue. Of course if customers find the value proposition valuable, that is.
Transparency and guaranteed outcomes
When we create a blockchain smart contract, all contract-related transactions will reflect in the chain. That literally means anyone can analyze transactions in real time. Of course, since the anonymous nature of transactions, customers won’t be able to identify involved parties down to the name. But at the same time, the frequency and dollar value of transactions provide enough details to identify so-called “whale” customers (who move the price of crypto tokens up and down).
Since I’m writing this after the FTX, Celsius, and other false defi meltdown, I want to be very specific about this inferred security. Only smart contracts with no admin keys are 100% secure. An admin key is a password that allows the contract creator to access its logic and update code. And if there’s a password, it can be stolen. The rest is the history in making.
Therefore, to achieve 100% secure operations, you need to write a smart contract with no admin keys. You deploy it once, and smart contract code keeps running without any changes whatsoever. So pay a lot of attention to security audits: at least one is required to scrutinize the contract inside out and find and remove all potential faults.
No admin keys also means that when you (and your community) decide that it’s time to update the contract, you will need to deploy a completely new (again, audited) smart contract. Because every published contract that’s trully defi sets its lines of code in stone.
Why do established brands hesitate to launch their own crypto tokens? Image Nike designing smart contracts to reward its customers? Now imagine the reputation damage to the brand if the crypto token associated with the contract goes to zero? What if frienemies get control of a massive share of tokens and dump it into the ground?
That’s why Nike decided to purchse an NFT shop, RTFKT, and use their smart contract infrastructure to sell unique kicks virtually and in real life. That’s more inline with their business and still implies Ethereum smart contract development. They utilize the OpenSea NFT platform like a vending machine, virtually selling the right to purchase unique (of course, scarce) physical sneakers.
Anyways, always remember that once you create a smart contract on Ethereum, it becomes popular, and then fails, your brand will be damaged. It’s easy to drop new smart contracts onto various chains for no-names. Brands should take multiple audits – finanial and security-related ones before creating a smart contract on Ethereum.
Ethereum as a Platform for Creating dApps
You may be wondering, “When Do I Need to Make a Smart Contract on Ethereum?”
To keep things simple, you need a smart contract-based application on Ethereum when you can think of fully automated actions for your digital product. Let’s say you’re developing a fitness app that works on a blockchain, and users earn crypto every time they workout.
Let’s also assume that you’re tracking workouts with custom sensors that customers need to purchase. You can discern fake workouts from real ones with 99% accuracy using the data coming from these gadgets. In this case, you can implement a smart contract to automatically pay out X amount of your crypto (FitnessCoin or whatever you want to call it) to users’ Ethereum wallets (e.g., MetaMask wallet) after they spend X amount of time exercising.
So, the real answer to the question, “Why not a regular application that has nothing to do with blockchain?” is the cost of operating such a product. It’s lower with automated digital contracts.
If we go back to the example of the insurance product from our intro (the one compensating for delayed flights) — even if it’s a web-based application, the insurance company needs operators and support staff to run it. However, when it’s a smart contract-based app (or dapp), it works on its own, drastically lowering the operational costs.
Another popular scenario for implementing smart contracts is initial coin offering (ICO). Let’s say you need to raise funds for developing this crypto-generating fitness app we referenced above. You run an ICO campaign, which among other things, implies minting virtual coins (FitnessCoin if you liked the name) and selling them to investors. To do that, you will need smart contracts: they are used to distribute purchased coins between users. Get in touch to discuss your use cases for blockchain development.
Programming Languages and Toolchain for Smart Contracts
There are several programming languages for coding smart contracts. Depending on a blockchain you’re working with, you will be choosing between:
- Solidity programming language
- Vyper (contract-oriented programming language, unlike Solidity which is object-oriented)
- Solidity compiler
- C++, on the EOS blockchain
- Golang, for Hyperledger
- EVM (Ethereum Virtual Machine)
Let’s also briefly mention other tools you might find useful to create your own smart contract. And while I don’t assume you’ll be coding yourself, it never hurts to have at least a high-level understanding of the skills required to get the job done.
IDEs (Integrated Development Environments) — software where programmers input code. Fortunately, there’s a couple that don’t require installation and setup because they’re entirely web-based:
Frameworks are like toolkits with plug-and-play instruments to compile and deploy a smart contract on Ethereum. They come with utilities for testing on a local blockchain instance, integration options for building other components of your dapps, and other stuff that streamlines Ethereum smart contract deployment.
- Truffle (comes with Ganache that allows you to quickly start a personal blockchain)
- OpenZeppelin SDK
Finally, you’ll need testnets (also known as testchains) or local blockchain networks for testing purposes. They do not require real ETH (Ethereum cryptocurrency) to pay for executing a smart contract, and you can request as much ETH balance as you need. Another upside is that all transactions happen immediately without the need for the global network of online nodes to calculate and verify each transaction.
Among other things you’d need to start building smart contracts, we should also mention Geth, that allows us to run an Ethereum node, which in turn is necessary to interact with other nodes on the network.
Develop a Smart Contract on Ethereum in 3 Steps
On a very high-level, to build a smart contract, you need to:
- write its code
- test it
- and finally, deploy it
Now let’s go through each step, so you know what to expect from your fintech development partner during the project before you start to build your own smart contract. [Note to developers: this is meant as a light tutorial on developing Ethereum smart contracts for beginners. So no code here.]
Developers write code using an appropriate programming language. “What’s there to know?” you might ask. Well, just a few things, really.
- Code describes the conditions for executing a contract: initiating a transaction or reaching out to another interconnected dapp.
- There are special data feeds (called oracles) that are used to connect a smart contract to off-chain, real-life events, which can be part of its execution logic.
- Developers can use open-source libraries (e.g., by OpenZeppelin) and templates. So, there’s no need to code everything from scratch.
Once you put out a smart contract onto the Ethereum blockchain (also known as mainnet), it becomes immutable. This means you won’t be able to amend it. Alas, that’s not a test-friendly scenario, right?
So what do you do to test a smart contract? You spin up a local blockchain (meaning all other nodes that make up a typical blockchain will live on your machine), or you use one of the testchains, e.g., Rinkeby.
If you are building a permissioned blockchain (i.e., the one that is not public) using Hyperledger, you will need these testnets: REMME, Hyperledger Umbra.
What these private test networks give you is instant transactions (no need to wait till another block is calculated by a node network) and free crypto, which is necessary for testing.
By deploying, we mean placing your smart contract onto the blockchain, whether it’s Ethereum or Ethereum-based private blockchain. All it takes to deploy is making a transaction, which naturally requires spending crypto. So be prepared.
One other thing to note is that the smart contract also needs to be compiled before it’s deployed. By compilation, we mean converting its code into a JSON file that can be read by a regular web app.
You can also use third-party services like Infura to host your solution when you deploy your contract.
That’s it. After these steps, you’re live, and the coded functions will kick into gears automatically when the programmed parameters will be met.
How to Overcome Smart Contracts Shortcomings
Despite all the hype about the decentralized future, there are still some disadvantages to using this technology that you should be aware of.
Immutable code means you won’t be able to reverse a contract once it has been deployed. Therefore, the cost of a bug is significantly higher than with regular software that can be patched on the fly. Fortunately, there are plenty of readily available testing environments that simulate the blockchain.
People hate to pay for each transaction on the Ethereum blockchain (the so-called gas price). Some defi apps, e.g., crypto exchanges, drive millions of transactions per day. Obviously, we need to implement mechanisms to batch several transacions into one so it’s more cost-efficient.
When public is too public
Deploying a smart contract to Ethereum implies that everyone on this blockchain will have access to it. I doubt too many businesses are ready to make their operations that transparent. Of course, an Ethereum-based permissioned (read private) blockchain is always an option: Hyperledger is a great choice, for example.
It may take between 16 seconds and 5 minutes for a smart contract to transact on Ethereum. They are working on Ethereum 2.0 that will handle 10000 transactions per second, but right now, that’s only 30 transactions per second. And guess what, there are many people in the world transacting on the Ethereum network every second. Again, private blockchain effectively solves this challenge.
[Update: as of March 6, 2023, Ethereum 2.0 is out, but it’s not yet noticeably faster for end users as more updates focused on the speed are still in the works.]
How Much Does it Cost to Develop a Smart Contract?
The cost of creating a simple smart contract may vary from $5K to $25K, depending on how many features it has, i.e. the budget always depends on the smart contract design. At the same time, you should realize that smart contract on its own, with no user interface, can’t do much. How will you get any traction if crypto noobs can’t easily interact with the contract?
So when programming smart contracts we need to alwasy assess it as a defi app to approximate its cost. We have a very transparent pricing system at Topflight that we call Vision to Traction. The system gives full control over deliverables, transparency around the spent budget, and even the one-and-only money-back guarantee.
How Long Does it Take to Create a Smart Contract?
We can make an Ethereum smart contract for a new crypto token in a matter of days. The problem is in our day and age no one really needs such contracts written in Solidity. Founders are actually looking for creating a mixture of smart contracts that work across chains and make their solution available to as many users as possible.
We aim to deliver some tanglible, testable results within 2-3 months. The rest depends on how you want to proceed. As you understand, a set of contracts to power a decentralized exchange or other complex decentralized applications may require 6-12 months.
Time to Create an Ethereum Smart Contract
As you can see, there are quite a few things to consider before you build a smart contract platform that will find real traction with users; this is also the case for fintech app development in general. At the moment, we’re building a cryptocurrency app to compete with the likes of Blockfi and Celsius.
And here’s another exciting crypto project we did for a metaverse game.
If you’d like us to review your Ethereum-based app concept or offer advice, reach out today to schedule a call.
- How to Make a DeFi Lending Platform
- How to Make a DeFi App
- How to Develop a Blockchain Application
- A Complete Guide to Developing a Fintech Application
- How to Build a Blockchain Payment System
- How to Develop a DeFi Staking Platform
- How to Build a DeFi Exchange Platform
- How to Start a DAO
Frequently Asked Questions
Modern apps nearly always have the front end user (user interface) and back end (the server-side) parts working together. How does that apply to smart contracts?
Think of them as the back-end component of your application, holding its business logic. As for the front end piece, you’re free to develop it using any web or mobile technologies.
How to build a smart contract on Ethereum, using the native tools offered by the Ethereum community?
How do smart contracts relate to Web3?
Web3 is the future of our current web technologies as we know and use them. While Gmail, Facebook, and other web applications are seen as Web2 apps, Web3 will be all about decentralized applications (fueled by dapps).
Is there a way to design a smart contract that has the benefit of being distributed on a shared ledger but at the same time does not reveal transactions to a wider public?
Yes, if you implement it on a private permissioned blockchain, for example, using Hyperledger, Azure Blockchain Workbench, or similar solutions.