Skip to content

Commit

Permalink
docs: include ERC721 supported methods in README (#190)
Browse files Browse the repository at this point in the history
Signed-off-by: Luis Mastrangelo <[email protected]>
  • Loading branch information
acuarica authored Jan 14, 2025
1 parent 7f9991e commit 5dbfa91
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,50 @@ The following methods and events are applicable to Fungible Tokens.

<!-- !./scripts/abi-table.js out/IHRC719.sol/IHRC719.json -->

| Function | Comment |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `associate()` | Associates the calling account with the token This function allows an account to opt-in to receive the token |
| `dissociate()` | Dissociates the calling account from the token This function allows an account to opt-out from receiving the token |
| `isAssociated() view` | Checks if the calling account is associated with the token This function returns the association status of the calling account |
| Function | Comment |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `associate()` | Associates the calling account with the token. This function allows an account to opt-in to receive the token |
| `dissociate()` | Dissociates the calling account from the token. This function allows an account to opt-out from receiving the token |
| `isAssociated() view` | Checks if the calling account is associated with the token. This function returns the association status of the calling account |

<!-- -->

### Non-Fungible Tokens

The following methods and events are applicable to Non-Fungible Tokens.

> [!NOTE]
> ERC721 support coming soon!
<!-- !./scripts/abi-table.js out/IERC721.sol/IERC721.json -->

| Function | Comment |
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `approve(address _approved, uint256 _tokenId) payable` | Change or reaffirm the approved address for an NFT. The zero address indicates there is no approved address. Throws unless `msg.sender` is the current NFT owner, or an authorized operator of the current owner. |
| `balanceOf(address _owner) view` | Count all NFTs assigned to an owner. NFTs assigned to the zero address are considered invalid, and this function throws for queries about the zero address. |
| `getApproved(uint256 _tokenId) view` | Get the approved address for a single NFT. Throws if `_tokenId` is not a valid NFT. |
| `isApprovedForAll(address _owner, address _operator) view` | Query if an address is an authorized operator for another address |
| `ownerOf(uint256 _tokenId) view` | Find the owner of an NFT. NFTs assigned to zero address are considered invalid, and queries about them do throw. |
| `safeTransferFrom(address _from, address _to, uint256 _tokenId) payable` | Transfers the ownership of an NFT from one address to another address. This works identically to the other function with an extra data parameter, except this function just sets data to "". |
| `safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) payable` | Transfers the ownership of an NFT from one address to another address. Throws unless `msg.sender` is the current owner, an authorized operator, or the approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this function checks if `_to` is a smart contract (code size > 0). If so, it calls `onERC721Received` on `_to` and throws if the return value is not `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`. |
| `setApprovalForAll(address _operator, bool _approved)` | Enable or disable approval for a third party ("operator") to manage all of `msg.sender`'s assets. Emits the ApprovalForAll event. The contract MUST allow multiple operators per owner. |
| `supportsInterface(bytes4 interfaceID) view` | Query if a contract implements an interface. Interface identification is specified in ERC-165. This function uses less than 30,000 gas. |
| `transferFrom(address _from, address _to, uint256 _tokenId) payable` | Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE THEY MAY BE PERMANENTLY LOST. Throws unless `msg.sender` is the current owner, an authorized operator, or the approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero address. Throws if `_tokenId` is not a valid NFT. |

| Event | Comment |
| --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)` | This emits when the approved address for an NFT is changed or reaffirmed. The zero address indicates there is no approved address. When a Transfer event emits, this also indicates that the approved address for that NFT (if any) is reset to none. |
| `ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)` | This emits when an operator is enabled or disabled for an owner. The operator can manage all NFTs of the owner. |
| `Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)` | This emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any number of NFTs may be created and assigned without emitting Transfer. At the time of any transfer, the approved address for that NFT (if any) is reset to none. |

<!-- -->

#### Association Methods Interface

<!-- !./scripts/abi-table.js out/IHRC719.sol/IHRC719.json -->

| Function | Comment |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `associate()` | Associates the calling account with the token This function allows an account to opt-in to receive the token |
| `dissociate()` | Dissociates the calling account from the token This function allows an account to opt-out from receiving the token |
| `isAssociated() view` | Checks if the calling account is associated with the token This function returns the association status of the calling account |
| Function | Comment |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `associate()` | Associates the calling account with the token. This function allows an account to opt-in to receive the token |
| `dissociate()` | Dissociates the calling account from the token. This function allows an account to opt-out from receiving the token |
| `isAssociated() view` | Checks if the calling account is associated with the token. This function returns the association status of the calling account |

<!-- -->

Expand Down
7 changes: 4 additions & 3 deletions scripts/abi-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function* data(kind, abi, userdoc, devdoc) {
if (frag.type === kind) {
const sighash = frag.format('sighash');
const [member] = frag.format('full').replace(`${kind} `, '').split(' returns ');
const notice = userdoc[sighash]?.notice;
const dev = devdoc[sighash]?.details;
const notice = (userdoc[sighash]?.notice ?? '').trim();
const dev = (devdoc[sighash]?.details ?? '').trim();

yield { member, notice, dev };
}
Expand Down Expand Up @@ -67,7 +67,8 @@ function main() {
write(`| ${kind} | Comment |`);
write('|----------|---------|');
for (const { member, notice, dev } of members) {
write(`| \`${member}\` | ${notice ?? ''} ${dev ?? ''} |`);
const sep = notice !== '' && dev !== '' && !notice.endsWith('.') ? '.' : '';
write(`| \`${member}\` | ${notice}${sep} ${dev} |`);
}
}
});
Expand Down

0 comments on commit 5dbfa91

Please sign in to comment.