Skip to content

Latest commit

 

History

History
131 lines (74 loc) · 7.43 KB

deploy-a-smart-contract-using-remix.md

File metadata and controls

131 lines (74 loc) · 7.43 KB
description
A step-by-step tutorial on how to create and deploy a smart contract on the Hedera network using Remix IDE.

Deploy a Smart Contract Using Remix

Introduction to Remix

Remix IDE is an open-source tool for developing smart contracts in Solidity for the Ethereum network. It offers built-in compiling, debugging, and deploying features, streamlining the development process. This tutorial will leverage Remix IDE to create and deploy a simple smart contract on the Hedera network.


Prerequisites

  • Web browser with access to Remix IDE.
  • Create a Hedera ECDSA testnet account.
  • Download the MetaMask wallet browser extension.

Add Hedera Testnet to your MetaMask

Before deploying a smart contract to the Hedera network using Remix, add Hedera Testnet as a custom network to MetaMask.

  1. Open the MetaMask wallet extension and navigate to Settings > Networks > Add a Network > Add a network manually then add the Hedera Testnet details:

  1. Switch the network to Hedera Testnet and add your account by importing your hex-encoded ECDSA private key to MetaMask.

Here is a more comprehensive guide on importing a Hedera account into MetaMask.


Create a Smart Contract

Open your web browser and navigate to Remix IDE. Click on the file icon in the File Explorer tab to create a new file and name it HelloHedera.sol .

Copy and paste this sample contract to the new file you created:

//SPDX-License-Identifier: MIT

pragma solidity 0.8.22;

contract SampleContract {
    string public myString = "Hello Hedera";

    function updateString(string memory _newString) public {
        myString = _newString;
    }
}

Compile the Contract

Navigate to the Solidity Compiler tab in the left sidebar and check that your compiler version is within the versions specified in the pragma solidity statement. Then, compile your HelloHedera.sol contract.

When a compilation for a Solidity file succeeds, Remix creates three JSON files for each compiled contract. Files can be seen in the File Explorers plugin as:

  1. artifacts/<contractName>.json: contains the link to the libraries, the bytecode, the deployed bytecode, the gas estimation, the method identifiers, and the ABI. It is used for linking a library address to the file.
  2. artifacts/<contractName_metadata>.json: contains the metadata from the output of Solidity compilation.
  3. artifacts/build-info/<dynamic_hash>.json: contains info about solc compiler version, compiler input and output. This file is generated similar to the files generated through Hardhat compilation. You can also try Hardhat compilation from Remix.

Please note that to generate these artifact files, the Generate contract metadata box in the General settings section of the Settings module needs to be checked. By default, it is checked.


Deploy to Hedera Testnet

Go to the Deploy & Run Transactions tab and select Injected Provider - MetaMask as the environment. A window will pop up if you're not signed into your MetaMask account. Sign in and make sure you're on Hedera Testnet and verify that the network is configured properly to Custom (296) network.

Once you click Deploy in the Deploy & Run Transactions tab, hit Confirm in the MetaMask notification window to approve and pay for the contract deployment transaction.


Interact with the Smart Contract on Hedera

Once the transaction is successful, you can interact with the smart contract through Remix. Select the dropdown on the newly deployed contract at the bottom of the left panel to view the contract's functions under Deployed Contracts. Write a new message to the updateString function using the input and confirm the write transaction in the MetaMask window to pay.


View Contract Details

Copy the contract address from the Deployed Contracts window.

Navigate to the HashScan network explorer and use the contract address to search for your contract to view the details.

Next Steps: Verify Your Smart Contract

If you're up for it, you can verify your deployed contract using the HashScan Smart Contract Verifier tool. Learn how:

{% content-ref url="how-to-verify-a-smart-contract-on-hashscan.md" %} how-to-verify-a-smart-contract-on-hashscan.md {% endcontent-ref %}

Congratulations! 🎉 You have successfully deployed a smart contract on the Hedera network using Remix IDE. Feel free to reach out in Discord if you have any questions!


Additional Resources

Remix IDE Documentation

HashScan Network Explorer

Deploy Leveraging EVM Dev Tools

Writer: Krystal, Technical Writer

GitHub | Hashnode

https://hashnode.com/@theekrystallee

Editor: Abi, DevRel Engineer

GitHub | LinkedIn

https://www.linkedin.com/in/a-ridley/

Editor: Logan, Software Engineering Intern

GitHub | LinkedIn

https://github.com/quiet-node