IOkrw.mint
mint(address recipient, uint256 amount) external returns (bool) Mints a specified amount of OKRW tokens and credits them to the recipient address. This function can only be successfully called by the authorized Minter address, which is configured at the chain level in the x/okrw module parameters. Calls from any other address will revert with a custom error.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
recipient | address | ✓ | The address to receive the newly minted OKRW. Cannot be the zero address. |
amount | uint256 | ✓ | The amount of OKRW to mint, in aokrw (the chain's base denom; 18 decimals — see concepts/core/okrw-precompile-overview for the unit definition). Must be greater than zero. |
Returns
bool Returns true on successful execution. The function will revert on failure rather than returning false.
Errors
| Code | Name | Description |
|---|---|---|
UnauthorizedMinter | UnauthorizedMinter | Reverts if the msg.sender of the call is not the authorized minter. Returns the caller and the authorizedMinter addresses. |
InvalidAddress | InvalidAddress | Reverts if the provided recipient address is invalid (e.g., the zero address) or if the caller address can't be normalized to a chain-side account. Returns the invalid addr. |
InvalidAmount | InvalidAmount | Reverts if the amount is zero. Note: The current implementation returns a generic revert reason for this case. |
Examples
Basic Minting from a Contract
This example shows a contract that calls the mint function. For this to succeed, the address of MinterContract itself must be set as the authorized minter in the x/okrw module parameters.
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.18;
import "./IOkrw.sol";
contract MinterContract {
address constant OKRW_PRECOMPILE = 0x1000000000000000000000000000000000000001;
IOkrw okrw = IOkrw(OKRW_PRECOMPILE);
// This function will only succeed if this contract's address
// is the authorized minter on the Maroo network.
function mintOkrw(address to, uint256 amount) external {
bool success = okrw.mint(to, amount);
require(success, "OKRW minting failed");
}
} Handling Custom Errors in Solidity
This example demonstrates how to use a try/catch block to gracefully handle a potential UnauthorizedMinter error from the precompile, allowing the contract to react to the failure instead of reverting entirely.
// ...
function safeMintOkrw(address to, uint256 amount) external {
try okrw.mint(to, amount) returns (bool success) {
require(success, "Mint returned false");
// Emit a local event or perform other logic
} catch (bytes memory lowLevelData) {
// Decode the 4-byte error selector from the revert payload.
// bytes memory slicing isn't supported in Solidity, so use assembly.
bytes4 selector;
assembly { selector := mload(add(lowLevelData, 32)) }
if (selector == IOkrw.UnauthorizedMinter.selector) {
// Strip the selector and decode the remaining args.
bytes memory args = new bytes(lowLevelData.length - 4);
for (uint i = 0; i < args.length; i++) args[i] = lowLevelData[i + 4];
(address caller, address authorizedMinter) = abi.decode(args, (address, address));
// Handle unauthorized error, e.g., emit an event
revert("Unauthorized minter caught");
} else {
revert("Unknown custom error");
}
}
} Calling and Handling Errors with Ethers.js
This client-side example shows how to call the mint function and parse the custom error data if the transaction reverts. This is useful for providing clear feedback to users in a dApp interface.
const { ethers } = require("ethers");
const okrwPrecompileAddress = "0x1000000000000000000000000000000000000001";
const okrwAbi = [
"function mint(address recipient, uint256 amount) external returns (bool)",
"error UnauthorizedMinter(address caller, address authorizedMinter)"
];
// Assume 'unauthorizedSigner' is an ethers.Signer for an account that is NOT the minter
const okrwContract = new ethers.Contract(okrwPrecompileAddress, okrwAbi, unauthorizedSigner);
async function attemptMint(recipient, amount) {
try {
const tx = await okrwContract.mint(recipient, ethers.parseEther(amount));
await tx.wait();
console.log("Minting successful!");
} catch (error) {
if (error.data) {
const decodedError = okrwContract.interface.parseError(error.data);
console.error(`Minting failed with error: ${decodedError.name}`);
console.error(`Args: ${decodedError.args}`);
} else {
console.error("An unknown error occurred:", error.message);
}
}
}
attemptMint("0xRecipientAddress...", "1500000");