npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unique-nft/contracts

v0.0.2

Published

Smart Contract library for Unique Network

Downloads

101

Readme

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.

| Parameter | Type | Description | | ---------- | -------- | ----------------------- | | trait_type | string | Type of the attribute. | | value | string | Value 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.

| Parameter | Type | Description | | --------- | --------- | ------------------------------------------------------------------- | | eth | address | Ethereum address or address(0) if the origin is substrate account | | sub | uin256 | Substrate 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