
# Cardano Example Dapp

## **CIP-68 NFT Mint**

Mints a CIP-68 token pair under one native script policy: a (100) reference NFT that carries the metadata as an inline datum, and a (222) user NFT that the holder actually owns. Unlike CIP-25, the metadata lives in an eUTXO datum instead of transaction metadata, so it can be updated later by whoever controls the reference token under the script-controlled address that holds it. The datum follows the CIP-68 shape #6.121([metadata, version, extra]) with 'extra' set to Unit/Void. Every value a dapp would want to change is exposed as a flat argument, and after submitting, the wallet redirects to a block explorer that renders CIP-68 tokens so the result can be checked. ONE DELIBERATE SIMPLIFICATION, for example purposes: uniqueness of the reference NFT rests on issuer behaviour plus the policy time-lock, not on a one-shot policy that consumes a specific UTXO, so the policy could technically mint another (100) token before it expires. A production issuer should use a one-shot minting policy. 


## Try it online: 

-  Visit [HTML+JS Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/CIP-68%20NFT%20Mint.html)
-  Visit [HTML+React Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/CIP-68%20NFT%20Mint_react.html)
-  Visit [Native HTML dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/CIP-68%20NFT%20Mint_nolib.html)
-  Run [Standalone URL dapp connection](https://wallet.gamechanger.finance/api/2/run/1-H4sIAAAAAAAAA8VYWXPbOBL-KyjtA6UqkpaPcaX8piROxhOP4xnL2a1M5QEiIQljEmBw2NKm_N-3GwApUqZsJdnafdEBNLq_vhv4NjDcFGxwNnhzcZ2cviJX76bkdy7MIB7kTGeKV4ZLAfu4qAklgc7IOyZIRbkiVuRMESkYEdTwe0b8MVLJgmfrMzgzPByPR0SxOVNMZMwJMUtqSEaV4kzDH0ZKZmhODSUUxAjCRcGBJazYMoaFHPkcHR2NiNUgrmGBR5eyQAg0M5YWxZrIB6FTcgsc7pgDfPRL3JVRAE4NMlASu53-66MXBCvaMJoTOSdGUaGBJajfnIuJloQjbkFmjNgKFllOCvhUZLYmD0vJ7uFnJoVRsvCKbfT2RvP2wh1vqCRQF8CJ5rliWnvVUC0AaVIyXQZLk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mBPld_VGJHFV0tBiLu9HQ4wePZj1BjhKQ8IMsh_ayprdOcpAd9jsEPVzaDDu9MoQpGs64_70VPtO4UqxWiqC33HND9l3Z82KeSmm8qe1Z629f6fQX_WifhUxL5aDleNG74QTOn2XPF9YwRkPT6T-mm6Pbq4haBNGGb20LTu5m7AAGytQoZ_p6t6pNhUClyHWbRd0HIIHw4D6jVTJagF1QvQzGmhGSY12r-DxJXI1KyCdHSrf6NuS3cLvfL9c_YWBCemmwaAMxhtzgW-3L54dd7i0L7u-fqEjtgiapQJPop_ONJ-0HlPJsOXikFGBRrtFgts-0a4R6ltXb8mP5jSmCn7ne3kVN3k3n5vAYNhwHUs_7j7_29zmGv_AcjR6PrvGwAA)

## Source code:

- dapp connection code: [GCScript DSL](CIP-68%20NFT%20Mint.gcscript)
- frontend (using @gamechanger-finance/gc): [HTML+JS dapp](CIP-68%20NFT%20Mint.html)
- frontend (using @gamechanger-finance/gc): [HTML+React dapp](CIP-68%20NFT%20Mint_react.html)
- frontend (without official library): [Native HTML dapp](CIP-68%20NFT%20Mint_nolib.html)

Dapp code was autogenerated by [Playground IDE in GameChanger Wallet ](https://wallet.gamechanger.finance/playground)

## GCScript code (dapp connection):
```json
{
  "title": "CIP-68 NFT Mint",
  "description": "Mints a CIP-68 token pair under one native script policy: a (100) reference NFT that carries the metadata as an inline datum, and a (222) user NFT that the holder actually owns. Unlike CIP-25, the metadata lives in an eUTXO datum instead of transaction metadata, so it can be updated later by whoever controls the reference token under the script-controlled address that holds it. The datum follows the CIP-68 shape #6.121([metadata, version, extra]) with 'extra' set to Unit/Void. Every value a dapp would want to change is exposed as a flat argument, and after submitting, the wallet redirects to a block explorer that renders CIP-68 tokens so the result can be checked. ONE DELIBERATE SIMPLIFICATION, for example purposes: uniqueness of the reference NFT rests on issuer behaviour plus the policy time-lock, not on a one-shot policy that consumes a specific UTXO, so the policy could technically mint another (100) token before it expires. A production issuer should use a one-shot minting policy. ",
  "type": "script",
  "exportAs": "CIP68Mint",
  "return": {
    "mode": "last"
  },
  "args": {
    "asset-name": "GameChangerCIP68",
    "display-name": "GameChanger CIP-68 NFT",
    "image-uri": "ipfs://QmVWGxAKpB2Sxy3ZnfZsdt3gxocFEUUe8GPBcraLTZSQKT",
    "media-type": "image/png",
    "policy-lifetime-slots": "86400",
    "cardano-mainnet": {
      "nft-viewer-URL": "https://cardanoscan.io/token/"
    },
    "cardano-preprod": {
      "nft-viewer-URL": "https://preprod.cardanoscan.io/token/"
    }
  },
  "run": {
    "cip68": {
      "type": "macro",
      "run": {
        "referenceLabel": "000643b0",
        "userLabel": "000de140"
      }
    },
    "argumentGuards": {
      "type": "macro",
      "run": {
        "asset-name-must-be-a-string": "{ assert( isType('string',get('args.asset-name')) ,'asset-name must be a string' , get('args') ) }",
        "asset-name-must-not-be-empty": "{ assert( not(isEmptyString(get('args.asset-name'))) ,'asset-name must not be empty' , get('args') ) }",
        "display-name-must-not-be-empty": "{ assert( not(isEmptyString(get('args.display-name'))) ,'display-name must not be empty: it is the on-chain metadata name' , get('args') ) }",
        "image-uri-must-not-be-empty": "{ assert( not(isEmptyString(get('args.image-uri'))) ,'image-uri must not be empty' , get('args') ) }",
        "policy-lifetime-must-be-gt-than-zero": "{ assert( cmpBigNum('gt',get('args.policy-lifetime-slots'),'0') ,'policy-lifetime-slots must be greater than zero' , get('args') ) }"
      }
    },
    "networkInfo": {
      "type": "getNetworkInfo"
    },
    "networkKey": {
      "type": "macro",
      "run": "{ join('-',get('cache.networkInfo.dltTag'),get('cache.networkInfo.networkTag')) }"
    },
    "network": {
      "type": "macro",
      "run": "{ get(join('.','args',get('cache.networkKey'))) }"
    },
    "networkGuards": {
      "type": "macro",
      "run": {
        "network-must-be-supported": "{ assert( not(isType('null',get('cache.network'))) ,'this dapp has no data configured for the connected network' , get('cache.networkKey') ) }",
        "nft-viewer-url-must-be-provided": "{ assert( not(isEmptyString(get('cache.network.nft-viewer-URL'))) ,'this dapp has no NFT viewer configured for the connected network' , get('cache.networkKey') ) }"
      }
    },
    "address": {
      "type": "getCurrentAddress"
    },
    "addressInfo": {
      "type": "macro",
      "run": "{getAddressInfo(get('cache.address'))}"
    },
    "currentSlotNumber": {
      "type": "getCurrentSlot"
    },
    "deadlineSlotNumber": {
      "type": "macro",
      "run": "{addBigNum(get('cache.currentSlotNumber'),get('args.policy-lifetime-slots'))}"
    },
    "assetNames": {
      "type": "macro",
      "run": {
        "bare": "{strToHex(get('args.asset-name'))}",
        "referenceHex": "{join('',getArray(get('cache.cip68.referenceLabel'),strToHex(get('args.asset-name'))))}",
        "userHex": "{join('',getArray(get('cache.cip68.userLabel'),strToHex(get('args.asset-name'))))}"
      }
    },
    "assetNameGuards": {
      "type": "macro",
      "run": {
        "labelled-asset-name-must-fit-in-32-bytes": "{ assert( eq(get('cache.assetNames.referenceHex'),truncate(get('cache.assetNames.referenceHex'),64,0,'')) ,'CIP-68 label plus asset-name must not exceed 32 bytes (64 hex chars)' , get('cache.assetNames') ) }",
        "audit-trail": "{ console('info',objToJson(get('cache.assetNames'))) }"
      }
    },
    "mintingPolicy": {
      "type": "nativeScript",
      "script": {
        "all": {
          "issuer": {
            "pubKeyHashHex": "{get('cache.addressInfo.paymentKeyHash')}"
          },
          "timeLock": {
            "slotNumEnd": "{get('cache.deadlineSlotNumber')}"
          }
        }
      }
    },
    "scriptAddress": {
      "type": "buildAddress",
      "name": "ScriptAddressForUser",
      "addr": {
        "spendScriptHashHex": "{get('cache.mintingPolicy.scriptHashHex')}"
      }
    },
    "metadataKeys": {
      "type": "macro",
      "run": {
        "name": "{strToHex('name')}",
        "image": "{strToHex('image')}",
        "mediaType": "{strToHex('mediaType')}",
        "displayName": "{strToHex(get('args.display-name'))}",
        "imageUri": "{strToHex(get('args.image-uri'))}",
        "mediaTypeValue": "{strToHex(get('args.media-type'))}"
      }
    },
    "metadatumDatum": {
      "type": "plutusData",
      "data": {
        "fromJSON": {
          "schema": 1,
          "obj": {
            "constructor": 0,
            "fields": [
              {
                "map": [
                  {
                    "k": {
                      "bytes": "{get('cache.metadataKeys.name')}"
                    },
                    "v": {
                      "bytes": "{get('cache.metadataKeys.displayName')}"
                    }
                  },
                  {
                    "k": {
                      "bytes": "{get('cache.metadataKeys.image')}"
                    },
                    "v": {
                      "bytes": "{get('cache.metadataKeys.imageUri')}"
                    }
                  },
                  {
                    "k": {
                      "bytes": "{get('cache.metadataKeys.mediaType')}"
                    },
                    "v": {
                      "bytes": "{get('cache.metadataKeys.mediaTypeValue')}"
                    }
                  }
                ]
              },
              {
                "int": 1
              },
              {
                "constructor": 0,
                "fields": []
              }
            ]
          }
        }
      }
    },
    "build": {
      "type": "buildTx",
      "name": "built-CIP68Mint",
      "title": "CIP-68 NFT Mint",
      "description": "Mints the (100) reference NFT with its metadata datum and the matching (222) user NFT.",
      "returnURLPattern": "{join('',getArray(get('cache.network.nft-viewer-URL'),get('cache.mintingPolicy.scriptHashHex'),get('cache.assetNames.userHex')))}",
      "tx": {
        "ttl": {
          "until": "{get('cache.deadlineSlotNumber')}"
        },
        "mints": [
          {
            "policyId": "{get('cache.mintingPolicy.scriptHashHex')}",
            "assets": [
              {
                "assetNameHex": "{get('cache.assetNames.referenceHex')}",
                "quantity": "1"
              },
              {
                "assetNameHex": "{get('cache.assetNames.userHex')}",
                "quantity": "1"
              }
            ]
          }
        ],
        "outputs": {
          "referenceNFT": {
            "address": "{get('cache.scriptAddress')}",
            "datum": {
              "datumHex": "{get('cache.metadatumDatum.dataHex')}"
            },
            "assets": [
              {
                "policyId": "{get('cache.mintingPolicy.scriptHashHex')}",
                "assetNameHex": "{get('cache.assetNames.referenceHex')}",
                "quantity": "1"
              }
            ]
          },
          "userNFT": {
            "address": "{get('cache.address')}",
            "assets": [
              {
                "policyId": "{get('cache.mintingPolicy.scriptHashHex')}",
                "assetNameHex": "{get('cache.assetNames.userHex')}",
                "quantity": "1"
              }
            ]
          }
        },
        "requiredSigners": {
          "issuer": "{get('cache.addressInfo.paymentKeyHash')}"
        },
        "witnesses": {
          "nativeScripts": {
            "mintingScript": "{get('cache.mintingPolicy.scriptHex')}"
          }
        }
      }
    },
    "sign": {
      "type": "signTxs",
      "namePattern": "signed-CIP68Mint",
      "detailedPermissions": false,
      "txs": [
        "{get('cache.build.txHex')}"
      ]
    },
    "submit": {
      "type": "submitTxs",
      "namePattern": "submitted-CIP68Mint",
      "txs": "{get('cache.sign')}"
    },
    "finally": {
      "type": "macro",
      "run": {
        "network": "{get('cache.networkKey')}",
        "txHash": "{get('cache.build.txHash')}",
        "policyId": "{get('cache.mintingPolicy.scriptHashHex')}",
        "mintingScript": "{get('cache.mintingPolicy.scriptHex')}",
        "scriptAddress": "{get('cache.scriptAddress')}",
        "canMintUntilSlotNumber": "{get('cache.deadlineSlotNumber')}",
        "referenceAssetNameHex": "{get('cache.assetNames.referenceHex')}",
        "userAssetNameHex": "{get('cache.assetNames.userHex')}",
        "metadataDatumHex": "{get('cache.metadatumDatum.dataHex')}",
        "viewerURL": "{join('',getArray(get('cache.network.nft-viewer-URL'),get('cache.mintingPolicy.scriptHashHex'),get('cache.assetNames.userHex')))}"
      }
    }
  }
}
```

## Run standalone QR dapp connection: 

You can use [Playground IDE in GameChanger Wallet ](https://wallet.gamechanger.finance/playground) in `QR URL Transport` mode to capture results

[![This GCScript/URL is too large! make it shorter uploading parts to GCFS. Unable to generate QR code](CIP-68%20NFT%20Mint.png)](https://gamechangerfinance.github.io/gamechanger.wallet/examples/CIP-68%20NFT%20Mint.png)

## Resources
- [How to connect?](https://www.npmjs.com/package/@gamechanger-finance/gc)
- [Docs and examples on Github](https://github.com/GameChangerFinance/gamechanger.wallet/)
- [GCScript documentation](https://wallet.gamechanger.finance/doc/api/v2)
- [Playground IDE in GameChanger Wallet ](https://wallet.gamechanger.finance/playground)
- [Tutorials on Youtube](https://www.youtube.com/@gamechanger.finance)
- [Support on Discord](https://discord.gg/vpbfyRaDKG)
- [News on Twitter](https://twitter.com/GameChangerOk)
- [Website](https://gamechanger.finance)

## License
MIT 
    
