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

@unique-nft/contracts

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unique-nft/contracts

Smart Contract library for Unique Network

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

Unique Network | Contracts

npm version

This repository contains smart contracts for minting collections and tokens using Solidity in the Unique Schema V2.

Installation

npm install @unique-nft/contracts

API

Structs

Attribute

Represents an attribute of a token.

ParameterTypeDescription
trait_typestringType of the attribute.
valuestringValue of the attribute.
CrossAddress

Represents ethereum or substrate account. Only one property can be filled out to consider the structure valid. Learn more about EVM in Unique Network and compatibility with substrate accounts in the official documentation.

The AddressUtils library provides helper methods to work with the CrossAddress struct.

ParameterTypeDescription
ethaddressEthereum address or address(0) if the origin is substrate account
subuin256Substrate public key or 0 if the caller is ethereum account

Contracts

CollectionMinter.sol

import "@unique-nft/contracts/CollectionMinter";

Provides functions to create collections in the Unique Schema V2.

constructor(bool _mutable, bool _admin, bool _tokenOwner)
Initializes the contract and sets the default permissions for token properties mutation

_createCollection(string _name, string _description, string _symbol, string _collectionCover)
Creates a collection with specified name, description, symbol, collection cover, and allowed nesting permissions.
TokenMinter.sol

import "@unique-nft/contracts/TokenMinter";

Provides functions to create tokens in the Unique Schema V2.

_createToken(address _collectionAddress, string _image, Attribute[] _attributes, CrossAddress _to) internal returns (uint256)
Internal function to create a new token with specified image and attributes in a given collection.
TokenManager.sol

import "@unique-nft/contracts/TokenManager.sol";

Provides utility functions for managing token data, such as setting and retrieving images and traits for tokens within a collection.

_setImage(address _collection, uint256 _tokenId, bytes memory _newImage) internal
Sets a new image for a specific token in a collection.

_setTrait(address _collection, uint256 _tokenId, bytes memory _traitType, bytes memory _traitValue) internal
Sets a new trait (attribute) for a specific token in a collection.

_getImage(address _collection, uint256 _tokenId) internal view returns (bytes memory)
Retrieves the image data of a specific token in a collection.

_getTraitValue(address _collection, uint256 _tokenId, bytes memory _traitType) internal view returns (bytes memory)
Retrieves the value of a specific trait for a token in a collection.
AddressValidator.sol

import "@unique-nft/contracts/AddressValidator";

Provides modifiers for validating addresses in token-related operations, ensuring that the caller is authorized.

onlyTokenOwner(uint256 _tokenId, address collectionAddress)
Restricts access to the owner of the token with ID _tokenId in the collection at collectionAddress. Reverts if msg.sender is not the token owner.

onlyMessageSender(CrossAddress memory _crossAddress)
Restricts access to the address represented by _crossAddress. Reverts if _crossAddress does not match msg.sender.

Example Usage

  • Minter.sol: Demonstrates how to create a gasless experience for minting collections and NFTs.
  • POAP.sol: Demonstrates how to create a POAP contract. Tokens minting sponsored by the POAP contract itself. Every account can mint only one NFT that cannot be transferred.
  • BreedingGame.sol: Demonstrates how contracts can mutate token's attributes and image.

Run tests

  1. Install packages and compile contracts
yarn
yarn compile
  1. Create .env file from .env.example

  2. Set at least two private keys with OPL balance to TEST_ACCOUNTS_ETH env. You can get OPL tokens for free at https://t.me/unique2faucet_opal_bot

  3. Run tests

yarn test

Keywords

FAQs

Package last updated on 08 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