Skip to main content
Version: v1.1

Mint Native Tokens

To mint tokens from a foundry, you first need to be aware that only the foundry owner can mint token, so you should execute the ISC.accounts.mintNativeTokens function in the same contract where you also created the native token.

Example Code

Ownership

You might want to look into making the function ownable with, for example, OpenZeppelin so only owners of the contract can call certain functionalities of your contract.

1. Check the Storage Deposit

Check if the amount paid to the contract is the same as the required storage deposit and set the allowance.

require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit");
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;
Payable

Instead of making the function payable, you could let the contract pay for the storage deposit. If so, you will need to change the require statement to check if the contract's balance has enough funds:

require(address(this).balance > _storageDeposit);

2. Mint the Native Token

Mint the native token specifying the foundry serial number, the amount to mint and the allowance.

ISC.accounts.mintNativeTokens(_foundrySN, _amount, allowance);

Full Example Code

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@iota/iscmagic/ISC.sol";

contract NativeTokenMinter {
event MintedNativeTokens(uint32 foundrySN, uint amount);

function mintNativeTokens(uint32 _foundrySN, uint _amount, uint64 _storageDeposit) public payable {
require(msg.value == _storageDeposit * (10 ** 12), "Please send exact funds to pay for storage deposit");

ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;

ISC.accounts.mintNativeTokens(_foundrySN, _amount, allowance);

emit MintedNativeTokens(_foundrySN, _amount);
}
}