greetings and salutations. In this guide, we will learn how to implement Solidity an object-oriented, high-level language for writing smart contracts. Smart contracts govern the behavior of accounts within the Ethereum state. A smart contract is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Smart contracts are intended to digitally facilitate, verify, or enforce the performance of a contract.
Solidity is designed to target the Ethereum Virtual Machine (EVM). Its syntax is curly-bracket and C++, Python, and JavaScript influence it. Another feature of Solidity is that it is statically typed, supports inheritance and libraries, complex user-defined types, etc. Ethereum is a decentralized blockchain platform that runs smart contracts. Ethereum Virtual Machine (EVM) is the runtime environment for smart contracts in Ethereum. EVM focuses on providing security and execution of untrusted code by computers. The EVM specializes in the prevention of DOS attacks and ensures that programs do not access other programs’ states. This ensures that communication between the programs has no interference.
Most use cases include- voting contracts, crowdfunding contracts, blind auctions, and multi-signature wallet contracts. To get started with smart contacts, please visit the links Blockchain basics, The Ethereum Virtual Machine, and smart contract. Think of Blockchain as a globally shared, transactional database where everyone can read entries in the database. To make changes to an entry in the database, you have to create a transaction that must be accepted by all others. This change can either be accepted or denied. If it is accepted, no other transaction can alter it. The Ethereum Virtual Machine is a runtime environment for smart contracts in Ethereum. Smart Contracts allow for agreements without centralized intermediaries. Simply put, Smart Contracts are self-executing sets of instructions without third parties intermediaries. These contracts are not written on paper but in code format and are automatically executed on a smart contract platform. Bitcoin was the first technology to take blockchain mainstream.
As of this writing, the latest Solidity version is v0.8.29. The official releases can be found on GitHub. Please visit the links provided for a better understanding. Solidity can be installed on your computer system in a number of ways. i.e via npm, via Docker, using binary packages and building from source. Also, you can clone a repository. This is because solidity versions follow a semantic versioning
Install and Use Solidity on Rocky / CentOS / Alma Linux
As described in the introductory part, several installation methods exist. Our guide will focus on npm and docker installation. For other installation methods, please check the official solidity website.
Method 1: Install Solidity via npm.
npm is one of the world’s largest software registries. Developers across the globe use the npm software registry to share and borrow software. Organizations deploy npm to manage private software developments. npm consists of 3 distinct components i.e the website, the command line interface, and the registry.
Step 1: Update your system
Begin the installation by updating the system packages cache.
sudo dnf update -y && sudo dnf upgrade -y
Step 2: Download and install Node.js and npm
To successfully install npm, we must install Node.js and npm command line interface using either Node version manager or a Node installer. This is because Nodejs helps to publish and install packages to and from the public npm registry or a private npm registry. nvm Node version manager is strongly recommended. The node installer method is not recommended because the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally.
To install Install Node.js, carry the following steps.
1 ) First install EPEL-release.
Install the latest EPEL-release by running the following command.
$ sudo yum install epel-release -y
#Output
Dependencies resolved.
===============================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================
Installing:
epel-release noarch 9-7.el9 extras 19 k
Transaction Summary
===============================================================================================================================================================================
Install 1 Package
Total download size: 19 k
Installed size: 26 k
Downloading Packages:
epel-release-9-7.el9.noarch.rpm 122 kB/s | 19 kB 00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 18 kB/s | 19 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : epel-release-9-7.el9.noarch 1/1
Running scriptlet: epel-release-9-7.el9.noarch 1/1
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.
Verifying : epel-release-9-7.el9.noarch 1/1
Installed:
epel-release-9-7.el9.noarch
Complete!
EPEL-release 9-7 will be installed.
2 ) Install Node.js
We will now install Node.js in our system to help us install npm.
Run the command:
$ sudo yum install nodejs
Extra Packages for Enterprise Linux 9 - x86_64 10 MB/s | 23 MB 00:02
Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64 910 B/s | 2.5 kB 00:02
Dependencies resolved.
===============================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================
Installing:
nodejs x86_64 1:16.20.2-8.el9_4 appstream 111 k
Installing dependencies:
nodejs-libs x86_64 1:16.20.2-8.el9_4 appstream 15 M
Installing weak dependencies:
nodejs-docs noarch 1:16.20.2-8.el9_4 appstream 7.1 M
nodejs-full-i18n x86_64 1:16.20.2-8.el9_4 appstream 8.2 M
npm x86_64 1:8.19.4-1.16.20.2.8.el9_4 appstream 1.7 M
Transaction Summary
===============================================================================================================================================================================
Install 5 Packages
Total download size: 32 M
Installed size: 168 M
Is this ok [y/N]: y
To check the Node.js version installed, run the command below:
$ node -v
v16.20.2
3 ) Install npm (Nodejs Package Manager )
With Node.js now successfully installed in your system, install npm to manage Node.js. Issue the command below in your terminal.
sudo yum install npm
Alternatively, you can run the command below.
sudo npm install -g npm
Once the installation completes, check the npm version installed by this command:
$ npm --version
8.19.4
Another way to check the version installed.
$ npm -v
8.19.4
Step 3: Install Solidity on Rocky / CentOS / Alma Linux
Once you have confirmed that npm was successfully installed, its time to compile Solidity on Rocky / CentOS / Alma Linux. To install the Solidity compiler, run the command below:
$ sudo npm install -g solc
added 9 packages, and audited 10 packages in 2s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.19.2 -> 9.4.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.0
npm notice Run npm install -g [email protected] to update!
npm notice
My output reveals that an update is available. I will update the package by running the command shown.
$ sudo npm install -g [email protected]
changed 15 packages, and audited 231 packages in 2s
14 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
The command above installs solidity program and makes it available globally throughout the system.
To confirm the Solidity version installed, run the command below.
$ solcjs --version
0.8.28+commit.7893614a.Emscripten.clang
We have successfully installed Solidity on Rocky / CentOS / Alma Linux.
Method 2: install Solidity via Docker on Rocky / CentOS / Alma Linux
The Docker images of Solidity are available builds are available using the solc image from the Ethereum organization. To download the latest release, use the tag stable in your code as you pull the image. For unstable versions, use the tag nightly on your code.
We will begin the process by installing Docker Engine on Rocky / CentOS / Alma Linux.
Step 1: Installing Docker Engine
Follow the steps below to install Docker Engine on Rocky / CentOS / Alma Linux.
1 ) Uninstall Old Docker Versions if they already exist.
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
It’s okay to get an output with “No packages marked for removal.”
2 ) Set up the Docker repository
Before Docker installation, set up the Docker repository. This is because it’s not shipped by default on Rocky / CentOS / Alma Linux.
Add the Docker repository with the following command. Begin by adding the yum-utils.
sudo yum install -y yum-utils
yum-utils provides the yum-config-manager.
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3 ) Install Docker Engine.
Now install the latest Docker Engine in your system by this command.
$ sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
Docker CE Stable - x86_64 486 kB/s | 62 kB 00:00
Dependencies resolved.
===============================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================
Installing:
containerd.io x86_64 1.7.25-3.1.el9 docker-ce-stable 43 M
docker-ce x86_64 3:27.5.0-1.el9 docker-ce-stable 27 M
docker-ce-cli x86_64 1:27.5.0-1.el9 docker-ce-stable 8.1 M
docker-compose-plugin x86_64 2.32.4-1.el9 docker-ce-stable 14 M
...
Transaction Summary
===============================================================================================================================================================================
Install 14 Packages
Total download size: 111 M
Installed size: 435 M
Is this ok [y/N]: y
In the process of installation, you will be prompted to accept the GPG key. Verify the fingerprints and Accept the prompt by y.
Check the Docker version installed.
$ docker -v
Docker version 27.5.0, build a187fa5
Start Docker by running this command.
sudo systemctl start docker
Check the Docker status by running the command:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
Active: active (running) since Thu 2025-01-16 18:29:30 EAT; 7s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 17069 (dockerd)
Tasks: 8
Memory: 23.4M
CPU: 131ms
CGroup: /system.slice/docker.service
└─17069 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jan 16 18:29:29 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:29.065964586+03:00" level=info msg="Starting up"
Jan 16 18:29:29 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:29.066505120+03:00" level=info msg="OTEL tracing is not configured, using no-op tracer provider"
Jan 16 18:29:29 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:29.113310426+03:00" level=info msg="Loading containers: start."
Jan 16 18:29:29 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:29.137398480+03:00" level=info msg="Firewalld: created docker-forwarding policy"
Jan 16 18:29:29 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:29.880292118+03:00" level=info msg="Firewalld: interface docker0 already part of docker zone, ret>
Jan 16 18:29:30 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:30.051714954+03:00" level=info msg="Loading containers: done."
Jan 16 18:29:30 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:30.067216088+03:00" level=info msg="Docker daemon" commit=38b84dc containerd-snapshotter=false st>
Jan 16 18:29:30 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:30.067339602+03:00" level=info msg="Daemon has completed initialization"
Jan 16 18:29:30 rocky9.cloudspinx.com dockerd[17069]: time="2025-01-16T18:29:30.112709851+03:00" level=info msg="API listen on /run/docker.sock"
Jan 16 18:29:30 rocky9.cloudspinx.com systemd[1]: Started Docker Application Container Engine.
Run a simple hello-world program to verify Docker Engine installation.
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:1b7a37f2a0e26e55ba2916e0c53bfbe60d9bd43e390e31aacd25cb3581ed74e6
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Docker Engine is successfully installed.
Step 2: Pull the Solidity Docker image
The Docker image runs the compiler executable, so you can pass all compiler arguments to it. As seen earlier, these images are available in the Ethereum organization.
Run the command below to pull the Solidity Docker image.
$ sudo docker pull ethereum/solc:stable
stable: Pulling from ethereum/solc
5e315d2b0e53: Pull complete
Digest: sha256:b3b83d65e1eae916b58e0c19b9051afa7ffc93e00f8210196639dee794a2a98a
Status: Downloaded newer image for ethereum/solc:stable
docker.io/ethereum/solc:stable
Verify the Solidity Docker image by running the command below.
$ sudo docker run ethereum/solc:stable --version
solc, the solidity compiler commandline interface
Version: 0.8.28+commit.7893614a.Linux.g++
To use Docker image to compile Solidity files on the host machine, you need to mount your input local folder and your output folder and specify the contract to compile.
The syntax looks like this:
sudo docker run -v /local/path:/sources ethereum/solc:stable -o /sources/output --abi --bin /sources/Contract.sol
It’s also possible to use the standard JSON interface. When using the standard JSON interface, you don’t mount any directories if the JSON input is self-contained.
The syntax looks like this:
sudo docker run ethereum/solc:stable --standard-json < input.json > output.json
To see all the running containers.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab7bb5a06f6a ethereum/solc:stable "/usr/bin/solc --ver…" 43 seconds ago Exited (0) 42 seconds ago reverent_archimedes
6fb0934ff15a hello-world "/hello" About a minute ago Exited (0) About a minute ago funny_joliot
Conclusion
That marks the end of our guide on how to Install and Use Solidity on Rocky / CentOS / Alma Linux. In the introduction, we looked at some definition of terms just to familiarize ourselves with Solidity. We then looked at Solidity npm and docker installation. i hope the guide has given you an exposure on what to expect from Solidity.
See the links below for more information.