AgentNFT

AgentNFT is an extension of the Agency main contract and is fully ERC721 compatible. Users may only hold 1 NFT at a time. The NFT contract handles most of the business logic, with transfers directed back to the main contract's transfer function. Transferring agents can only be done via the AgentNFT contract.

supportsInterface

Checks if the contract supports a given interface. Interface identification is specified in ERC-165.

function supportsInterface(
    bytes4 interfaceID) external pure returns (bool)

Parameters:

NameTypeDescription

interfaceID

bytes4

Interface ID to check.

Return Values:

NameTypeDescription

None

bool

True if the contract supports the interface.

tokenURI

Retrieves metadata for a specified token ID, including owner, tier, birth, and parent details from the Agency contract, and calls_tokenURI .

function tokenURI(
    uint tokenId) external view returns (string memory)

Parameters:

NameTypeDescription

tokenId

uint

ID of the token.

Return Values:

NameTypeDescription

None

string

Token URI.

_tokenURI

Internal function to construct the token URI. It constructs an SVG image with this information and encodes it into Base64. The resulting Base64 string is embedded in a JSON format, forming the final URI. This URI provides detailed information for displaying the NFT, such as name, description, and image, serving external applications or services.

function _tokenURI(
    uint tokenId, 
    uint parent, 
    uint tier, 
    uint birth) internal pure returns (string memory output)

Parameters:

NameTypeDescription

tokenId

uint

ID of the token.

parent

uint

ID of the parent.

tier

uint

Tier of the agent.

birth

uint

Timestamp of the agent's creation.

Return Values:

NameTypeDescription

output

string

Token URI.

totalSupply

Returns the total number of tokens.

function totalSupply() external view returns (uint)

Return Values:

NameTypeDescription

None

uint

Total supply of tokens.

balanceOf

Returns the balance of tokens for a given owner.

function balanceOf(
    address owner) external view returns (uint balance)

Parameters:

NameTypeDescription

owner

address

Address of the token owner.

Return Values:

NameTypeDescription

balance

uint

Token balance of the owner.

ownerOf

Returns the owner of a given token.

function ownerOf(
    uint tokenId) public view returns (address owner)

Parameters:

NameTypeDescription

tokenId

uint

ID of the token.

Return Values:

NameTypeDescription

owner

address

Owner address of the token.

onMint

Invoked by the Agency contract during the minting of a new token, its sole purpose is to emit the Transfer event.

function onMint(
    address user, 
    uint tokenId) external

Parameters:

NameTypeDescription

user

address

Address of the user receiving the token.

tokenId

uint

ID of the minted token.

safeTransferFrom

Safely transfers a token from one address to another. This function simply calls the other safeTransferFrom with the bytes data ''.

function safeTransferFrom(
    address from,
    address to,
    uint tokenId) external

Parameters:

NameTypeDescription

from

address

Address of the sender.

to

address

Address of the receiver.

tokenId

uint

ID of the token.

approve

Approves an address to manage the specified token.

function approve(
    address to, 
    uint tokenId) external

Parameters:

NameTypeDescription

to

address

Address to be approved.

tokenId

uint

ID of the token.

setApprovalForAll

Sets or revokes approval for an operator to manage all tokens of the sender.

function setApprovalForAll(
    address operator, 
    bool approved) external

Parameters:

NameTypeDescription

operator

address

Address of the operator.

approved

bool

Approval status.

transferFrom

Transfers a token from one address to another.

function transferFrom(
    address from,
    address to,
    uint tokenId) external

Parameters:

NameTypeDescription

from

address

Address of the sender.

to

address

Address of the receiver.

tokenId

uint

ID of the token.

_isContract

Internal function to check if an address is a contract. It checks if the provided address corresponds to a smart contract by examining its bytecode size. It returns true if the size is greater than zero; otherwise, it returns false.

function _isContract(
    address account) internal view returns (bool)

Parameters:

NameTypeDescription

account

address

Address to check.

Return Values:

NameTypeDescription

None

bool

True if the address is a contract.

safeTransferFrom

Facilitates the secure transfer of an ERC721 token from one address (from) to another (to). It invokes the internal _transferFrom function, updating token ownership. If the recipient (to) is a smart contract, it checks whether it implements the IERC721Receiver interface. If implemented, it calls the onERC721Received function, ensuring the expected selector is returned. Any deviation or failure is appropriately handled, providing robust and safe token transfers in ERC721-compliant contracts.

function safeTransferFrom(
    address from,
    address to,
    uint tokenId,
    bytes memory data) public 

Parameters:

NameTypeDescription

from

address

Address of the sender.

to

address

Address of the receiver.

tokenId

uint

ID of the token.

data

bytes

Additional data.

Last updated