Cardano Example Dapp
Helios Timelock
Builds an Helios Smart Contract on the fly. First transaction will lock coins setting main staking key as owner, second one will be able to unlock it only after some time and using main spending key. Burner/Gift wallets not recommended. Timelock not exactly tested.
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):
{
"title": "Helios Timelock",
"description": "Builds an Helios Smart Contract on the fly. First transaction will lock coins setting main staking key as owner, second one will be able to unlock it only after some time and using main spending key. Burner/Gift wallets not recommended. Timelock not exactly tested.",
"type": "script",
"require": {
"not": {
"walletTypeIn": [
"burner",
"gift"
]
}
},
"returnURLPattern": "http://localhost:3000/demo/api/dapp",
"run": {
"dependencies": {
"type": "script",
"run": {
"stakeCredential": {
"type": "data",
"value": "ad03a4ae45b21f50fde67956365cff94db41bc08a2c2862403d8a234"
},
"beneficiary": {
"type": "getSpendingPublicKey"
},
"owner": {
"type": "getStakingPublicKey"
},
"currentSlotNumber": {
"type": "getCurrentSlot"
},
"coin": {
"type": "data",
"value": "5000000"
},
"datum": {
"type": "plutusData",
"data": {
"fromJSON": {
"schema": 1,
"obj": {
"list": [
{
"int": 1234
},
{
"bytes": "{get('cache.dependencies.owner.pubKeyHashHex')}"
},
{
"bytes": "{get('cache.dependencies.beneficiary.pubKeyHashHex')}"
}
]
}
}
}
},
"smartContract": {
"type": "plutusScript",
"script": {
"heliosCode": "{replaceAll(hexToStr('0a7370656e64696e672074696d655f6c6f636b0a0a73747275637420446174756d207b0a202020206c6f636b556e74696c3a20202054696d650a202020206f776e65723a202020202020205075624b657948617368202f2f20746865206f776e65722063616e20616c7761797320756e6c6f636b20746865206173736574730a2020202062656e65666963696172793a205075624b657948617368202f2f2062656e65666963696172792063616e206f6e6c7920756e6c6f636b207468652061737365747320616674657220276c6f636b556e74696c270a7d0a0a66756e63206d61696e28646174756d3a20446174756d2c205f2c206374783a20536372697074436f6e7465787429202d3e20426f6f6c207b0a2020202074783a205478203d206374782e74783b0a202020206e6f773a2054696d65203d2074782e74696d655f72616e67652e73746172743b0a0a2020202074782e69735f7369676e65645f627928646174756d2e6f776e657229207c7c20280a202020202020202074782e69735f7369676e65645f627928646174756d2e62656e6566696369617279292026260a20202020202020206e6f77203e20646174756d2e6c6f636b556e74696c0a20202020290a7d0a20202020202020200a636f6e7374204558414d504c455f444154554d203a446174756d203d20446174756d7b0a2020202054696d653a3a6e6577284578616d706c6554696d65292c0a202020205075624b6579486173683a3a6e657728233031323334353637383961626364663031323334353637383961626364663031323334353637383961626364663031323334353637383961292c0a202020205075624b6579486173683a3a6e657728236664636261393837363534333231306664636261393837363534333231306664636261393837363534333231306664636261393837363534290a7d0a0a'),'ExampleTime','1234')}",
"parameters": [
"EXAMPLE_DATUM"
],
"version": "0.15.2",
"simplify": false
}
},
"smartContractAddress": {
"type": "buildAddress",
"name": "smartContractAddress",
"addr": {
"spendScriptHashHex": "{get('cache.dependencies.smartContract.scriptHashHex')}",
"stakePubKeyHashHex": "{get('cache.dependencies.stakeCredential')}"
}
}
}
},
"buildLock": {
"type": "buildTx",
"name": "LockingTX",
"tx": {
"outputs": [
{
"address": "{get('cache.dependencies.smartContractAddress')}",
"datum": {
"datumHex": "{get('cache.dependencies.datum.dataHex')}"
},
"assets": [
{
"policyId": "ada",
"assetName": "ada",
"quantity": "{get('cache.dependencies.coin')}"
}
],
"idPattern": "lockedOutput"
}
],
"requiredSigners": {
"owner": "{get('cache.dependencies.owner.pubKeyHashHex')}"
}
}
},
"signLock": {
"type": "signTxs",
"namePattern": "signed-lock",
"txs": [
"{get('cache.buildLock.txHex')}"
],
"detailedPermissions": false
},
"submitLock": {
"type": "submitTxs",
"namePattern": "submitted-lock",
"txs": "{get('cache.signLock')}"
},
"wait": {
"type": "await",
"until": {
"beneficiaryTimeLock": {
"kind": "timer",
"unit": "seconds",
"value": 10
}
}
},
"buildUnlock": {
"type": "buildTx",
"name": "UnlockingTX",
"tx": {
"ttl": {
"from": "{get('cache.dependencies.currentSlotNumber')}"
},
"inputs": [
{
"txHash": "{get('cache.buildLock.txHash')}",
"index": "{get('cache.buildLock.indexMap.output.lockedOutput')}"
}
],
"requiredSigners": {
"beneficiary": "{get('cache.dependencies.beneficiary.pubKeyHashHex')}"
},
"witnesses": {
"plutus": {
"scripts": [
{
"scriptHex": "{get('cache.dependencies.smartContract.scriptHex')}",
"lang": "{get('cache.dependencies.smartContract.lang')}"
}
]
}
},
"options": {
"collateralCoinSelection": "LASLAD"
}
}
},
"signUnlock": {
"type": "signTxs",
"namePattern": "signed-unlock",
"txs": [
"{get('cache.buildUnlock.txHex')}"
],
"detailedPermissions": false
},
"submitUnlock": {
"type": "submitTxs",
"namePattern": "submitted-unlock",
"txs": "{get('cache.signUnlock')}"
},
"finally": {
"type": "script",
"exportAs": "LockAndRedeem",
"run": {
"locks": {
"type": "macro",
"run": {
"coin": "{get('cache.dependencies.coin')}",
"datumHex": "{get('cache.dependencies.datum.dataHex')}",
"datumHash": "{get('cache.dependencies.datum.dataHashHex')}"
}
},
"smartContract": {
"type": "macro",
"run": "{get('cache.dependencies.smartContract.scriptHex')}"
},
"smartContractHash": {
"type": "macro",
"run": "{get('cache.dependencies.smartContract.scriptHashHex')}"
},
"smartContractAddress": {
"type": "macro",
"run": "{get('cache.dependencies.smartContractAddress')}"
},
"lockTx": {
"type": "macro",
"run": "{get('cache.buildLock.txHash')}"
},
"unlockTx": {
"type": "macro",
"run": "{get('cache.buildUnlock.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
