Introduction
Qtum, a hybrid blockchain combining Bitcoin's UTXO model and Ethereum's EVM, has developed its own token standards to facilitate seamless token creation and management. This article explores Qtum's QRC20 (fungible) and QRC721 (non-fungible) token standards, their Ethereum counterparts (ERC20 and ERC721), and their practical applications.
Why Token Standards Matter
Imagine a street with five stores, each accepting a different currency. Chaos would ensue without a unified monetary system. Similarly, blockchain ecosystems require standardized token protocols to ensure interoperability and usability. Ethereum pioneered this with ERC20, ERC721, and ERC1155. Qtum follows suit with QRC20, QRC721, and QRC1155.
ERC20: The Fungible Token Standard
ERC20 is Ethereum's foundational standard for fungible tokens, essential for currencies and utility tokens. Its simplicity fueled the 2017 ICO boom. Key components include:
Mandatory Functions:
totalSupply: Returns total token supply.balanceOf: Checks an address's token balance.transfer: Moves tokens between addresses.approve/transferFrom: Enables delegated transfers.
Optional Metadata:
- Token name, symbol, and decimals (up to 18).
QRC20: Qtum’s Fungible Token Standard
QRC20 mirrors ERC20’s functionality. Below is a step-by-step guide to interacting with QRC20 contracts:
1. Checking Token Balance
qtum-cli callcontract {TOKEN_CONTRACT_ADDRESS} 70a08231{to32bytesArg(addressToHash160($userAddress))}- Output: Look for
executionResult.outputin the JSON response.
2. Withdrawing Tokens
qtum-cli sendtocontract {TOKEN_CONTRACT_ADDRESS} a9059cbb{to32bytesArg(addressToHash160($userAddress))}{to32bytesArg(addDecimals($amount))} 0 {DEFAULT_GAS_LIMIT} {DEFAULT_GAS_PRICE} {MAIN_QRC_ADDRESS}- Returns: Transaction ID (txid) for tracking.
3. Generating Deposit Addresses
qtum-cli getnewaddress- Use the same address for Qtum and QRC20 tokens.
4. Monitoring Transactions
qtum-cli searchlogs STARTING_BLOCK 999999999 '{ "addresses": ["TOKEN_CONTRACT_ADDRESS"]}' '{"topics": ["ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}'- Filters transfer events by
to/fromaddresses.
👉 Learn more about QRC20 token development
ERC721: The Non-Fungible Token Standard
ERC721 defines NFTs, where each token is unique. Core functions include:
1. ownerOf()
function ownerOf(uint256 _tokenId) returns (address) {
require(tokenExists[_tokenId]);
return tokenOwners[_tokenId];
}2. approve()
function approve(address _to, uint256 _tokenId) {
require(msg.sender == ownerOf(_tokenId));
allowed[msg.sender][_to] = _tokenId;
}3. takeOwnership()
function takeOwnership(uint256 _tokenId) {
address oldOwner = ownerOf(_tokenId);
require(allowed[oldOwner][msg.sender] == _tokenId);
tokenOwners[_tokenId] = msg.sender;
}4. transfer()
function transfer(address _to, uint256 _tokenId) {
address owner = ownerOf(_tokenId);
removeFromTokenList(owner, _tokenId);
tokenOwners[_tokenId] = _to;
}5. tokenOfOwnerByIndex() (Optional)
function tokenOfOwnerByIndex(address _owner, uint256 _index) returns (uint256) {
return ownerTokens[_owner][_index];
}QRC721: Qtum’s NFT Standard
Deployment Steps:
Prerequisites:
- Install Solidity compiler and Qtum’s Solar tool.
- Clone the QRC721Token repository.
Deploy Contract:
solar deploy contracts/QRC721.sol '["name","symbol"]' --qtum_rpc=http://user:[email protected]:port- Output: Contract address and deployment details in
solar.development.json.
👉 Explore QRC721 documentation
FAQs
Q1: Can QRC20 tokens interact with ERC20 wallets?
A: No, QRC20 tokens are specific to Qtum’s blockchain but follow the same principles as ERC20.
Q2: How do NFTs differ from fungible tokens?
A: NFTs are unique and indivisible (e.g., digital art), while fungible tokens are interchangeable (e.g., cryptocurrencies).
Q3: What’s the gas fee structure for QRC721 transactions?
A: Similar to Ethereum, Qtum charges gas fees calculated in QTUM tokens.
Q4: Can I migrate ERC721 assets to QRC721?
A: Cross-chain migration requires bridging solutions or manual re-minting.
Conclusion
Qtum’s QRC20 and QRC721 standards empower developers to create versatile tokens while leveraging Bitcoin’s security and Ethereum’s flexibility. In Part 2, we’ll explore QRC1155, a multi-token standard combining the best of both worlds.
For advanced token strategies, 👉 visit our developer portal.