HomeCoinsQTUM (QTUM)The Token Standards Of Qtum Part 2 — QRC1155 | by Qtum...

The Token Standards Of Qtum Part 2 — QRC1155 | by Qtum | Sep, 2021

- Advertisement -


The QRC1155 token standard brings together QRC20 and QRC721 under one roof. As a result, it makes it very simple for developers to create sophisticated smart contracts without getting lost in a barrage of redundant code.

Code Snippets

Please adjust for indentation and line wraps, which are not given in the format below.

Tokenized Items Contract

// contracts/GameItems.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import “@openzeppelin/contracts/token/ERC1155/ERC1155.sol”;

contract GameItems is ERC1155 {

uint256 public constant GOLD = 0;

uint256 public constant SILVER = 1;

uint256 public constant THORS_HAMMER = 2;

uint256 public constant SWORD = 3;

uint256 public constant SHIELD = 4;

constructor() public ERC1155(“https://game.example/api/item/{id}.json”) {

_mint(msg.sender, GOLD, 10**18, “”);

_mint(msg.sender, SILVER, 10**27, “”);

_mint(msg.sender, THORS_HAMMER, 1, “”);

_mint(msg.sender, SWORD, 10**9, “”);

_mint(msg.sender, SHIELD, 10**9, “”);

}

}

Deployer balance

> gameItems.balanceOf(deployerAddress,3)

1000000000

Transfer items

> gameItems.safeTransferFrom(deployerAddress, playerAddress, 2, 1, “0x0”)

> gameItems.balanceOf(playerAddress, 2)

1

> gameItems.balanceOf(deployerAddress, 2)

0

Batch Transactions

> gameItems.safeBatchTransferFrom(deployerAddress, playerAddress, [0,1,3,4], [50,100,1,1], “0x0”)

> gameItems.balanceOfBatch([playerAddress,playerAddress,playerAddress,playerAddress,playerAddress], [0,1,2,3,4])

[50,100,1,1,1]

Metadata URI

> gameItems.uri(2)

“https://game.example/api/item/{id}.json”

JSON Document

{

“name”: “Thor’s hammer”,

“description”: “Mjölnir, the legendary hammer of the Norse god of thunder.”,

“image”: “https://game.example/item-id-8u5h2m.png”,

“strength”: 20

}



Source link

- Advertisement -
Mr Bitcointehttps://www.bitcointe.com/
“Fact You Need To Know About Cryptocurrency - The first Bitcoin purchase was for pizza.” ― Mohsin Jameel
462FansLike
76FollowersFollow
4,567FollowersFollow
5,261FollowersFollow
1,507FollowersFollow
2,230SubscribersSubscribe

Most Popular

bitcoin
Bitcoin (BTC) $ 61,768.00
ethereum
Ethereum (ETH) $ 4,054.58
tether
Tether (USDT) $ 1.01
bitcoin-cash
Bitcoin Cash (BCH) $ 626.69
litecoin
Litecoin (LTC) $ 197.67
eos
EOS (EOS) $ 4.74
okb
OKB (OKB) $ 27.56
tezos
Tezos (XTZ) $ 6.78
leo-token
LEO Token (LEO) $ 3.43
cardano
Cardano (ADA) $ 2.17
monero
Monero (XMR) $ 267.99
stellar
Stellar (XLM) $ 0.376438
chainlink
Chainlink (LINK) $ 30.80
huobi-token
Huobi Token (HT) $ 10.14
tron
TRON (TRX) $ 0.100682
usd-coin
USD Coin (USDC) $ 1.01
dash
Dash (DASH) $ 197.40
neo
NEO (NEO) $ 44.56
iota
IOTA (MIOTA) $ 1.32
nem
NEM (XEM) $ 0.176754
zcash
Zcash (ZEC) $ 171.98
maker
Maker (MKR) $ 2,545.44
paxos-standard
Pax Dollar (USDP) $ 1.01
ethereum-classic
Ethereum Classic (ETC) $ 55.24
vechain
VeChain (VET) $ 0.137615
true-usd
TrueUSD (TUSD) $ 1.01
ftx-token
FTX Token (FTT) $ 63.28
kucoin-shares
KuCoin Token (KCS) $ 14.89
waves
Waves (WAVES) $ 28.54