
# Cardano Example Dapp

## **Runtime Assertions**

This example demonstrates how custom runtime assertions can be implemented. Modify the arguments to trigger errors. Explore the Console in Live Debugger for extra information


## Try it online: 

-  Visit [HTML+JS Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Runtime%20Assertions.html)
-  Visit [HTML+React Dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Runtime%20Assertions_react.html)
-  Visit [Native HTML dapp](https://gamechangerfinance.github.io/gamechanger.wallet/examples/Runtime%20Assertions_nolib.html)
-  Run [Standalone URL dapp connection](https://wallet.gamechanger.finance/api/2/run/1-H4sIAAAAAAAAA52UTW_bMAyG_wqhix0gX-jQS27px60bhq679SLbjK3NkgyJ3hIE-e8jHS8fjbOt8yGIxJcvH0q0t4oM1agW6rl1ZCzCMkYMZLyLaqwKjHkwjSxZ8lKZCLjWtqkRCrSsoaAJI1T-J-RtJG8h9D764AO5dpAhGMmz6AiLKXz0hVltgCpWhrKV7QjkgYIpSwyAIfgQp_C4bmofsBPes5nn0sbBk_mB8IBZ24lXnhPWzMIh_m91BzxWtGmktX0PvMZ14wMtI-8d23zgRjgWkNrgvj4_fdZEGKTfiqhZzGa1z3Vd-UiLD_P5fCaNz3RjZoVuGk5kfDbcKqetFPvmKweFR4mUvHFzO1aZdt-xUIuVriPKstYuF_HNrdpx6daJwVJ-3iLv3dW2REoTWSSjnTqk3L0_5f79KfurjCeJVufBHwXS-sTy_U8ynPBMGFeKWz8DKYCJL5yYJvtYMj7UmUpqMhrB4DNOXjvvVwXiLkOkofe40MIJPLChNNCf9H-y9dnDeMLWCwbwIM1M6Vo7Sq6y8XQcuFiZYRjm2sdOuTjz6pF1XCw4Y-otLrXDZybDekDLPL9y2g2z9cHzQ5P0P52ZxM_wfrv8ne04aM53dGgb2pyzcSQ18VECX7q7SC-m7Rrb6ayxjdB1Bd6e3D_NWhmQv41hQpV2k-5TcEqZ2-bOlJ9amyYlDQ4dDN348NT1pUBKQX_9yRDl7vD8ApwZl1P5BQAA)

## Source code:

- dapp connection code: [GCScript DSL](Runtime%20Assertions.gcscript)
- frontend (using @gamechanger-finance/gc): [HTML+JS dapp](Runtime%20Assertions.html)
- frontend (using @gamechanger-finance/gc): [HTML+React dapp](Runtime%20Assertions_react.html)
- frontend (without official library): [Native HTML dapp](Runtime%20Assertions_nolib.html)

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

## GCScript code (dapp connection):
```json
{
  "title": "Runtime Assertions",
  "description": "This example demonstrates how custom runtime assertions can be implemented. Modify the arguments to trigger errors. Explore the Console in Live Debugger for extra information",
  "type": "script",
  "exportAs": "AssertionsDemo",
  "returnURLPattern": "http://localhost:3000/demo/api/dapp",
  "args": {
    "name": "john doe",
    "age": 25,
    "banked": false,
    "balance": "25"
  },
  "run": {
    "A": {
      "type": "script",
      "args": "{get('args')}",
      "run": {
        "B": {
          "type": "script",
          "args": "{get('args')}",
          "run": {
            "C": {
              "type": "script",
              "args": "{get('args')}",
              "run": {
                "asserts": {
                  "type": "macro",
                  "run": {
                    "name-must-be-string": "{ assert(  isType('string',get('args.name'))                      ,'\"name\" must be a string'                , get('args') )  }",
                    "balance-must-be-string": "{ assert(  isType('string',get('args.balance'))                   ,'\"balance\" must be a string (bignum)'    , get('args') )  }",
                    "age-must-be-number": "{ assert(  isType('number',get('args.age'))                       ,'\"age\" must be a number'                 , get('args') )  }",
                    "banked-must-be-boolean": "{ assert(  isType('boolean',get('args.banked'))                   ,'\"banked\" must be a boolean'             , get('args') )  }",
                    "name-must-not-be-empty": "{ assert(  not(isEmptyString(get('args.name')))                   ,'\"name\" must not be empty'               , get('args') )  }",
                    "balance-must-be-greater-than-age": "{ assert(  cmpBigNum('gt',get('args.balance') ,get('args.age'))   ,'\"balance\" must be greater than \"age\"' , get('args') )  }"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```

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