Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openzeppelin/contracts

Package Overview
Dependencies
Maintainers
4
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openzeppelin/contracts

Secure Smart Contract library for Solidity

  • 5.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
361K
decreased by-21.87%
Maintainers
4
Weekly downloads
 
Created

What is @openzeppelin/contracts?

@openzeppelin/contracts is a library for secure smart contract development. It provides implementations of standards like ERC20 and ERC721, as well as utilities for common tasks such as access control and upgradeability.

What are @openzeppelin/contracts's main functionalities?

ERC20 Token

This code demonstrates how to create an ERC20 token using the @openzeppelin/contracts library. The ERC20 contract is imported and extended to create a new token with an initial supply.

const { ERC20 } = require('@openzeppelin/contracts/token/ERC20/ERC20.sol');

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
        _mint(msg.sender, initialSupply);
    }
}

ERC721 Token

This code demonstrates how to create an ERC721 non-fungible token (NFT) using the @openzeppelin/contracts library. The ERC721 contract is imported and extended to create a new NFT with a minting function.

const { ERC721 } = require('@openzeppelin/contracts/token/ERC721/ERC721.sol');

contract MyNFT is ERC721 {
    constructor() ERC721("MyNFT", "MNFT") {
    }

    function mint(address to, uint256 tokenId) public {
        _mint(to, tokenId);
    }
}

Access Control

This code demonstrates how to use the Ownable contract from the @openzeppelin/contracts library to restrict access to certain functions. The onlyOwner modifier ensures that only the contract owner can call the restrictedFunction.

const { Ownable } = require('@openzeppelin/contracts/access/Ownable.sol');

contract MyContract is Ownable {
    function restrictedFunction() public onlyOwner {
        // restricted logic
    }
}

Upgradeability

This code demonstrates how to use the TransparentUpgradeableProxy contract from the @openzeppelin/contracts library to create upgradeable smart contracts. The proxy pattern allows for the logic of the contract to be upgraded while preserving the contract's state.

const { TransparentUpgradeableProxy } = require('@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol');

contract MyContractV1 {
    uint256 public value;

    function setValue(uint256 _value) public {
        value = _value;
    }
}

contract MyContractV2 {
    uint256 public value;

    function setValue(uint256 _value) public {
        value = _value * 2;
    }
}

Other packages similar to @openzeppelin/contracts

Keywords

FAQs

Package last updated on 17 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc