SettlementNft

Git Source

Inherits: ERC721

Author: EridianAlpha

An ERC721 NFT token called Ethereum Settlement (SETTLEMENT).

State Variables

BASE_IMAGE_URI

string public BASE_IMAGE_URI;

SETTLER_TOKEN

SettlerToken public immutable SETTLER_TOKEN;

nextTokenId

uint256 public nextTokenId = 1;

s_mintTimestamp

mapping(uint256 => uint256) internal s_mintTimestamp;

s_ownerToId

mapping(address => uint256) internal s_ownerToId;

Functions

constructor

Constructor to initialize the contract with a base image URI and deploy the SettlerToken contract.

constructor(string memory _baseImageUri) ERC721("Ethereum Settlement", "SETTLEMENT");

Parameters

NameTypeDescription
_baseImageUristringThe base URI for the NFT image.

_update

Override standard ERC721 _update function.

Mints outstanding SETTLER tokens. Checks only 1 NFT per address.

function _update(address to, uint256 tokenId, address auth) internal override returns (address previousOwner);

Parameters

NameTypeDescription
toaddressThe address to transfer the NFT to.
tokenIduint256The ID of the NFT.
authaddressThe address that is authorized to transfer the NFT.

Returns

NameTypeDescription
previousOwneraddressThe previous owner of the NFT.

mint

Override standard ERC721 mint function.

Mints a new NFT and sets the mint timestamp. Adds the msg.sender to the s_ownerToId mapping.

function mint() external;

tokenURI

Override standard ERC721 tokenURI function.

Generates the JSON metadata for the NFT.

function tokenURI(uint256 tokenId) public view override returns (string memory uri);

Parameters

NameTypeDescription
tokenIduint256The ID of the NFT.

Returns

NameTypeDescription
uristringThe JSON metadata for the NFT.

_generateAttributes

Generates the attributes for the NFT used in the tokenURI.

function _generateAttributes(uint256 tokenId) internal view returns (string memory attributes);

Parameters

NameTypeDescription
tokenIduint256The ID of the NFT.

Returns

NameTypeDescription
attributesstringThe attributes for the NFT.

_generateSvg

Generates the SVG for the NFT.

function _generateSvg(uint256 tokenId) internal view returns (string memory svg);

Parameters

NameTypeDescription
tokenIduint256The ID of the NFT.

Returns

NameTypeDescription
svgstringThe SVG for the NFT.

_generateSettlementRectangle

Generates the SVG rectangle for the settlement ID.

function _generateSettlementRectangle(string memory tokenIdString) internal pure returns (string memory rectangleSvg);

Parameters

NameTypeDescription
tokenIdStringstringThe ID of the NFT as a string.

Returns

NameTypeDescription
rectangleSvgstringThe SVG rectangle for the settlement ID.

_generateDaysSinceMintRectangle

Generates the SVG rectangle for the days since mint.

function _generateDaysSinceMintRectangle(uint256 tokenId) internal view returns (string memory rectangleSvg);

Parameters

NameTypeDescription
tokenIduint256The ID of the NFT.

Returns

NameTypeDescription
rectangleSvgstringThe SVG rectangle for the days since mint.

_daysSinceMint

Calculates the days since mint for an NFT.

function _daysSinceMint(uint256 _mintTimestamp) internal view returns (uint256 daysSinceMint);

Parameters

NameTypeDescription
_mintTimestampuint256The timestamp when the NFT was minted.

Returns

NameTypeDescription
daysSinceMintuint256The days since the NFT was minted.

getOwnerToId

Getter function to get the NFT ID from an owner address.

function getOwnerToId(address owner) external view returns (uint256 tokenId);

Parameters

NameTypeDescription
owneraddressThe address of the NFT owner.

Returns

NameTypeDescription
tokenIduint256The ID of the NFT.

getMintTimestamp

Getter function to get the mint timestamp of an NFT from a token ID.

function getMintTimestamp(uint256 tokenId) external view returns (uint256 mintTimestamp);

Parameters

NameTypeDescription
tokenIduint256The ID of the NFT.

Returns

NameTypeDescription
mintTimestampuint256The timestamp when the NFT was minted.

Errors

SettlementNft_SingleActivePerAddress

error SettlementNft_SingleActivePerAddress();