Introduction to ZRC-2
ZRC-2 is the formal standard for Fungible Token in Zilliqa. It is an open standard for creating currencies on the Zilliqa blockchain.
The ZRC-2 standard allows for functionalities like
- Minting/burning tokens
- Transferring tokens from one account to another
- Querying account token balance
- Querying total token balances
- Approving third party to spend a certain amount of tokens
Examples of ZRC-2
- XSGD - the first Singapore dollar-pegged stablecoin built by Xfers
- gZIL - Governance ZIL token earned through Zilliqa Seed Node Staking Program
Checking Whether a Contract is ZRC-2 Compliant
Before you start any integration with ZRC-2, it is important to check the smart contract to ensure it conforms to the ZRC-2 standard. Non-conformance to the standard may lead to composability issues with other contracts or dApp/exchange integration.
Please check the ZRC-2 specification subsection in the Developers section of this developer portal.
Please check the Integrating with ZRC-2 Fungible Tokens Contract subsection on how to get token balance and transfer tokens.
Tracking Incoming ZRC-2 Deposit
To track any new incoming deposit of a specific ZRC-2 token:
- Poll the blockchain block by block using API
GetTxnBodiesForTxBlockAPI and process each transactions
- For each transaction in the TxBlock, perform the following:
- Check whether
toAddrmatches the corresponding ZRC-2 token contract address. For example, contract address a845c1034cd077bd8d32be0447239c7e4be6cb21 for gZIL ZRC-2 token.
- Check that the success field is set to
true. If it is
false, it means that this transaction was not accepted by the network.
data, look for
TransferFromtag. Check the
valueto see whether it matches the base16 address format of your deposit address.
- If it matches,
valuerepresents the amount of tokens that are being transferred from the sender to your deposit address.
- Check whether
value, please note the number of decimal places used by the smart contract.
- [Optional checks] You can also check
event_logsand ensure the following:
addressmatches your deposit address
senderrefers to the sender of the transactions
recipientrefers your deposit address
amountis the amount of token transferred
Sample transaction receipt of a ZRC-2 token