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, for a mintable asset to be fully non-custodial, 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.
You must have minting privileges for the
mintForfunction. Only minters should have these privileges.
Define a new token asset type by deploying an on-chain contract, for ERC-20, ERC-721, or ERC-1155, that includes a
mintForfunction. This function enables the contract to mint the token on-chain after the user withdraws the token that was minted off-chain.
mintForfunction 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)
After you deploy the new token contract on-chain, 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 off-chain tokens using the
MintRequesttransaction type in the StarkEx REST API. The
token_idfield 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_idin API calls to refer to a unique off-chain asset.
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
TransferRequesttransaction type, or trade it using the
SettlementRequesttransation type. 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 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
withdrawAndMintfunction in your on-chain contract actually mints the token on-chain and transfers it to your user’s Ethereum account.
registerTokenfunction in the
withdrawAndMintfunction in the
mintForfunction appears in the ERC-20, ERC-721, and ERC-1155 contracts.