Skip to main content

Cardano Example Dapp

Native asset minter and burner​

Creates a native script and uses it as policy to mint two fungible tokens under it, then burns one of them in a second transaction while the other survives. Asset names and quantities are checked with assert() before the wallet builds anything, remove them to explore different outcomes and balance states.

Try it online:​

Source code:​

Dapp code was autogenerated by Playground IDE in GameChanger Wallet

GCScript code (dapp connection):​

{
"type": "script",
"returnURLPattern": "http://localhost:3000/demo/api/dapp",
"title": "Native asset minter and burner",
"description": "Creates a native script and uses it as policy to mint two fungible tokens under it, then burns one of them in a second transaction while the other survives. Asset names and quantities are checked with assert() before the wallet builds anything, remove them to explore different outcomes and balance states.",
"exportAs": "MintAndBurn",
"return": {
"mode": "last"
},
"args": {
"asset-name": "WillDieToken",
"mint-quantity": "100",
"burn-quantity": "100",
"survivor-asset-name": "WillNotDieToken",
"survivor-quantity": "1"
},
"run": {
"argumentGuards": {
"type": "macro",
"run": {
"asset-names": "{assert(and(not(isEmptyString(get('args.asset-name'))),not(isEmptyString(get('args.survivor-asset-name'))),neq(get('args.asset-name'),get('args.survivor-asset-name'))),'asset names must be non-empty and differ',get('args'))}",
"quantities": "{assert(and(cmpBigNum('gt',get('args.mint-quantity'),'0'),cmpBigNum('gt',get('args.survivor-quantity'),'0'),cmpBigNum('gt',get('args.burn-quantity'),'0'),cmpBigNum('lte',get('args.burn-quantity'),get('args.mint-quantity'))),'quantities must be positive and burn must not exceed mint',get('args'))}"
}
},
"dependencies": {
"type": "script",
"run": {
"address": {
"type": "getCurrentAddress"
},
"addressInfo": {
"type": "macro",
"run": "{getAddressInfo(get('cache.dependencies.address'))}"
},
"issuerGuards": {
"type": "macro",
"run": {
"current-address-must-have-a-payment-key-hash": "{ assert( and(isType('string',get('cache.dependencies.addressInfo.paymentKeyHash')),not(isEmptyString(get('cache.dependencies.addressInfo.paymentKeyHash')))) ,'the connected address has no payment key hash: this example needs a key-based address to derive the minting policy from, not a script address' , get('cache.dependencies.addressInfo') ) }"
}
},
"mintingPolicy": {
"type": "nativeScript",
"script": {
"pubKeyHashHex": "{get('cache.dependencies.addressInfo.paymentKeyHash')}"
}
}
}
},
"buildMint": {
"type": "buildTx",
"name": "built-mint",
"title": "{join(' ',getArray('Mint',get('args.mint-quantity'),get('args.asset-name'),'and',get('args.survivor-quantity'),get('args.survivor-asset-name')))}",
"tx": {
"mints": [
{
"policyId": "{get('cache.dependencies.mintingPolicy.scriptHashHex')}",
"assets": [
{
"assetName": "{get('args.asset-name')}",
"quantity": "{get('args.mint-quantity')}"
},
{
"assetName": "{get('args.survivor-asset-name')}",
"quantity": "{get('args.survivor-quantity')}"
}
]
}
],
"witnesses": {
"nativeScripts": {
"mintingPolicyScript": "{get('cache.dependencies.mintingPolicy.scriptHex')}"
}
}
}
},
"signMint": {
"type": "signTxs",
"namePattern": "signed-mint",
"txs": [
"{get('cache.buildMint.txHex')}"
],
"detailedPermissions": false
},
"submitMint": {
"type": "submitTxs",
"namePattern": "submitted-mint",
"txs": "{get('cache.signMint')}"
},
"buildBurn": {
"type": "buildTx",
"name": "built-burn",
"title": "{join(' ',getArray('Burn',get('args.burn-quantity'),get('args.asset-name')))}",
"tx": {
"mints": [
{
"policyId": "{get('cache.dependencies.mintingPolicy.scriptHashHex')}",
"assets": [
{
"assetName": "{get('args.asset-name')}",
"quantity": "{join('',getArray('-',get('args.burn-quantity')))}"
}
]
}
],
"witnesses": {
"nativeScripts": {
"mintingPolicyScript": "{get('cache.dependencies.mintingPolicy.scriptHex')}"
}
}
}
},
"signBurn": {
"type": "signTxs",
"namePattern": "signed-burn",
"txs": [
"{get('cache.buildBurn.txHex')}"
],
"detailedPermissions": false
},
"submitBurn": {
"type": "submitTxs",
"namePattern": "submitted-burn",
"txs": "{get('cache.signBurn')}"
},
"finally": {
"type": "macro",
"run": {
"issuer": "{get('cache.dependencies.addressInfo.paymentKeyHash')}",
"policyId": "{get('cache.dependencies.mintingPolicy.scriptHashHex')}",
"policyScript": "{get('cache.dependencies.mintingPolicy.scriptHex')}",
"burnedAssetName": "{get('args.asset-name')}",
"survivingAssetName": "{get('args.survivor-asset-name')}",
"mintTxHash": "{get('cache.buildMint.txHash')}",
"burnTxHash": "{get('cache.buildBurn.txHash')}"
}
}
}
}

Run standalone QR dapp connection:​

You can use Playground IDE in GameChanger Wallet 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

Resources​

License​

MIT