The Wayback Machine - https://web.archive.org/web/20241122171841/https://www.geeksforgeeks.org/how-to-use-metamask-to-deploy-a-smart-contract-in-solidity-blockchain/
Open In App

How to use MetaMask to Deploy a Smart contract in Solidity (Blockchain)?

Last Updated : 08 Jan, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Smart contracts are self-executing contracts. They were first proposed by Nick Szabo in the 90s. They are set of rules and protocols which two parties agree upon and have to follow. One of the main features is that they are immutable once deployed on the blockchain. It is widely used in the Ethereum blockchain. The main language used for writing smart contracts in Solidity.

IDE

To write and execute solidity codes, the most common IDE used is an online IDE known as REMIX. You can either open it online on https://remix.ethereum.org/ or install it in your system from https://github.com/ethereum/remix-ide. You can also use Mist (the Ethereum DApp browser).  

After you write the code and compile it you can deploy it in following ways –

  • Remix VM (London)
  • Remix VM (Berlin)
  • Injected Provider – MetaMask
  • Hardhat Provider
  • Ganache Provider
  • Foundry Provider
  • Wallet Connect
  • External Http Provider
  • L2 – Optimism Provider
  • L2 – Arbitrum One Provider

This article explains how to deploy your contract by using MetaMask as Injected Provider – MetaMask.

MetaMask 

MetaMask is a type of Ethereum wallet that bridges the gap between the user interfaces for Ethereum (e.g. Mist browsers, DApps) and the regular web (e.g. Chrome, Firefox, websites).

Its function is to inject a JavaScript library called web3.js into the namespace of each page your browser loads. Web3.js is written by the Ethereum core team. MetaMask is mainly used as a plugin in chrome. You can add it from here or download it directly from this link.

After adding MetaMask as an extension in chrome and creating an account, set up your account as follows –

Step 1: Select Goerli Test Network from a list of available networks as below:

Metamask

Step 2: Request test ether by using this link : https://goerlifaucet.com/

Goerli Faucet

Step 3: MetaMask is ready for deployment. To know more about MetaMask visit the MetaMask official guide.

Steps to deploy your contract

Step 1: Open Remix IDE in your browser. After opening click on + and write the filename as follows:

Create a contract

Step 2: Write the following sample code for testing and compile by clicking on the compile button as shown:

Solidity




// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
 
// Creating a contract
contract shreyansh_05
{
    // Defining a function
    function get_output() public pure returns (string memory){
        return ("Hi, your contract ran successfully");
    }
}


Compile the ni.sol  file

Step 3: After compilation and move to deploy section just below the compilation and select Injected Provider – MetaMask in place of Remix VM as shown below –

Select the Injected Provider – Metamask

Step 4: Now your contract is ready to be deployed. Click on deploy button and the MetaMask will ask for confirmation as follows –  

Click the Confirm Button

Step 5: After confirmation, the deployed contract will look like –

Deployed Contract

Step 6: Expand the deployed contract as below and get the output using the get_output() function:

Output

Step 7: Now, to verify whether your transaction (process) executed successfully, you can check your balance on MetaMask.

Now your contract is completely ready to function. Make sure the compiler version matches the version of your solidity code. This is the basic implementation of MetaMask with solidity. 


Previous Article
Next Article

Similar Reads

How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
There are various processes involved in deploying a smart contract using Ganache and Truffle Suite: 1. Install Ganache first. Ganache is a personal blockchain for Ethereum development. You must first download and install it. It is available for download from https://www.trufflesuite.com/ganache, the official website. 2. Install Truffle Suite: The n
4 min read
Solidity - Deploy a Smart Contract for Marks Management System
Solidity is a high-level language. The structure of smart contracts in solidity is very similar to the structure of classes in object-oriented languages. The solidity file has an extension .sol. What are Smart Contracts?Solidity’s code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (
3 min read
Steps to Execute Solidity Smart Contract using Remix IDE
Remix IDE is generally used to compile and run Solidity smart contracts. Below are the steps for the compilation, execution, and debugging of the smart contract. Step 1: Open Remix IDE on any of your browsers, select on New File and click on Solidity to choose the environment. Step 2: Write the Smart contract in the code section, and click the Comp
1 min read
Creating a Smart Contract that Returns Address and Balance of Owner using Solidity
Problem: Create a smart contract named MyContract having a state variable as owner. Create a constructor to fetch the address of the owner from msg and hold it into the state variable owner. Also, create a function getBalance() to show the current balance of the owner. Solution: Every smart contract is owned by an address called as owner. A smart c
2 min read
What is Smart Contract in Solidity?
Solidity's code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. A contract is a fundamental block of building an application on Ethereum. Now let's look at the code example for making smart contract : Example #
4 min read
Decentralized Bank Smart Contract in Solidity
Solidity is an Object-oriented Programming Language for implementing Smart Contracts. It's a High-Level Statically Typed Language like C. The solidity file has an extension .sol. The article focuses on discussing the decentralized bank smart contract in Solidity. In the below example, the aim is to deploy a Smart Contract for Decentralized Bank Sys
3 min read
Make HTTP Request Using Your Solidity Smart Contract
Smart contracts are self-executing digital programs that are designed to automate the enforcement of the terms of a contract. Solidity is a programming language used to write these smart contracts on the Ethereum blockchain. One of the challenges with smart contracts is their inability to interact with the outside world, including making HTTP reque
10 min read
Unlock the Power of Solidity: Exploring the Essential Keywords for Smart Contract Development
Solidity is a smart contract programming language built solely to develop smart contracts that can be deployed on blockchains. C++ and JavaScript inspired it, an Object Oriented and High-Level language (HLL), that helps developers define the behaviour and rules for a Decentralized Application (Dapp). Smart contract facilitates autonomous, secure, a
13 min read
How to Simply Deploy a Smart Contract on Ethereum?
Smart contracts are blocks of code that reside on the blockchain. It is like an Ethereum account but there is a critical difference between an external account and a smart contract. Unlike a smart contract, an external account can connect to multiple Ethereum networks (Goerli testnet, mainnet, etc.) whereas a smart contract is only specific to one
7 min read
Deploy a Smart Contract on Ethereum with Python, Truffle and web3py
This article discusses deploying a Smart Contract on Ethereum with Python, Truffle, and web3py. Prerequisite: In order to write a simple smart contract, deploy it to a personal Ethereum blockchain, and call the contract using Python3, install the below software on a PC: 1. Python3 v3.5.3 or later versions: Install python following the instructions
6 min read
Steps to Create, Test and Deploy Ethereum Smart Contract
Smart contracts are self-execution programs stored on a blockchain that are automatically executed when predefined conditions are met. They allow the participants on the blockchain to transact with each other without a trusted central authority. After creating a smart contract, the next step is to deploy the smart contract onto a blockchain for exe
7 min read
How to deploy Smart Contracts using Ethers.js and Node.js on Goerli Testnet Blockchain from Back-end ?
In this article, we will be deploying smart contracts on blockchain from back-end, so that we do not have to require hardhat or truffle frameworks and their commands to deploy a smart contract or if somebody doesn't want to use these frameworks. Since we have to run manual commands of these frameworks in the terminal to deploy Smart Contracts. We c
9 min read
How to Install and Use Metamask on Google Chrome?
MetaMask is a type of cryptocurrency wallet that is used to interact with user interfaces of different web3 applications(For example, Mist browsers, DApps) and the regular web (For example, Google Chrome, Mozilla Firefox, websites). Its function is to inject a JavaScript library called web3.js into the namespace of each page your browser loads. Web
3 min read
Solidity - Abstract Contract
Abstract contracts are contracts that have at least one function without its implementation or in the case when you don't provide arguments for all of the base contract constructors. Also in the case when we don't intend to create a contract directly we can consider the contract to be abstract. An instance of an abstract cannot be created. Abstract
3 min read
Interaction Between Smart Contracts with Solidity
Interaction between two smart contracts in Solidity means invoking functions of one contract from another contract so that we can use the content of one contract in another. For example, if you want to use contractA methods into contractB, so simply import the contractA inside contract B and create an instance of contractA then call methods using t
5 min read
Building a Simple Fixed Deposit Application Using Solidity Smart Contracts
Blockchain technology has revolutionized the way we handle financial transactions, and the world of decentralized finance (DeFi) is growing at an unprecedented rate. One of the most intriguing aspects of this financial evolution is the use of smart contracts, which are self-executing agreements with the power to automate and secure various financia
13 min read
What is Escrow Smart Contract?
Escrow is the third party that holds the asset(asset can be money, bond, or stocks) in the presence of two parties. Escrow will release the fund when certain conditions are met. For Example: "A" is a seller and wants to sell his car, and "B" is a buyer who wants to buy "A"'s car so they will contact Escrow "C"(an arbiter) which holds the asset unti
2 min read
What is Wallet Smart Contract?
Wallets are just like your bank account, through which we can receive money, send money, and can check the balance. Important terms:uint- unsigned integer.address- It is a unique set of the string provided for the transaction.msg.sender- Address of the current user.msg.value- Cost put by the current user.public- Visibility of the function.view- Thi
4 min read
Smart Contract to Store Employee Details
Solidity is a high-level language. The structure of smart contracts in solidity is very similar to the structure of classes in object-oriented languages. The solidity file has an extension .sol. What are Smart Contracts? Solidity’s code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data
3 min read
Deploying Smart Contract on Test/Main Network Using Truffle
A Smart Contract is a computer program that directly and automatically controls the transfer of digital assets between the parties under certain conditions. A smart contract works in the same way as a traditional contract while also automatically enforcing the contract. Smart contracts are programs that execute exactly as they are set up(coded, pro
5 min read
Interacting With Ethereum Smart Contract Using Web3js
Ethereum is a cryptocurrency platform in the market just like Bitcoin. It is an open-source & decentralized blockchain featuring working on smart contracts. It has its own cryptocurrency known as ether. The smart contracts in Ethereum are written in solidity. TestRPC The Ethereum TestRPC is like a manual emulator for blockchain. It provides blo
4 min read
Setting Up Smart Contract Development Environment
A development environment is an environment in which all the resources and tools are available which are used to develop a program or software product. Here, an attempt to create a development environment that is a collection of the processes and tools that are used to develop smart contracts. There are mainly two choices available to set up the en
5 min read
How to Test a Smart Contract for Ethereum?
Public Blockchains like Ethereum are immutable, it is difficult to update the code of a smart contract once it has been deployed. To guarantee security, smart contracts must be tested before they are deployed to Mainnet. There are several strategies for testing contracts, but a test suite comprised of various tools and approaches is suitable for de
15+ min read
How to Test a Smart Contract with Remix?
The Remix IDE is an open-source development environment for building, testing, and deploying smart contracts on the Ethereum blockchain. One of the most notable features of Remix IDE is its integration with the Solidity programming language. Solidity is a contract-oriented language that is specifically designed for building smart contracts on Ether
7 min read
How to Calling Smart Contract Functions with Web3.js?
Have you wondered how smart contracts interact with the front end? So, the answer is the web3.js library. First, briefly discuss some terms related to web3.js and learn about them. Web3.js: Web3. js is a collection of libraries that allow users to interact between smart contracts and the front end. It is used to develop websites that can interact w
4 min read
What is a NFT Smart Contract?
NFT Smart contracts play an important role in the blockchain space across many use cases. In particular, NFT smart contracts are becoming increasingly important as the metaverse and Web3 attract more interest. NFT smart contracts are specialized blockchain contracts that facilitate the creation, ownership, transfer, and management of NFTs. This art
8 min read
Integrating your Smart Contract with Frontend
In this article, we are going to learn how to connect a smart contract to the front end. To keep the process less complex and focus on the integration process, the smart contract in itself is kept simple. You can easily introduce multiple complex functions once you understand the basics. For this tutorial, we are simply putting a campaign on the lo
14 min read
Life Cycle of Smart Contract
Smart contracts are self-executing agreements with the terms directly written into code. Understanding their life cycle is essential for anyone involved in blockchain development. This life cycle includes key phases such as development, testing, deployment, interaction, and maintenance. Each phase plays a crucial role in ensuring the contract funct
7 min read
How to Deploy Contract From NodeJS using Web3?
This article focuses on discussing deploying a contract from NodeJS using web3. The following topics will be covered in this article: Introduction to web3js modules.How to generate ABI and bytecode using web3js.Compilation and deployment of smart contracts using web3js.Software requirements: Nodejs.Ganache.Text editor - VS Code1. Introduction to we
6 min read
How To Fix the Error "Metamask stopped injecting Web3"?
Let's see some basic terminologies first as follows: Metamask: Metamask is a cryptocurrency software wallet that interacts with the Ethereum network.web3.js: web3.js is a collection of libraries that allow you to interact with a local or remote Ethereum node using HTTP, IPC, or WebSocket. Blockchain: A blockchain is a digitally distributed, decentr
4 min read
Article Tags :
three90RightbarBannerImg