XRC721
Introduction
XRC721 is an open standard that presents how to build unique non-fungible tokens on the XDC blockchain. Most tokens are fungible, whereas XRC721 tokens are, each of them, unique—they are best thought of as rare, inimitable, one-of-a-kind items.
The XRC721 standard is more complex than the XRC20 standard. It defines the minimum requirements a smart contract must meet for unique tokens to be owned, managed, and traded. The XRC721 standard has multiple optional extensions, split between several contracts. But it does not prevent the addition of supplemental functions or mandate a standard for token metadata.
Construct an XRC721 Token Contract
XRC721 tokens can be used to track various items with unique attributes in a hypothetical game. The tokens are minted and awarded to the players as required by the game rules, at which point players can keep or transfer their tokens. Note that any account can call awardItem
to mint tokens. Access control is added, however, to restrict accounts from minting tokens.
The contract for a tokenized item might look like this:
The XRC721 also includes IXRC721Metadata and IXRC721Enumerable standard extensions. Here, the _setTokenURI
method is used to store an item’s metadata.
Unlike XRC20, XRC721 does not have a decimal field because every token is unique, a whole, and thus cannot be partitioned.
Read methods
symbol() → string
Provides the symbol of the token, mostly just an abbreviation of the name.
name() → string
Provides the name of the token.
totalSupply() → uint256
Returns the total amount of tokens in the contract.
balanceOf(address account) → uint256
Provides the number of non-fungible tokens in the owner's account.
ownerOf(tokenId) → address
Returns the NFT owner specified by tokenId
.
tokenURI(uint256 tokenId) → string
Gives the URI for a tokenID
.
tokenOfOwnerByIndex(address owner, uint256 index) → uint256
Returns the token ID at a given index of the requested owner.
tokenByIndex(uint256 index) → uint256
Returns the token ID at a given index.
supportInterface(tokenId) → bool
Sets its value true if the contract implements the interface defined by interfaceId
.
getApproved(tokenId) → address
Returns the approved address for a token ID or sets it to zero if no address. If the token ID does not exist, it reverts.
isApprovedForAll (address owner, address operator) → bool
Tells whether a given owner approves an operator.
Write Methods
approve(address to, uint256 tokenId)
Approves the address that sends the given token ID. It ensures to approve only one address per token at a given time. Only the token owner or an approved operator can call the approve
method. The zero address means that no approved address exists.
transferFrom(address from, address to, uint256 tokenId)
Provides the ownership of a given token ID to another address.
safeTransferFrom(address from, address to, uint256 tokenId)
Safely provides the ownership of the requested token ID to another address.
setApprovalForAll(address operator, bool approved)
setApprovalForAll
method grants or revokes the approval of a given operator. An operator can send all tokens of the sender on their behalf.
Usage
When the user wants to use the SDKPHP library he/ she need to follow the below steps
Create a folder User convient (eg : sdk)
Inside the folder open the command prompt and type composer require xdc3/php
Create a file according to User convient (eg : index.php)
After creating user need to add the path , import the classes and create the object
(Optional) If user wants to change the URL Goto vendor -> XDC3 folder -> PHP folder -> .env file
Important
This library provides simple way to interact with XDC XRC20 & XRC721 tokens. Before Installing This Library
Install php version 7.4.25 on the system
Go to PHP Folder on the system, open php.ini file then enable gmp and curl extensions
Remove ";" from ";extension=gmp" to enable this Extension
Remove ";" from ";extension=curl" to enable this Extension
Enable ";curl.cainfo =" and add SSL Certificate path here
To download the SSL Certificate go to https://curl.se/docs/caextract.html then click on cacert.pem on the top.
Copy the path of the certificate and paste in the php.ini file
curl.cainfo = "C:\Users\HP\Downloads\cacert.pem"
Install openssl in the system using chocolately
Run the following command in admin powershell to install openssl
choco install openssl
Folder Info
In XDC library inside the vendor folder -> xdc3base -> php we can find the all called functions of the XRC20 methods . (including contract file , address calling from apothem file etc)
In PHPS library inside the vendor folder -> xdc3 -> php we can find the all calling functions from the XDC library. (ex : in modules xrc20 folder contains every calling methods)
Example
Last updated