Build a simple Ethereum wallet | Divyansh Rai

Shared on Blockchain

editor-img
Divyansh Rai
Sept 23, 2022
shared in

Build a simple Ethereum wallet

Nowadays, wallets come in all different shapes, sizes, and features, and are used to carry bills, cards, and coins.

With the advent of digital and cryptocurrencies, wallets no longer need to be physical. You can carry your information on your cards, on your phones and watches, and your cryptocurrency wallets live in the cloud.

What is an Ethereum wallet?

Ethereum wallets are “applications that let you interact with your Ethereum account”. It lets you check your balance and send transactions.

Some popular wallets include Coinbase, ZenGo, and Binance. You need an Ethereum wallet to receive Ether.

To build a wallet, we will use Solidity. Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs which govern the behaviour of accounts within the Ethereum state.

media

// SPDX-License-Identifier: MIT

Any line that begins with two forward slashes in Solidity, signals to the compiler to ignore that line. They are usually used for adding comments in the code. The first line in my code is a comment, but an important one.

It indicates the Software Package Data Exchange (SPDX) license the code can be used under.

pragma solidity ^0.8.10;

The next line in the code tells the compiler the version of Solidity to use for compiling the code. This is important because each version of Solidity might deprecate some functionality and may introduce new build-in functions. Using the right version of Solidity allows the user to use these functionalities in their code.

The first line of real Solidity code declares a contract and gives it a name. This name is used as an identifier when compiling and deploying code.

address payable public owner;

This address identifies the contract on the blockchain. It is like a bank account for a user.

In order for a contract to receive Ether, the contract must have one of two type of functions:

  • A receive() external payable function; or
  • A fallback function

The receive() external payable function is called when a contract is sent Ether, but no call data. In the case of this wallet, it will be called each time the contract is sent Ether.

The Ether will get added to the address where this contract is deployed. An “external” function is a part of the contract interface. An external function cannot be called internally from within the contract.


Checkout related posts on: