ERC-721 Interface Reference — NFT Functions & Events

ERC-721 is the non-fungible token standard on EVM chains, where each token has a unique ID and owner. This reference lists the standard functions, events, and the metadata extension.

Ownership functions

balanceOf(owner) — the number of NFTs held by an address. ownerOf(tokenId) — the address that owns a specific token. Unlike ERC-20, each token is identified by a unique tokenId rather than a divisible amount.

Transfer functions

safeTransferFrom(from, to, tokenId) — transfers a token and checks that a contract recipient can handle ERC-721 tokens, preventing tokens from being stranded. An overload accepts extra data. transferFrom also exists but performs no recipient safety check.

Approval functions

approve(to, tokenId) — grants one address permission to transfer a single token. setApprovalForAll(operator, approved) — grants or revokes an operator permission over all of the caller's tokens. getApproved(tokenId) — the approved address for one token. isApprovedForAll(owner, operator) — whether an operator is approved for all of an owner's tokens.

Events and metadata

Transfer(from, to, tokenId), Approval(owner, approved, tokenId) and ApprovalForAll(owner, operator, approved) mirror the functions and are emitted on the corresponding actions. The optional metadata extension adds tokenURI(tokenId), which returns a URI pointing to a JSON document describing the token (name, image, attributes).

常见问题

What is the difference between approve and setApprovalForAll?

approve grants permission to move one specific tokenId. setApprovalForAll grants an operator permission over every token the owner holds in that contract, which is how marketplaces list an entire collection with a single transaction.

Where does the NFT image come from?

The contract's tokenURI(tokenId) returns a URI to a JSON metadata document. That document contains fields such as name, description, and an image URL. The image itself is off-chain content referenced by the metadata.

相关工具

充值、拿密钥、上线。

自助开通。支持加密货币或银行卡。按额度计费——重型原语更贵,简单调用很便宜。

获取 API 密钥