The off-chain minting flow

Minting tokens on-chain has become increasingly expensive as Ethereum and gas prices have risen. For example, minting an ERC-721 NFT costs between 100,000 to 200,000 gas per asset. These prices are prohibitively expensive for many use cases. Off-chain minting solves this problem.

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

off chain minting
Figure 1. Off-chain minting flow for ERC-721 token

Off-chain minting is a StarkEx operation that creates off-chain representations of ERC-20, ERC-721, and ERC-1155 assets.

The on-chain contract is unaware of the asset until you withdraw it on-chain.

The asset ID is encoded in a compressed form called the minting blob, which is required in order to withdraw on-chain. The minting blob is not stored on-chain. The operator defines it and stores it in the application.

For more information on the types of assets and how to compute them, see the following sections in StarkEx Specific Concepts:

1. The application sends a minting request to StarkEx.

The application sends a mint request transaction to the StarkEx gateway, using the add_transaction API with the MintRequest transaction type.

The request includes the following information:

vault_id

The ID of the vault into which the token is minted.

stark_key

The public Stark key of the vault owner, as registered on the StarkEx contract.

token_id

Identifies the asset uniquely in StarkEx.

amount

The amount of tokens to be minted. For ERC-721 tokens, this value must be 1.

2. StarkEx validates the minting request.

To ensure that StarkEx cannot create any arbitrary asset, such as minting a large amount of ETH, StarkEx can only mint an off-chain asset if the operation conforms to the following constraints:

  • does not overwrite an existing vault

  • does not mint the same ERC-721 asset more than once

  • assigns bits 240-251 as follows:

    Table 1. Assignment of bits 240-251 per mintable asset type
    Bit 251 Bit 250 Bit 249 Bits 241-248

    ERC-721

    1

    0

    0

    0

    ERC-1155

    1

    1

    0

    0

    ERC-20

    1

    1

    1

    0

3. The minting operation is included in a batch.

If the mint request is valid, StarkEx includes it in a batch that it submits on-chain along with a validity proof.

4. Withdraw and mint.

To be fully non-custodial, a mintable asset must be paired with an on-chain contract in which the asset will be minted. When your user withdraws from off-chain to on-chain, your application must do the following:

  1. Call the withdrawAndMint function in the on-chain contract.

  2. Provide the minting blob to enable the asset contract to create the token.