Deploying an ERC-1155 Multi-Token
ERC-1155 lets one contract hold many token types — fungible or non-fungible — with efficient batch operations. Same pattern on OXN as on Ethereum.
Standard ERC-1155
contracts/GameItems.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract GameItems is ERC1155, Ownable {
uint256 public constant SWORD = 0;
uint256 public constant SHIELD = 1;
uint256 public constant POTION = 2;
constructor(address initialOwner)
ERC1155("https://game.example/api/item/{id}.json")
Ownable(initialOwner)
{}
function mint(address to, uint256 id, uint256 amount) external onlyOwner {
_mint(to, id, amount, "");
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts)
external onlyOwner
{
_mintBatch(to, ids, amounts, "");
}
}
Deploy with gasLimit: 4_000_000n.
Confidential per-player state (game example)
Games with hidden inventories or in-game stats can use OXN's confidentiality:
mapping(address => mapping(uint256 => uint256)) private hiddenStats;
function updateStats(uint256 itemId, uint256 newValue) external {
require(balanceOf(msg.sender, itemId) > 0, "must own item");
hiddenStats[msg.sender][itemId] = newValue; // stored encrypted
}
function getMyStats(uint256 itemId) external view returns (uint256) {
return hiddenStats[msg.sender][itemId]; // signed query only
}
Players see their own item stats; opponents can't inspect them off-chain.
Confidential batch transfers
Standard safeBatchTransferFrom on OXN encrypts the arguments (ids and amounts) automatically. Observers see that a transfer happened between two addresses but not which items or quantities.
Full example
See the OXN sample repository for a runnable game-items project.
Next steps
- Building a Sealed-Bid Auction — confidentiality applied to a specific pattern
- Randomness — for game mechanics