Time to read: 1 min
Runes Mock Bridge Contract Explanation walk through
1. Understanding the Contract Structure
This contract defines a new token type, RuneToken, based on the ERC-1155 standard. It also uses the Ownable contract, which restricts certain functions to the contract's owner.
Key Imports:
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
- ERC1155: This is a token standard that supports both fungible and non-fungible tokens within the same contract.
- Ownable: This contract standard restricts certain actions to only the contract's owner (the one who deployed it or someone assigned as the owner).
- Strings: A utility library for working with string conversions.
Main Components of the Contract
Events:
TokensFrozen: Emits an event when tokens are frozen for a specific account.TokensUnfrozen: Emits an event when tokens are unfrozen.
Data Structures:
- Balance: Holds the account and balance of a token.
- TokenInfo: Contains details about a token, such as its URI ( Uniform Resource Identifier), name, symbol, maximum supply, current supply, default minting amount, and balance.
Mappings:
_tokenInfos: Stores the information about each token, keyed by the token ID._userTokens: Tracks all tokens held by a user._frozenTokens: Keeps track of how many tokens are frozen for each user.
2. The Constructor
constructor(address initialOwner) ERC1155("") Ownable(initialOwner) {}
- ERC1155 (""): This calls the ERC1155 constructor, but the URI is set as an empty string initially.
- Ownable (initialOwner): The
Ownablecontract is initialized with theinitialOwneras the owner of the contract, allowing only this address to perform certain actions (e.g., minting).
3. The uri Function
function uri(uint256 tokenId) public view override returns (string memory) {
return _tokenInfos[tokenId].uri;
}
This function returns the URI for a given token ID. The URI typically points to a metadata file that contains additional details about the token (e.g., images, descriptions).