RaylsErc1155Handler
RaylsErc1155Handler is the abstract base contract for ERC1155 (multi-token) tokens on a Rayls Privacy Node. Extend it to create a multi-token contract supporting both fungible and non-fungible tokens that can be minted, burned, and teleported cross-chain.
Inheritance: RaylsApp, ERC1155, ERC1155Holder, Initializable, ReentrancyGuard, RaylsAccessManaged
Minimal implementation
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "@rayls/contracts/tokens/RaylsErc1155Handler.sol";
contract MyToken1155 is RaylsErc1155Handler {
constructor(
string memory _uri,
string memory _name,
address _endpoint,
address _raylsNodeEndpoint,
address _userGovernance,
address _owner
)
RaylsErc1155Handler(
_uri,
_name,
_endpoint,
_raylsNodeEndpoint,
_userGovernance,
_owner,
false
)
{}
}Constructor parameters
| Parameter | Description |
|---|---|
_uri | Base URI for token metadata |
_name | Collection name |
_endpoint | Privacy Node endpoint — routes messages to other Privacy Nodes via the Private Network Hub |
_raylsNodeEndpoint | Privacy Node endpoint for the Rayls Public Chain |
_userGovernance | RBAC contract that manages user roles and permissions within the Privacy Node |
_owner | Address granted the Owner role (mint, burn, submitTokenUpdate) |
The last parameter (false) marks this as a standard token. Pass true only if you are overriding the default transfer behavior.
Token registration lifecycle
After deploying your token, call registerToken on the Privacy Node's TokenRegistryReplica system contract:
TokenRegistryReplica.registerToken(tokenAddress, ErcStandard.ERC1155, false)Once the Private Hub operator approves the registration, the relayer calls receiveResourceId() on your contract automatically:
// Called by the relayer (MESSAGE_EXECUTOR role) after approval — do NOT call manually
function receiveResourceId(bytes32 _resourceId) public virtual restrictedAfter this, your token has a resourceId and is ready for cross-chain teleports.
Mint and burn
// Owner role only
function mint(address to, uint256 id, uint256 value, bytes memory data) public virtual restricted nonReentrant
// Owner role only
function burn(address from, uint256 id, uint256 value) public virtual restricted nonReentrantBoth functions automatically report the change to the Private Hub's TokenRegistry via _submitTokenUpdate.
Balance updates
// Owner role only
function submitTokenUpdate(
SharedObjects.BalanceUpdateType updateType,
uint256 id,
uint256 amount
) public virtual restrictedBalanceUpdateType is an enum: MINT or BURN. You rarely need to call this directly — mint and burn call it internally.
Teleport functions
Vanilla teleport
Simple burn-and-mint with no revert mechanism.
function teleport(
address to,
uint256 id,
uint256 value,
uint256 chainId,
bytes memory data
) public virtual nonReentrant returns (bool)Atomic teleport
Tokens are locked on the destination until confirmed. If the destination fails, the relayer reverts the operation.
function teleportAtomic(
address to,
uint256 id,
uint256 value,
uint256 chainId,
bytes memory data
) public virtual nonReentrant returns (bool)Teleport to Public Chain
Sends tokens from a Privacy Node to an address on the Rayls Public Chain. Requires the caller to be a registered user.
function teleportToPublicChain(
address to,
uint256 id,
uint256 value,
uint256 destinationChainId,
bytes memory data
) public virtual onlyRegisteredUsers nonReentrant returns (bool)Token locking
ERC1155 tokens lock amounts per (address, tokenId):
// Returns locked amount for a specific token ID held by an account
function getLockedAmount(address account, uint256 id) public view returns (uint256)Receive functions (called by the relayer)
| Function | Trigger |
|---|---|
receiveTeleport(address to, uint256 id, uint256 value, bytes data) | Vanilla teleport arrived — mints tokens |
receiveTeleportAtomic(address to, uint256 id, uint256 value, bytes data) | Atomic teleport arrived — mints and locks |
receiveTeleportFromPublicChain(address to, uint256 id, uint256 amount) | Public Chain → Privacy Node — unlocks tokens |
revertTeleportMint(address to, uint256 id, uint256 value, bytes data) | Atomic reverted on source — re-mints |
revertTeleportBurn(address to, uint256 id, uint256 value) | Atomic reverted on destination — unlocks and burns |
revertTeleportToPublicChain(address from, uint256 id, uint256 amount) | Public Chain mint failed — unlocks tokens |
unlock(address to, uint256 id, uint256 amount, bytes data) | Confirms atomic teleport — releases locked tokens |
All are restricted to MESSAGE_EXECUTOR.
Access control summary
| Role | Functions |
|---|---|
| Owner | mint, burn, submitTokenUpdate |
| MESSAGE_EXECUTOR | receiveTeleport, receiveTeleportAtomic, receiveTeleportFromPublicChain, revertTeleportMint, revertTeleportBurn, revertTeleportToPublicChain, unlock, receiveResourceId |
| Any address | teleport, teleportAtomic, teleportToPublicChain* |
teleportToPublicChainadditionally requiresonlyRegisteredUsers.
Updated 20 days ago
