Cardano Example Dapp
Stake Withdrawal
Withdraws staking rewards from the reward account of the current address. Cardano requires a withdrawal to move the entire reward balance, so the quantity must match the rewards available at build time. It is exposed as a flat argument, so an auto-generated dapp can drive it without touching the code, and it is checked with assert() before the wallet builds anything
Try it online:
- Visit HTML+JS Dapp
- Visit HTML+React Dapp
- Visit Native HTML dapp
- Run Run in Wallet…Open in IDE…
Source code:
- dapp connection code: GCScript DSL
- frontend (using @gamechanger-finance/gc): HTML+JS dapp
- frontend (using @gamechanger-finance/gc): HTML+React dapp
- frontend (without official library): Native HTML dapp
Dapp code was autogenerated by Playground IDE in GameChanger Wallet
GCScript code (dapp connection):
{
"type": "script",
"title": "Stake Withdrawal",
"description": "Withdraws staking rewards from the reward account of the current address. Cardano requires a withdrawal to move the entire reward balance, so the quantity must match the rewards available at build time. It is exposed as a flat argument, so an auto-generated dapp can drive it without touching the code, and it is checked with assert() before the wallet builds anything",
"exportAs": "SingleWithdraw",
"require": {
"not": {
"walletTypeIn": [
"burner",
"gift"
]
}
},
"returnURLPattern": "http://localhost:3000/demo/api/dapp",
"return": {
"mode": "last"
},
"args": {
"withdrawal-quantity": "1000000"
},
"run": {
"argumentGuards": {
"type": "macro",
"run": {
"withdrawal-quantity-must-be-a-string": "{ assert( isType('string',get('args.withdrawal-quantity')) ,'withdrawal-quantity must be a string' , get('args') ) }",
"withdrawal-quantity-must-not-be-empty": "{ assert( not(isEmptyString(get('args.withdrawal-quantity'))) ,'withdrawal-quantity must not be empty' , get('args') ) }",
"withdrawal-quantity-must-be-positive": "{ assert( cmpBigNum('gt',get('args.withdrawal-quantity'),'0') ,'withdrawal-quantity must be greater than zero, and must equal the whole reward balance available at build time' , get('args') ) }"
}
},
"dependencies": {
"type": "script",
"run": {
"currentAddress": {
"type": "getCurrentAddress"
},
"addressInfo": {
"type": "macro",
"run": "{getAddressInfo(get('cache.dependencies.currentAddress'))}"
}
}
},
"txs": {
"type": "script",
"args": "{get('args')}",
"run": {
"buildWithdraw": {
"type": "buildTx",
"title": "{join(' ',getArray('Stake Withdrawal of',get('args.withdrawal-quantity'),'lovelace'))}",
"tx": {
"withdrawals": {
"rewards": {
"address": "{get('cache.dependencies.addressInfo.rewardAddress')}",
"quantity": "{get('args.withdrawal-quantity')}"
}
},
"options": {
"autoProvision": {
"workspaceNativeScript": true
},
"autoOptionalSigners": {
"nativeScript": true
}
}
}
},
"signWithdraw": {
"type": "signTxs",
"detailedPermissions": false,
"txs": [
"{get('cache.txs.buildWithdraw.txHex')}"
]
},
"submitWithdraw": {
"type": "submitTxs",
"txs": "{get('cache.txs.signWithdraw')}"
}
}
},
"finally": {
"type": "macro",
"run": {
"address": "{get('cache.dependencies.currentAddress')}",
"rewardAddress": "{get('cache.dependencies.addressInfo.rewardAddress')}",
"withdrawnQuantity": "{get('args.withdrawal-quantity')}",
"txHash": "{get('cache.txs.buildWithdraw.txHash')}"
}
}
}
}
Run standalone QR dapp connection:
You can use Playground IDE in GameChanger Wallet in QR URL Transport mode to capture results
Resources
- How to connect?
- Docs and examples on Github
- GCScript documentation
- Playground IDE in GameChanger Wallet
- Tutorials on Youtube
- Support on Discord
- News on Twitter
- Website
License
MIT
