
# Cardano Example Dapp

## **Batch Airdrop with Receipt**

Airdrops an existing native asset to five recipients in a single transaction and stamps a CIP-20 receipt on-chain: a SHA-256 digest of the canonical recipient manifest. Anyone can later recompute the digest from the published list and prove the drop was not altered, without trusting the sender. Minimum ADA per output is auto-computed by buildTx, and the change optimizer is left enabled to keep the UTXO set healthy.


## Try it online: 

-  Visit [HTML+JS Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Batch%20Airdrop%20with%20Receipt.html)
-  Visit [HTML+React Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Batch%20Airdrop%20with%20Receipt_react.html)
-  Visit [Native HTML dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Batch%20Airdrop%20with%20Receipt_nolib.html)
-  Run [Standalone URL dapp connection](https://wallet.gamechanger.finance/api/2/run/1-H4sIAAAAAAAAA81YbW-jOhb-K1a-0EohQwiQpqv90Lujqxnt3tm5dzrSSqvVlYMNuAUDtkkg3f73PTaQQpo0yo4qTVWpBR8_55Xz9jRRTKV0cjv5BaswQXdMEJEXaMtUgv6gIWWFmkwnhMpQwL8s50DaEUmEOaI1k4rxGHGs2IYiLCVVSOUo0k-ChqxglCuJGEcYSaBMKVICc4lDDQcYBEmFMw2H_vb5q-06-ppmjHJuhwlm_BaOvn26s10_QITFVMJRhFRCUYh5zlmI0xdWKMOcRUAzQ3e8ybkhQilWVGiiPCsqRc3lDioSeWaei2qdMplQguCPMpIVIt90xMYsWCKew1EKaJRMjZ3yChQWVWsGTSopJ1TM0G-Ms6zK0N3HO1QAdyAE3oiBppXK7U4UgtYNWlcsJff11DA1iiWYxxTlYPOM7eAy3EpppBDleJ3CJTDxI6WFIf5-_69_Im33hIJkSTMDl6mm0G5t_QbPtC5yoe5k7-rOiXAiqKoE-PVpkuVE30mxVJPn6QSLWOrXxqd2kacsbGxGgIJ4q7m78MjN2nPWwQKHFK8dsly4qzAg6_l8Hi4COF5RhyzCYB4EIfzOF2vg1oJxnGlOv-JH-v3bR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3fOk5lnHI78vvIT6fQ-0kTtY4fI7TBYgLwepib3dO5uRuxTGqGDKzTMyZ4nJhpeXVogP1kBq6y4IK1T8vHfoapGveT_HB6l9N2xgWg0T30Bt8uRfcGaVVI8Ibaeg9gd_l3oEevxuArm3nWe2cCozzdbwgQYcToasZvmOrTdm3RfvTjgtQlgk5REx77GhoLqtcLtoKh3YZhPR-pGmZF9y1bsQLU01E2tZyh76YWyJaYrULeu-oWmTuoV0vvBTRH67WnjrK4uJYOM1hXTY21BlHcLS8Athvr9QtlH6wZ_o9F06_jHdIU6W3OYCBpX2yoYBHTW5H9wqjPI7P9egNmna9YgZP6gv86pvqZyLo2Hq61hu3KxrQOwjRVL33tcZAjrcFzv_WAW__uP_LPZA9x_Iva3_rS2vQVbZv2NNlggfF0rlyAB_-jc7V7iTLuT6SMe0SZxSXKLH4iZRZHlPEuUcb7iZTxjijjX6KM_xMp4x8qo_ehVc1ShkXzESusFQuWxlmZjE33p8R9_htVUDgV_qbEsHL1fY1pBZ41mGQxH-RQ_Xhfyy6HvqQq_Z6Sw1xKgAtLKflKRcakhFQIdopwKqlOXNpmI1ObBD1T9Sdaa220Z2S1ztiwV2tfHBXBnKjXUhhOI0ZaWqvtdiLGoZ6ebHGfXubfY1Fh5r42DeuN0wHRXh84asn6in5A2BXtIcVH05Z9Mw3bAXXfse0L_J0Omt8PI-VoXW3d-j-rw7YiTxkAAA)

## Source code:

- dapp connection code: [GCScript DSL](Batch%20Airdrop%20with%20Receipt.gcscript)
- frontend (using @gamechanger-finance/gc): [HTML+JS dapp](Batch%20Airdrop%20with%20Receipt.html)
- frontend (using @gamechanger-finance/gc): [HTML+React dapp](Batch%20Airdrop%20with%20Receipt_react.html)
- frontend (without official library): [Native HTML dapp](Batch%20Airdrop%20with%20Receipt_nolib.html)

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

## GCScript code (dapp connection):
```json
{
  "title": "Batch Airdrop with Receipt",
  "description": "Airdrops an existing native asset to five recipients in a single transaction and stamps a CIP-20 receipt on-chain: a SHA-256 digest of the canonical recipient manifest. Anyone can later recompute the digest from the published list and prove the drop was not altered, without trusting the sender. Minimum ADA per output is auto-computed by buildTx, and the change optimizer is left enabled to keep the UTXO set healthy.",
  "type": "script",
  "exportAs": "BatchAirdrop",
  "return": {
    "mode": "last"
  },
  "args": {
    "asset-policy-id": "d491234d8b40b63aceab0d7329c6db111c3634d9e0d3c6166c66c13b",
    "asset-name": "FakeUSD",
    "recipient-1-quantity": "10",
    "recipient-2-quantity": "25",
    "recipient-3-quantity": "5",
    "recipient-4-quantity": "40",
    "recipient-5-quantity": "20",
    "cardano-mainnet": {
      "return-URL": "https://cardanoscan.io/transaction/{txHash}",
      "recipient-1-address": "addr1q9faamq9k6557gve35amtdqph99h9q2txhz07chaxg6uwwgd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqczuqwr",
      "recipient-2-address": "addr1q98f06pcrsn8x03uw0vlejw684fcu02waffvfscdsz0djgqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yq2vsyn7",
      "recipient-3-address": "addr1q9cyzfctymllue5gx93mxnrymlzzxejkzgsrkgwq7upje4gd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqpnzcra",
      "recipient-4-address": "addr1q9zlzmrvdrlt8f90va74qa4req68shy5kc54s8np4p6a2eqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqhq5g2r",
      "recipient-5-address": "addr1qyygq384vhtcys27wedeh7r6jd0arwefvfxt6ggwjld0mjqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqa24x5g"
    },
    "cardano-preprod": {
      "return-URL": "https://preprod.cardanoscan.io/transaction/{txHash}",
      "recipient-1-address": "addr_test1qpfaamq9k6557gve35amtdqph99h9q2txhz07chaxg6uwwgd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqm5pqzu",
      "recipient-2-address": "addr_test1qp8f06pcrsn8x03uw0vlejw684fcu02waffvfscdsz0djgqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqf6dylp",
      "recipient-3-address": "addr_test1qpcyzfctymllue5gx93mxnrymlzzxejkzgsrkgwq7upje4gd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yqz9lc0z",
      "recipient-4-address": "addr_test1qpzlzmrvdrlt8f90va74qa4req68shy5kc54s8np4p6a2eqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yq5kfgxu",
      "recipient-5-address": "addr_test1qqygq384vhtcys27wedeh7r6jd0arwefvfxt6ggwjld0mjqd6j6v0fc04n5ehg292yxvs292vesrqqmxqfnp7yuwn7yq7ugxch"
    }
  },
  "run": {
    "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'))) }"
    },
    "guards_1": {
      "type": "macro",
      "run": {
        "network-must-be-supported": "{ assert( not(isType('null',get('cache.network')))        ,'this dapp has no addresses configured for the connected network'  , get('cache.networkKey') ) }",
        "audit-trail": "{ console('info',get('cache.network')) }"
      }
    },
    "lines": {
      "type": "macro",
      "run": "{getArray(join('=',getArray(get('cache.network.recipient-1-address'),get('args.recipient-1-quantity'))),join('=',getArray(get('cache.network.recipient-2-address'),get('args.recipient-2-quantity'))),join('=',getArray(get('cache.network.recipient-3-address'),get('args.recipient-3-quantity'))),join('=',getArray(get('cache.network.recipient-4-address'),get('args.recipient-4-quantity'))),join('=',getArray(get('cache.network.recipient-5-address'),get('args.recipient-5-quantity'))))}"
    },
    "canonical": {
      "type": "macro",
      "run": "{join(';',get('cache.lines'))}"
    },
    "digest": {
      "type": "macro",
      "run": "{sha256(get('cache.canonical'))}"
    },
    "totalQuantity": {
      "type": "macro",
      "run": "{addBigNum(get('args.recipient-1-quantity'),get('args.recipient-2-quantity'),get('args.recipient-3-quantity'),get('args.recipient-4-quantity'),get('args.recipient-5-quantity'))}"
    },
    "receipt": {
      "type": "macro",
      "run": "{join(' | ',getArray('Batch airdrop receipt',join(' ',getArray('asset:',get('args.asset-name'))),join(' ',getArray('recipients:','5')),join(' ',getArray('total:',get('cache.totalQuantity'))),join(' ',getArray('manifest sha256:',get('cache.digest')))))}"
    },
    "guards_2": {
      "type": "macro",
      "run": {
        "policy-must-not-be-ada": "{ assert( neq(get('args.asset-policy-id'),'ada')                            ,'this dapp airdrops native assets, not ada'            , get('args.asset-policy-id') ) }",
        "manifest-must-have-five-lines": "{ assert( eq(get('cache.lines.4'),join('=',getArray(get('cache.network.recipient-5-address'),get('args.recipient-5-quantity')))) ,'the manifest did not build all five lines' , get('cache.lines') ) }",
        "total-must-be-greater-than-zero": "{ assert( cmpBigNum('gt' ,get('cache.totalQuantity'),'0')          ,'nothing to airdrop: total quantity is zero'           , get('cache.totalQuantity') ) }",
        "audit-trail": "{ console('info',get('cache.canonical')) }"
      }
    },
    "build": {
      "type": "buildTx",
      "name": "built-BatchAirdrop",
      "title": "Batch Airdrop with Receipt",
      "description": "Five recipients, one transaction, one verifiable on-chain receipt.",
      "returnURLPattern": "{get('cache.network.return-URL')}",
      "tx": {
        "outputs": {
          "r1": {
            "address": "{get('cache.network.recipient-1-address')}",
            "assets": [
              {
                "policyId": "{get('args.asset-policy-id')}",
                "assetName": "{get('args.asset-name')}",
                "quantity": "{get('args.recipient-1-quantity')}"
              }
            ]
          },
          "r2": {
            "address": "{get('cache.network.recipient-2-address')}",
            "assets": [
              {
                "policyId": "{get('args.asset-policy-id')}",
                "assetName": "{get('args.asset-name')}",
                "quantity": "{get('args.recipient-2-quantity')}"
              }
            ]
          },
          "r3": {
            "address": "{get('cache.network.recipient-3-address')}",
            "assets": [
              {
                "policyId": "{get('args.asset-policy-id')}",
                "assetName": "{get('args.asset-name')}",
                "quantity": "{get('args.recipient-3-quantity')}"
              }
            ]
          },
          "r4": {
            "address": "{get('cache.network.recipient-4-address')}",
            "assets": [
              {
                "policyId": "{get('args.asset-policy-id')}",
                "assetName": "{get('args.asset-name')}",
                "quantity": "{get('args.recipient-4-quantity')}"
              }
            ]
          },
          "r5": {
            "address": "{get('cache.network.recipient-5-address')}",
            "assets": [
              {
                "policyId": "{get('args.asset-policy-id')}",
                "assetName": "{get('args.asset-name')}",
                "quantity": "{get('args.recipient-5-quantity')}"
              }
            ]
          }
        },
        "auxiliaryData": {
          "674": {
            "msg": "{strToMetadataStr(get('cache.receipt'))}"
          }
        }
      }
    },
    "sign": {
      "type": "signTxs",
      "namePattern": "signed-BatchAirdrop",
      "detailedPermissions": false,
      "txs": [
        "{get('cache.build.txHex')}"
      ]
    },
    "submit": {
      "type": "submitTxs",
      "namePattern": "submitted-BatchAirdrop",
      "txs": "{get('cache.sign')}"
    },
    "finally": {
      "type": "macro",
      "run": {
        "network": "{get('cache.networkKey')}",
        "txHash": "{get('cache.build.txHash')}",
        "manifest": "{get('cache.lines')}",
        "manifestDigestSha256": "{get('cache.digest')}",
        "totalAssetQuantity": "{get('cache.totalQuantity')}"
      }
    }
  }
}
```

## 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](Batch%20Airdrop%20with%20Receipt.png)](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Batch%20Airdrop%20with%20Receipt.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 
    
