How to build Dapp (solidity) part 1

Fred J Dreward
3 min readFeb 17, 2022
web 3 illustration

Dapps are a new form of technology that provides a way to share power in a network. Traditionally, when you access internet services like Google Maps or Facebook, the data you create is analyzed and stored on centralized servers. The data might eventually be deleted if it’s no longer relevant to the service’s functions, but chances are that your personal information — from your search history to location data — will be shared with third parties without your consent or knowledge. Dapps change this model by using decentralized networks which analyzes data locally and stores it on devices like laptops, phones, tablets. Therefore there is no need for users’ personal information to be shared with third party servers unlike traditional apps.

(1) Create Solidity Contract: The Solidity is a contract-oriented, high-level language for implementing smart contracts. It was influenced by C++, Python and JavaScript. It is statically typed, supports inheritance, libraries and complex user-defined types among other features.

Solidity provides a turing complete language which supports many of the programming structures common in modern programming languages. Since Ethereum also runs on each block chain node and contains a full implementation of the EVM it can be used to deploy ‘global decentralized applications’. This allows developers to create markets, store registries of debts or promises, move funds in accordance with instructions given long in the past etc.

The Solidity compiler, written in the Rust language, translates Solidity source code into Ethereum Virtual Machine bytecode and optionally into JavaScript. Other implementations are available but they are either incomplete or unstable.

Let’s start with a simple example to create a basic smart contract in solidity. You will need to create your own private/public key pair. This will be used by your newly created Ethereum account to sign transactions in the network.

(2) Deploy Smart Contract: In Solidity, contracts are stored in their own files with the “.sol” extension. Contracts can be compiled using the command line “solc” compiler which is included with all Ethereum clients (e.g., geth).

Solidity-code contracts are deployed to the Ethereum blockchain in a transaction. The first time a contract is created it is given an initial supply of zero, and cannot be changed. Contracts are also given their own address on the blockchain and can be thought of as an account.

The contract will have access to persistent storage and memory, holding variables that we can use. Using Solidity’s inheritance feature we can create contracts that inherit and are able to modify variables from parent contracts, including their state variables. This will make each contract simple, modular, and easily auditable.

we’ll create four files named: .sol, .json, .keystore, and .asset files. The last file is optional and only needed if you plan to deploy the dapp to a blockchain. For this tutorial we ll use the ‘Kovan’ test instance of Ethereum Blockchain as our target blockchain.

There are two steps to creating a dapp: first we need to create our frontend interface, then add in code for the backend server script (written in solidity).

We ll assume that you have already created a solidity testnet Ethereum developer account, installed the latest version of Ethereum client, and downloaded the ‘Kovan’ blockchain. If you haven’t created an account yet, now is a good time to do so.

Create a directory named: dapp

Copy everything into it except for the contract files (.sol and .json). We ll refer to these as the frontend and backend files. The bundle of all four files should be placed in your executable directory (e.g., C:\Program Files\enigma-dapp\dapp\contracts or wherever you store your other files).

Open the .sol file in a text editor. Copy and paste the following code:

/** * @title Confirmation * @dev Confirm a transaction that was sent from given sender. * @param _sender The address of the sender. * @param _transactionHash The hash of the transaction which should be confirmed. */ contract Confirmation { function confirm(address _sender, bytes32 _transactionHash) public; }

This is your basic definition contract, which specifies what this dapp will do (confirming a transaction). It s not necessarily the actual dapp you want to create at this point, but it will be used as a framework or model for our real dapp later.

--

--

Fred J Dreward

I trade in free time. I’m a senior developer and web3 developer, and I also love music