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.
Parameters:
Name | Type | Description |
---|---|---|
interfaceID | bytes4 | Interface ID to check. |
Return Values:
Name | Type | Description |
---|---|---|
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
.
Parameters:
Name | Type | Description |
---|---|---|
tokenId | uint | ID of the token. |
Return Values:
Name | Type | Description |
---|---|---|
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.
Parameters:
Name | Type | Description |
---|---|---|
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:
Name | Type | Description |
---|---|---|
output | string | Token URI. |
totalSupply
Returns the total number of tokens.
Return Values:
Name | Type | Description |
---|---|---|
None | uint | Total supply of tokens. |
balanceOf
Returns the balance of tokens for a given owner.
Parameters:
Name | Type | Description |
---|---|---|
owner | address | Address of the token owner. |
Return Values:
Name | Type | Description |
---|---|---|
balance | uint | Token balance of the owner. |
ownerOf
Returns the owner of a given token.
Parameters:
Name | Type | Description |
---|---|---|
tokenId | uint | ID of the token. |
Return Values:
Name | Type | Description |
---|---|---|
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.
Parameters:
Name | Type | Description |
---|---|---|
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 ''
.
Parameters:
Name | Type | Description |
---|---|---|
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.
Parameters:
Name | Type | Description |
---|---|---|
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.
Parameters:
Name | Type | Description |
---|---|---|
operator | address | Address of the operator. |
approved | bool | Approval status. |
transferFrom
Transfers a token from one address to another.
Parameters:
Name | Type | Description |
---|---|---|
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
.
Parameters:
Name | Type | Description |
---|---|---|
account | address | Address to check. |
Return Values:
Name | Type | Description |
---|---|---|
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.
Parameters:
Name | Type | Description |
---|---|---|
from | address | Address of the sender. |
to | address | Address of the receiver. |
tokenId | uint | ID of the token. |
data | bytes | Additional data. |
Last updated