Skip to content

Instantly share code, notes, and snippets.

@yihuang
Last active March 17, 2021 06:50
Show Gist options
  • Save yihuang/bba81eb0724f0b499cffcadca9cdc79f to your computer and use it in GitHub Desktop.
Save yihuang/bba81eb0724f0b499cffcadca9cdc79f to your computer and use it in GitHub Desktop.
native asset design patterns

native asset design patterns

Fixed max supply

Problem

You want your token to have fixed max supply (NFT is just token with 1 max supply).

Solution

Invalidate the mint script after some slot number, then we can be sure no more new tokens can be minted after that.

Mint script:

{
  "type": "all",
  "scripts":
  [
    {
      "type": "before",
      "slot": SLOT_NUMBER
    },
    {
      "type": "sig",
      "keyHash": "KEY_HASH"
    }
  ]
}

The creator mint the max supply number of tokens before SLOT_NUMBER. Further token distribution logic can be encoded into the receipient address.

NFT Mint Demo

Time locking

Problem

You want to lock newly minted tokens until some time later.

Solution

Always mint the tokens into an address guarded by both signature and time.

Airdrop

Problem

Distribute token to mass users directly is very costly in Cardano because of UTxO model, you'll need to pay lots of money for those minimal ada required for UTxOs. So we have to find another way.

Solution

  • Find your airdrop target from current total UTxO set on chain, apply some criteria you like, for example ada >= 10.

  • Build the token transfer transaction for each recipient like this (send 100 token to recipient):

    inputs:
      token_distributor, a token
      recipient, b lovelace
    outputs:
      token_distributor, (a - 100) token
      recipient, b lovelace + 100 token - tx fee
    
  • Add witness for token_distributor.

  • Package all the transactions and publish them somewhere, could publish to on chain metadata if the package is not too big.

  • User find the airdrop event and download the package, find the relevant transactions, sign and submit those transactions to receive the tokens. A wallet can automate these steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment