Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Last active August 6, 2021 15:19
Show Gist options
  • Save cgcardona/2c1a427ed6c695767699ce566a812b4f to your computer and use it in GitHub Desktop.
Save cgcardona/2c1a427ed6c695767699ce566a812b4f to your computer and use it in GitHub Desktop.

Open Zeppelin and Remix Integration

Open Zeppelin provides security products to build, automate, and operate decentralized applications and has a full suite of battle-tested and audited smart-contracts for the EVM including:

You can deploy Open Zeppelin smart contracts on the Avalanche C-Chain via Remix.

Installation

When developing locally you install Open Zeppeling via npm:

npm install @openzeppelin/contracts

Then within the Solidity smart-contract you import the contract you wish from the node_modules/ directory which was created by the previous npm install command:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

However when using Remix we're unable to import from a local node_modules/ directory because it doesn't exist. Fortunately Remix supports importing from Github.

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC20/ERC20.sol";

Note: Only use tags which are published in an official release of OpenZeppelin Contracts. On Remix specify the release tag when importing from GitHub or you'll get the latest code in the master branch. The example below imports v3.3.0.

Works

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC20/ERC20.sol";

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) public ERC20("Gold", "GLD") {
        _mint(msg.sender, initialSupply);
    }
}

Doesn't work

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) public ERC20("Gold", "GLD") {
        _mint(msg.sender, initialSupply);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment