Share your GetBlock experience with other devs and get 5M RPCs

banner image

Remix and OpenZeppelin for Web3 Developers

Deen Newman

Deen Newman

November 2, 2023

9 min read

article cover

Blockchain technology has opened up a world of possibilities, and some tools helping developers turn those possibilities into reality deserve special attention. OpenZeppelin and Remix have emerged as pivotal players, providing the essential building blocks for secure and reliable applications.

Join us on a journey to unpack the features and benefits of using OpenZeppelin together with
Remix.

Remix and OpenZeppelin: Highlights

In our tutorials, we frequently reference OpenZeppelin libraries and use Remix IDE to demonstrate the power of Web3 development. It’s time we dive deeper.

  • Remix IDE brings together all the tools and features needed to write, edit, test, and debug Solidity code in one place;
  • It is a versatile tool supporting various EVM-compatible protocols;
  • OpenZeppelin is renowned for its open-source library, a trusted resource for numerous leading crypto-related projects;
  • Web3 dApp developers commonly use OpenZeppelin's rigorously tested and audited open-source code to bolster security and streamline their development process;

The collaborative use of both tools benefits aspiring developers and provides an easily navigable environment for professionals.

What is Remix?

Remix is a free online workspace for programmers, offering tools like a code editor, compiler, debugger, and some additional features available as plugins to facilitate the development of Solidity-based projects.

Remix_IDE_hometab

Image from Remix

  • Local blockchain instance isolated from real network to experiment on features;
  • Abundance of useful plugins;
  • Gas estimation shown based on your code helps to write an optimal code;
  • Neat GUI;

Originally designed for Ethereum, the tool can be easily used for developing smart contracts across all EVM-compatible protocols like BNB Chain or Polygon.

In fact, the software was created by the Ethereum Foundation as a playground to learn Solidity, therefore it provides extremely well-laid documentation and detailed tutorials particularly useful when starting the Web3 development journey.

What is OpenZeppelin?

OpenZeppelin is a well-respected cyber security company focused on the blockchain space offering a whole stack of tools and services, from code auditing to open source smart contract library.

OpenZeppelin Contracts is arguably the most used tool aiding both experienced Web3 dApp developers and beginners in their journey.

OpenZeppelin_website

Image from OpenZeppelin

It is a free-to-use extensive repository consisting of different code templates that developers are free to reuse in their projects, namely:

  • Standardized token contracts, both fungible and non-fungible;
  • Ownable and role-based access control contracts;
  • On-chain governance contracts;
  • Upgradable proxies.

Rather than writing contracts from scratch, developers commonly opt to leverage OpenZeppelin tools to import battle-tested and thoroughly audited open-source codes.

As a security company, OpenZeppelin makes sure to keep the codes well-tested and audited. Additionally, their services have garnered a huge community that actively contributes to bug fixing and reporting rising issues

Remix and OpenZeppelin: The dynamic duo for Web3 development

Pairing the two tools creates a highly convenient and streamlined experience for developers, providing valuable support to both blockchain professionals and newcomers ready to launch their first Web3 dApp.

In the subsequent sections of this article, we'll lead you through the steps of managing OpenZeppelin libraries. We will also help you navigate Remix and deploy imported contracts.

Using OpenZeppelin in your project

Users have two main options for leveraging the libraries: either directly import them into projects or use ready-made solutions for contract generation. We will take a close look at both of these methods.

Installing OpenZeppelin

Access the terminal within your working directory and execute the provided command to install the package as a dependency for your project:

npm install @openzeppelin/contracts

That will install the latest available version. Please note that various contract library releases support different versions of Solidity. To download a desired version simply browse the version and add the corresponding tag, for example:

npm install @openzeppelin/contracts@2.5.2

At this point, you can start using the modules in your project by importing them.

Importing contracts

Here is a sample contract that utilizes OpenZeppelin’s instance of the ERC20 token. The complete list of templates is available on the official GitHub repository.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

Within the code, we need to specify that the contract will inherit fields and functions from the respective library as shown below:

contract ContractName is ERC20 {
    constructor () ERC20 (“TokenName”, “Symbol”) {}

Using OpenZeppelin with Remix

In Remix, you can follow the same format as in the previous step. However, if you're working on a standard token contract, there's a more streamlined tool to enhance your experience.

Contract_Wizard_by_OpenZeppelin

Image from OpenZeppelin

You can construct basic contracts with just a few clicks using Contract Wizard, which offers an easy-to-use UI that generates a code based on inputs and boxes you tick. You have the option to download, copy, or directly open the code in Remix by clicking the button on the header panel.

Getting started with Remix

In Remix, we can proceed with configuring our contract manually and eventually deploying it. Let’s quickly walk through the main capabilities of the online IDE.

N.B. For step-by-step guidance, check out our tutorial where we deployed an NFT smart contract using Remix and Contract Wizard.

Understanding the Remix Interface

Like standard code editors, Remix features a familiar layout with a left-hand menu, a code editor, and a bottom JavaScript terminal for instant feedback and script execution.

Remix_Interface

Image from Remix

The home page tab is an ideal starting point for navigating the platform. Here, you can access ‘LearnEth’ tutorials that guide you through Remix basics and Solidity programming.

Setting up a project

You have the option to add new files and workspaces, download some from your local storage, or explore the default workspace, which comes preloaded with a couple of smart contracts for you to experiment with.

Remix_File_Explorer

Image from Remix

Contract compiler

The third button on the left menu leads to a built-in compiler. Here, you can indicate the compiler that aligns with the Solidity version.

Enable the ‘Auto compile’ option so that whenever the change is made to the code it dynamically captures errors. The green check mark on the compiler icon indicates that the code is error-free and successfully assembled.

Remix_Compiler_&_Autocompiler

Image from Remix

Deploying the code

Users have several choices as where to run their contracts.

Configuring_Environments_in_Remix

Image from Remix

Local environment

The IDE provides a virtual environment isolated from a real blockchain that comes with a number of accounts populated with some Ether. This option serves well for debugging a smart contract locally without spending real tokens.

Connecting to a local node

By choosing the ‘Custom Http provider’, users that operate their own nodes can easily connect their machines to Remix and self-manage the deployment.

Testnet & Mainnet

Once you’re ready to immortalize your code on Ethereum or other chains, proceed with ‘Injected Provider - MetaMask’ and connect an account and connect an account associated with a chosen network. Confirm the action from a notification that appears.

Using a node provider

Routing your transactions through an infrastructure provider is as easy as connecting your MetaMask to Remix. In the example below, we set up a Holesky test network on MetaMask via an RCP link retrieved from a GetBlock account. By connecting the added network to Remix, free tariff users can launch contracts to the main and test networks of their choice at no cost.

Adding_networks_to_MetaMask

Image from MetaMask

Interacting with the contract

Upon a successful deployment of the contract, you can utilize a user interface to access all its methods. The interface features orange buttons for modifying the state's value and blue buttons for retrieving the value.

Interacting_with_deployed_contracts_in_Remix

Image from Remix

To bring it all together, with only Remix in our toolkit, we successfully navigated our smart contract through the entire production cycle with the valuable assistance of OpenZeppelin.

Remix Plugins for Web3 development

Remix hosts a number of helpful add-ons perfectly integrated with the workflow. Let's highlight a few examples.

DGIT turns Remix into an editor for your GitHub repository.

Remixd allows you to work on your local machine and proceed with Remix for testing and debugging, where edits will also be saved on your device.

The etherscan plugin makes it easy to verify contracts in Etherescan by simply passing the API key used to deploy the contract.

Flattener is especially useful when using libraries such as OpenZepellin as it extracts pieces of code hidden behind imports.

Remix_Plugin_Explorer

Image from Remix

Through the Plugin Manager, you can discover more tools that will significantly enrich your Remix experience.

Best practices for using Remix and OpenZeppelin together

To wrap up, it's worth noting some important factors to be aware of when using these two tools in tandem.

1. Version control

To avoid errors while finalizing your contract, pay attention to release notes for an instance of OpenZeppelin you’re planning to use since they are fine-tuned to support different Solidity versions.

2. Security considerations

Please note that unless you connect Remix to your local file system, it will utilize the browser storage which may eventually be cleared and lost. Timely backups will help save hours of hard work.

3. Testing your contracts

While OpenZepeplin is catering to Web3 dApp developers by providing industry-standard smart contract modules, integrating them within your project does not eliminate the need for proper security audits.

Although both frameworks are well-established and security-focused, it remains the developers' personal responsibility to embrace and implement optimal security measures.

Context Banner

Closing notes

OpenZeppelin and Remix together is a nice definition of convenient and efficient Solidity coding.

They simplify the development process, promote security best practices, and accommodate both experienced developers and newcomers. By leveraging these essential tools, you can embark on your blockchain development journey with confidence.

Elevate your Web3 dApp development even further with GetBlock's services. Simply sign up using MetaMask or your email to access over 50 supported blockchains from a top-tier RPC node provider.

Become a part of our affiliate program to reap the benefits of extra bonuses while you explore the exciting possibilities of blockchain development.

FAQ

  • What is Remix and why is it important in web development?

    plus
  • What Remix plugins are available to assist in Web3 development?

    plus
  • How to install OpenZeppelin and use its contracts in a project?

    plus
  • What are the best practices for using Remix and OpenZeppelin together in web development?

    plus
Deen Newman

Deen Newman

November 2, 2023

9 min read

twittertwittertelegramtelegramLinkedinLinkedin