Minting a token off-chain

Although a token can remain off-chain as long as your user only wants to execute off-chain operations, such as minting and trading, you must enable your users to withdraw the new token on-chain.

To do so, you pair it with the on-chain contract in which the asset is minted, and register it with the StarkEx smart contract.

When your user makes a withdrawal request, StarkEx burns the off-chain token and sends a call to the mintFor function in the paired on-chain contract, which mints a corresponding on-chain token.

The operator needs to inform their users that the operator controls the offchain minting policy.

  • You must have minting privileges for the mintFor function. Only minters should have these privileges.

  1. Define a new token asset type by deploying an on-chain contract, for ERC-20, ERC-721, or ERC-1155, that includes a mintFor function. This function enables the contract to mint the token on-chain after the user withdraws the token that was minted off-chain.

    The mintFor function is defined in the ERC-20, ERC-1155, and ERC-721 contracts, with the following signature:

    MINTABLE_TOKEN(address).mintFor(withdrawer=msg.sender, asset_blob, amount)

  2. After you deploy the new token contract on-chain, register it to the StarkEx smart contract with the registerToken function in the TokenRegister.sol smart contract.

    Validium vaults and ZK-Rollup vaults each have a range of 31 bits for the ID of each vault. When you allocate new vaults, consider that the simplest way to allocate new vaults is sequentially. You can also reuse vaults with a zero balance.

  3. Mint new off-chain tokens using the MintRequest transaction type in the StarkEx REST API. The token_id field is computed as explained in Identifiers for supported assets. This field sets the mapping to the token contract’s address.

    The StarkEx API does not include the keyword asset_id. Use the keyword token_id in API calls to refer to a unique off-chain asset.

    The MintRequest method mints this token to an unused vault that you specify in the function call, such as your own vault or a user’s vault.

  4. If you mint the new token to your own vault, you can either transfer it to a user, using the TransferRequest transaction type, or trade it using the SettlementRequest transation type. Both of these transactions have a fee mechanism, so you can collect fees.

    A settlement transaction contains 2 signed limit orders.

  5. Your user can hold or trade the token off-chain. To execute any on-chain transactions, they must first withdraw the token on-chain, as described in the withdrawal flow. The withdrawal is included in a batch, and finalized off-chain, and then it is available for your user to withdraw on-chain. The withdrawAndMint function in your on-chain contract actually mints the token on-chain and transfers it to your user’s Ethereum account.

Additional resources