Deploying Solidity contract on Ethereum

Solidity is a high-level programming language for writing smart contracts on blockchain platforms. Ethereum is the most popular and widely used implementation. Ethereum serves as the underlying blockchain network where Solidity smart contracts are deployed and executed.

What is a Solidity contract?

A Solidity contract is a collection of code, including data and functions, that defines its rules and logic. Once deployed, the contract resides at a specific address on the Ethereum blockchain.

Deploying a Solidity contract

Deploying a Solidity contract on Ethereum involves the following steps:

  1. Selecting the development environment

  2. Writing the Solidity contract

  3. Deploying the contract on the Ethereum blockchain

  4. Interacting with the deployed contract

Selecting the development environment

Before writing a smart contract, it’s important to select a development environment that aligns with our requirements. Several options for this purpose include Remix, Visual Studio Code, and IntelliJ IDEA.

Writing the Solidity contract

After selecting the development environment, our next step is to write the Solidity contract code.

In the code below, we create an example contract helloWorld with a message variable and getter/setter functions for it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.5.0;
contract HelloWorld {
string public message;
constructor (string memory myMessage) public {
message = myMessage;
}
function setMessage(string memory newMessage) public {
message = newMessage;
}
function getMessage() public view returns (string memory) {
return message;
}
}

Deploying the contract on the Ethereum blockchain

Remix is a web-based IDE specifically designed for writing, testing, and deploying smart contracts directly from our browser. We will use the Remix IDE to deploy our code on Ethereum. We’ll also need to have the MetaMaskMetaMask is the crypto wallet which allows users to interact with the Ethereum and other blockchains, directly from their web browsers. extension installed in our Chrome browser for the deployment of the contract.

  • Go to the Remix web-based IDE and create a Solidity contract file in the “FILE EXPLORER” panel. We create the helloWorld.sol file for our contract.

Creating the helloWorld.sol file in the "FILE EXPLORER" panel
Creating the helloWorld.sol file in the "FILE EXPLORER" panel
  • To compile the code, select the source file and go to the “SOLIDITY COMPILER” panel. Make sure to select an appropriate compiler version for the file and click “Compile fileName.sol.” After compiling the code, our contract is ready to be deployed.

Compiling the helloWorld.sol file in the "SOLIDITY COMPILER" panel
Compiling the helloWorld.sol file in the "SOLIDITY COMPILER" panel
  • Go to the “DEPLOY & RUN TRANSACTIONS” panel and select the blockchain in which the contract needs to be deployed in the “ENVIRONMENT” field. We’ll select the “Inject Provider - MetaMask” so Remix can read data from our Metamask account and deploy it to any blockchain it’s connected to.

The "DEPLOY & RUN TRANSACTIONS" panel
The "DEPLOY & RUN TRANSACTIONS" panel
  • Now, go to MetaMaskhttps://metamask.io/ and connect to the Sopolia test network after creating the account.

Note: It's recommended to use an Ethereum account with no real Ether balance on mainnets to ensure that we do not make any costly mistakes. We are using the Sepolia test network as its a safe environment for learning and testing.

Connecting MetaMask account to the Sepolia test network
Connecting MetaMask account to the Sepolia test network
  • We’ll need some test ETH to deploy our contract, which can be obtained from a faucethttps://www.alchemy.com/faucets/ethereum-sepolia. Once the transaction is completed, our METAMASK balance should show some amount of Sepolia ETH.

The METAMASK account
The METAMASK account
  • The “DEPLOY & RUN TRANSACTIONS” panel should now display the “Sepolia (11155111) network” in the “ENVIRONMENT” field and our current account and its balance in the “ACCOUNT” field.

Setting "ENVIRONMENT" in the "DEPLOY & RUN TRANSACTIONS" panel
Setting "ENVIRONMENT" in the "DEPLOY & RUN TRANSACTIONS" panel
  • Now, we are ready to deploy our contract. Select the helloWorld.sol in the “CONTRACT” field, provide the input string for the message variable, for example, “Hello World” and click the “Deploy” button. MetaMask will ask us to confirm the transaction for creating the contract on the blockchain, which costs some amount of test ETH. Click the “Confirm” button.

Deploying the helloWorld.sol contract
Deploying the helloWorld.sol contract
  • Once the transaction is successful, the “Deployed/Unpinned Contracts” section shows the address of our contract on the Sepolia test network.

Address of the deployed contract in the "Deployed/Unpinned Contracts" section
Address of the deployed contract in the "Deployed/Unpinned Contracts" section

Interacting with the deployed contract

Once our contract is deployed, we can interact with it in the “Deployed/Unpinned Contracts” field.

Deployed contract
Deployed contract
  • Click the “getMessage” button, and it will execute the getMessage() function of our contract. The function will retrieve the current value of the message variable, and the retrieved value will be displayed below the button.

Calling the getMessage() fucntion
Calling the getMessage() fucntion
  • Click the “message” button, and it will retrieve the current value of the message variable without calling any function, and the retrieved value will be displayed below the button.

Retrieving the value of message variable
Retrieving the value of message variable
  • Set a new value for the message variable by passing the value and clicking the “setMessage” button. It will execute the setMessage() function of the contract to set a new value for the message variable.

Calling the setMessage() function
Calling the setMessage() function

Note: Every time we interact with a function that changes the state of the contract (like setting a new message), we'll need to pay gas fees to miners for processing and validating our transaction on the Ethereum network.

Conclusion

Understanding how to deploy› Solidity contracts on Ethereum is essential for anyone looking to leverage the power of blockchain technology. With tools like Remix and MetaMask, the deployment process becomes accessible, allowing developers to create decentralized applications with predefined rules and logic. As we continue to explore the potential of blockchain technology, understanding how to deploy Solidity contracts will remain a fundamental skill for developers.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved