-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplayer_template.ts
56 lines (45 loc) · 1.75 KB
/
player_template.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Data, fromText, Lucid } from "https://deno.land/x/[email protected]/mod.ts";
import { HelloRedeemer } from "./types.ts";
import {
awaitTxConfirms,
getFormattedTxDetails,
} from "../../common/offchain/utils.ts";
import { GameData, TestData } from "./task.ts";
export async function play(
lucid: Lucid,
gameData: GameData,
): Promise<TestData> {
/**
* The smart contracts are already deployed, see the [run.ts] file for more details.
* The [gameData] variable contains all the things you need to interact with the vulnerable smart contracts.
*/
// This is just a sanity check, so you do not have to change much here to pass the tests
// Check the validator code to find out how to unlock the locked ADA!
// The following code fails, read the validator carefully to find out why?
// Hint base64: TG9vayBhdCB0aGUgcmVkZWVtZXIu
// We find the contract UTxO where the ADA is locked
// We create the redeemer
// ================ YOUR CODE STARTS HERE
// We unlock the locked UTxO using the redeemer "Hello, World!".
console.log(`Building a transaction to unlock the locked script UTxO`);
const redeemer = Data.to({ msg: fromText("Hello, World!") }, HelloRedeemer);
const utxo = gameData.scriptUtxo;
const scriptValidator = gameData.scriptValidator;
const tx = await lucid
.newTx()
.collectFrom([utxo], redeemer)
.attachSpendingValidator(scriptValidator)
.complete();
const signedTx = await tx
.sign()
.complete();
const unlockTxHash = await signedTx.submit();
console.log(
`UTxO was successfuly unlocked ${
getFormattedTxDetails(unlockTxHash, lucid)
}`,
);
// We await the transaction confirmations.
await awaitTxConfirms(lucid, unlockTxHash);
// ================ YOUR CODE ENDS HERE
}