Skip to main content

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:​

Source code:​

Dapp code was autogenerated by Playground IDE in GameChanger Wallet

GCScript code (dapp connection):​

{
"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 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