← Back to list

Enumerated Types: How does Cardano identify them?

As a new programmer, an enumerated type is one more thing that confused the s*** out of me. I never really understood how Cardano…

gZero · 2025-07-01 18:51 · 0 claps · 1.7 min read
#cardano #cardano-development #blockchain-development #aiken #validator
Open on Medium ↗
Wiki topics: CRY · Crypto & Web3

Enumerated Types: How does Cardano identify them?

As a new programmer, an enumerated type is one more thing that confused the s*** out of me. I never really understood how Cardano identifies them.

Not anymore, and neither will you in about 3 minutes.

Say, for example, I defined a redeemer like this:

pub type MintRedeemer {
 TypeOne
 TypeTwo
}

The above defines a Redeemer called MintRedeemer with two different constructors, which translates to MintRedeemer can either be TypeOne or TypeTwo, but not both.

Notice how all these are just random names we gave for the redeemer and its constructors.

Now let’s see how we can use this redeemer type we defined:

Below is my minting validator that says, if you see a TypeOne redeemer in the transaction, move forward with the minting one token w/ the specified policy.

If you see a TypeTwo redeemer, move forward with burning any number of tokens w/ the specified policy.

And if it is anything else, reject the transaction.

use aiken/assets.{AssetName, PolicyId}
use vodka_mints.{check_policy_only_burn, check_policy_only_minted}

validator mint_and_burn(){
  // Destructure transaction to get the mint value
  let transaction{mint, ..} = tx
  // Assign Assetname
  let x:AssetName = #"40420f"
  mint(redeemer: MintRedeemer, policy_id: PolicyId, tx: Transaction){
    when redeemer is {
        TypeOne -> check_policy_only_minted(mint, policy_id, x, 1)
        TypeTwo -> check_policy_only_burn(mint, policy_id)
        _ -> False
      }
  }

  else(_){
    fail
  }
}

When passing a redeemer to a transaction, we don’t use the constructor keywords TypeOne or TypeTwo.

So, now the question becomes, how does the blockchain know which type of redeemer is passed?

Here is the big reveal…

When passing the TypeOne redeemer to the transaction, we construct it as:

{ "constructor": 0, "fields": [] }   // for TypeOne

The key here is the “constructor”: 0; That is how the blockchain knows it’s the TypeOne redeemer.

Similarly, the TypeTwo redeemer is constructed as:

{ "constructor": 1, "fields": [] }   // for TypeTwo

To tie it all together, the ordering of the constructors in your redeemer type is all that matters to the blockchain. The names are just for you to read your validator better.

If your redeemer is defined like this:

pub type MintRedeemer {
 TypeTwo
 TypeOne
}

Then you’d have to construct your redeemers like this:

{ "constructor": 0, "fields": [] }   // for TypeTwo
{ "constructor": 1, "fields": [] }   // for TypeOne

Hope that helped!


메타데이터
post_id
deb979f3dd07
slug
enumerated-types-how-does-cardano-identify-them-deb979f3dd07
url
https://medium.com/@gullafourteen/enumerated-types-how-does-cardano-identify-them-deb979f3dd07
canonical_url
https://medium.com/@gullafourteen/enumerated-types-how-does-cardano-identify-them-deb979f3dd07
author_url
https://medium.com/@gullafourteen
status
ok
fetched_at
2026-06-25 12:15:08