Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HenriableVehicleNFT

Git Source

Inherits: ERC721, Ownable

Title: Henriable vehicle-title NFT.

Author: Obiaraije Henry

An ERC721 that represents the title deed of one physical asset. The platform mints it to itself once an investment is fully funded and transfers it to the rider when the hire purchase is paid in full. The token is a standard, transferable ERC721 after the rider receives it.

Kept as its own contract (not inherited by {Henriable}) so the platform’s business logic stays under the EIP-170 code-size limit. Minting is gated by a single {minter} address, which the owning deployer sets to the {Henriable} address during deployment; the deployer keeps admin control of the collection.

State Variables

minter

The only address allowed to mint titles (the {Henriable} platform).

address(0) means no address can mint until the owner sets it.

address internal minter

nextTokenId

Id that will be assigned to the next minted title.

Ids start at 1 so 0 keeps meaning “no title”, matching the platform.

uint256 internal nextTokenId

Functions

constructor

Deploys the collection with its name and symbol.

constructor(address initialOwner) ERC721("Henriable Vehicle Title", "HVT") Ownable(initialOwner);

Parameters

NameTypeDescription
initialOwneraddressThe address that owns the collection and may set the minter.

onlyMinter

Restricts a function to the configured {minter}.

Reverts with {HVehicleNftUnauthorizedMinter} when the caller is not the minter.

modifier onlyMinter() ;

setMinter

Sets the address allowed to mint titles, typically the platform.

Only the collection owner may call this. Pass address(0) to disable minting. States updated: {minter}.

function setMinter(address newMinter) external onlyOwner;

Parameters

NameTypeDescription
newMinteraddressThe address allowed to mint, or address(0) to disable minting.

mint

Mints the next title to an address.

Only the {minter} may call this. Ids are assigned sequentially from 1. States updated: {nextTokenId}.

function mint(address to) external onlyMinter returns (uint256 tokenId);

Parameters

NameTypeDescription
toaddressThe address that will own the newly minted title.

Returns

NameTypeDescription
tokenIduint256The id of the newly minted title.

tokenURI

Returns the token’s metadata as an on-chain base64 data URI.

ERC721 metadata JSON with an inline base64 SVG image, so titles render in Etherscan, wallets and marketplaces with no off-chain hosting. The owner on the card is read live, so it updates when the platform transfers the deed. Reverts for a non-existent token (via {_requireOwned}).

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

Parameters

NameTypeDescription
tokenIduint256The title’s token id.

Returns

NameTypeDescription
<none>stringA data:application/json;base64,... URI.

_renderSvg

Renders the title card as an SVG.

function _renderSvg(uint256 tokenId, address owner, string memory asset, address rider)
    internal
    pure
    returns (string memory);

Parameters

NameTypeDescription
tokenIduint256The title’s token id.
owneraddressThe current owner, shown on the card.
assetstringThe asset name (empty when unknown).
rideraddressThe hired rider (address(0) when unknown), shown on the card.

Returns

NameTypeDescription
<none>stringThe SVG markup.

_titleInfo

Reads the asset name and rider from the platform (the minter).

Returns zero values when the minter is unset or is not a contract that answers, so metadata degrades gracefully instead of reverting.

function _titleInfo(uint256 tokenId) internal view returns (bytes32 assetName, address rider);

Parameters

NameTypeDescription
tokenIduint256The title’s token id.

Returns

NameTypeDescription
assetNamebytes32The bytes32 asset name, or bytes32(0).
rideraddressThe rider, or address(0).

_bytes32ToString

Decodes a bytes32 asset name into a trimmed ASCII string.

function _bytes32ToString(bytes32 value) internal pure returns (string memory);

Parameters

NameTypeDescription
valuebytes32The bytes32 to decode.

Returns

NameTypeDescription
<none>stringThe decoded string (up to the first zero byte).

getMinter

Returns the address allowed to mint titles.

function getMinter() external view returns (address);

Returns

NameTypeDescription
<none>addressThe configured minter, or address(0) when unset.

getNextTokenId

Returns the id that will be assigned to the next minted title.

function getNextTokenId() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The next token id.