Deploying a Smart Contract to the Blockchain Network
Published: 2023-02-14 15:49:41

---
title: Deploying a Smart Contract to the Blockchain Network
published: true
date: 2022-11-28 12:51:02 UTC
tags: 
canonical_url: https://blog.michaeltech.xyz/deploying-a-smart-contract-to-the-blockchain-network
---

![Deploying a smart contract to the blockchain network](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wt6vezqiv6of8o6biqf6.png)


We'll be looking at a quick guide to writing and deploying a smart contract to the blockchain network.

Let's begin by looking at a simple contract program that stores and retrieves the value of a variable on the blockchain.

```
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

```

The first line of code identifies the license in use for the program, the second line is a directive that specifies the version of solidity compilers that should be used for the contract.

The _uint_ (unsigned integer) variable _storedData_ is declared. two functions \*set \*and \*get \*are created to alter and return the variable's value.

```
pragma solidity >=0.4.16 <0.9.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

```

We'll be interacting with our Solidity project with the use of an online Solidity IDE called [Remix](https://remix-project.org/)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1669636964419/Ua6EB_-Hy.png)

Once the contract has been compiled successfully you can deploy and interact with it on the Remix IDE. When the contract has been deployed, under Deployed contracts you will see the name of the contract and the two buttons _set_ and _get_ representing the two functions in the contract which can be used to modify and retrieve the value of the stored variable.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1669637600115/maT2niW5P.png)

In real-time use cases, contracts are deployed to blockchain networks, let's deploy this contract to the Polygon network, Contracts on the blockchain require a gas fee(cost of making a blockchain transaction) but we'll be using a test network which will not require real money. For us to pay the gas fee we'll be using a cryptocurrency wallet like [Metamask](https://metamask.io/download/) , download [Metamask](https://metamask.io/download/) here though you can choose to use any other non-custodial wallet. We'll be using the Polygon Mumbai Test network to host our smart contract, To connect your MetaMask Wallet to the Polygon Mumbai Testnet, visit this website https://chainlist.org/ and search for polygon, you'll see the Mumbai option under the search results, go ahead and select it.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1669638795737/LBiBCGsqN.png)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1669638810705/JVs45T-S4.png)

Once you have done that, you need to get some test MATICS to start with, you will get it from [here](https://faucet.polygon.technology/). Input your wallet address and voila you've got some cash!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1671542612161/OgMSu3bOi.png)

To deploy your contract to the testnet, go to the Remix IDE, and instead of the default JavaScript VM, select Injected Web3.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1669639033842/MqQpAamHn.png)

Your wallet will pop up and require permission, your contract is now deployed and hosted on the Polygon Mumbai Testnet. Congrats on the successful deployment of your smart contract!