Minting an NFT off-chain
Although an NFT can remain off-chain as long as your user only wants to execute L2 operations, such as minting and trading, for a mintable asset to be fully non-custodial, you must enable your users to withdraw the new NFT to L1. 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.
You must have minting privileges for the
mintForfunction. Only minters should have these privileges.
Define a new NFT asset type by deploying an ERC-721 contract that includes a
minForfunction mints an ERC-721 token. When your user withdraws an NFT onto L1, the StarkEx smart contract calls this function. The
mintForfunction mints the L2 NFT onto L1 as a new, ERC-721 token.
mintForfunction is defined in the ERC-721 and ERC-20 contracts, with the following signature:
MINTABLE_TOKEN(address).mintFor(withdrawer=msg.sender, asset_blob, amount)
After you deploy the new ERC-721 contract to L1, register it to the StarkEx smart contract with the
registerTokenfunction in the
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.
Mint new tokens on L2 by using the
MintRequestmethod in the StarkEx Common Objects API. The
token_idfield is computed as explained in AssetInfo, AssetType and AssetId. This field sets the mapping to the ERC-721 contract, the
token_idcomputation includes the contract address.
Be aware that mintable ERC-721 tokens have an
asset_idparameter instead of
token_id, but semantically, these parameters are identical.
MintRequestmethod mints this token to an unused vault that you specify in the function call, such as your own vault or a user’s vault.
If you mint the new token to your own vault, you can either transfer it to a user, using the
TransferRequestAPI method, or trade it using the
SettlementRequestAPI method. Both of these transactions have a fee mechanism, so you can collect fees.
A settlement transaction contains 2 signed limit orders.
Your user can hold or trade the NFT on L2. To do any transactions on L1, you must first withdraw to L1 using the
WithdrawalRequestAPI method. The withdrawal is included in a batch, and finalized on L2, and then it is available for your user to withdraw to L1. The L1 StarkEx contract
withdrawAndMintfunction actually mints the NFT on L1 and transfers it to your user’s Ethereum account.