Common (Token)

This module provides extensions and utilities that are common to multiple token standards.

ERC2981

IERC2981

use openzeppelin::token::common::erc2981::IERC2981;

0x2d3414e45a8700c29f119a54b9f11dca0e29e06ddcb214018fc37340e165ed6

Interface of the ERC2981 standard as defined in EIP-2981.

Functions

royalty_info(token_id: u256, sale_price: u256) → (ContractAddress, u256) external

Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of exchange. The royalty amount is denominated and must be paid in that same unit of exchange.

ERC2981Component

use openzeppelin::token::common::erc2981::ERC2981Component;

ERC2981 component extending IERC2981.

Embeddable Implementations

Immutable Config constants

FEE_DENOMINATOR: u128 constant

The denominator with which to interpret the fee set in set_token_royalty and set_default_royalty as a fraction of the sale price.

validate() internal

Validates the given implementation of the contract’s configuration.

Requirements:

  • FEE_DENOMINATOR must be greater than 0.

This function is called by the contract’s initializer.

Embeddable functions

royalty_info(@self: ContractState, token_id: u256, sale_price: u256) → (ContractAddress, u256) external

Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of exchange. The royalty amount is denominated and should be paid in that same unit of exchange.

The returned tuple contains:

  • t.0: The receiver of the royalty payment.

  • t.1: The amount of royalty payment.

Internal functions

initializer(ref self: ContractState, default_receiver: ContractAddress, default_royalty_fraction: u128) internal

Initializes the contract by setting the default royalty and registering the supported interface.

Requirements:

  • default_receiver cannot be the zero address.

  • default_royalty_fraction cannot be greater than the fee denominator.

  • The fee denominator must be greater than 0.

The fee denominator is set by the contract using the Immutable Component Config.

default_royalty(self: @ContractState) → (ContractAddress, u128, u128) internal

Returns the royalty information that all ids in this contract will default to.

The returned tuple contains:

  • t.0: The receiver of the royalty payment.

  • t.1: The numerator of the royalty fraction.

  • t.2: The denominator of the royalty fraction.

set_default_royalty(ref self: ContractState, receiver: ContractAddress, fee_numerator: u128) internal

Sets the royalty information that all ids in this contract will default to.

Requirements:

  • receiver cannot be the zero address.

  • fee_numerator cannot be greater than the fee denominator.

delete_default_royalty(ref self: ContractState) internal

Removes default royalty information.

token_royalty(self: @ContractState, token_id: u256) → (ContractAddress, u256, u256) internal

Returns the royalty information that all ids in this contract will default to.

The returned tuple contains:

  • t.0: The receiver of the royalty payment.

  • t.1: The numerator of the royalty fraction.

  • t.2: The denominator of the royalty fraction.

set_token_royalty(ref self: ContractState, token_id: u256, receiver: ContractAddress, fee_numerator: u128) internal

Sets the royalty information for a specific token id, overriding the global default.

Requirements:

  • receiver cannot be the zero address.

  • fee_numerator cannot be greater than the fee denominator.

reset_token_royalty(ref self: ContractState, token_id: u256) internal

Resets royalty information for the token id back to unset.