Mint A Pre-Existing Index Token

To interact with index contracts in order to mint a new amount of an Index token, it is necessary to use the second mint public function:

function mint(uint256 objectId, uint256 value, address receiver) public override payable

This function uses the interoperable Item interface version.

Its inputs are as follows:

  • objectId -> the index token's interoperable interface objectId. Pass objectId = 0x0000000000000000000000000000000000000000 to input ETH

  • value -> amount of the index tokens to mint. The value parameter calculates the required token amounts to mint the index tokens as tokenValue = (_amounts[i] * value) / 1e18

  • receiver -> pass 0x0000000000000000000000000000000000000000 to send the index tokens to msg.sender or otherwise the specific receiver address

The mint function internally calls the _safeTransferFrom function to transfer the required token amounts from the msg.sender to the contract, or msg.value in the case that ETH is involved:

if(tokens[objectId][i] == address(0)) {
    ethInvolved = true;
     require(msg.value == tokenValue, "insufficient eth");
} else {
     _safeTransferFrom(tokens[objectId][i], msg.sender, address(this), tokenValue);

It then mints the amount of index tokens by calling the mint method of the native Item collection, and then sends them to the receiver address using the _safeTransfer method via the index token's interoperable Item interface version:, value);
_safeTransfer(address(theCollection.asInteroperable(objectId)), receiver == address(0) ? msg.sender : receiver, theCollection.toInteroperableInterfaceAmount(objectId, theCollection.balanceOf(address(this), objectId)));

Last updated