-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathemulate_something.ts
65 lines (52 loc) · 1.28 KB
/
emulate_something.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
57
58
59
60
61
62
63
64
65
import {
Addresses,
Crypto,
Emulator,
fromText,
Lucid,
toUnit,
} from "../mod.ts";
const privateKey = Crypto.generatePrivateKey();
const address = Addresses.credentialToAddress(
{ Emulator: 0 },
Crypto.privateKeyToDetails(privateKey).credential,
);
const { payment } = Addresses.inspect(address);
const emulator = new Emulator([{ address, assets: { lovelace: 3000000000n } }]);
const lucid = new Lucid({
provider: emulator,
wallet: { PrivateKey: privateKey },
});
const mintingPolicy = lucid.newScript({
type: "All",
scripts: [
{
type: "Before",
slot: lucid.utils.unixTimeToSlots(emulator.now() + 60000),
},
{ type: "Sig", keyHash: payment!.hash },
],
});
const policyId = mintingPolicy.toHash();
async function mint(): Promise<string> {
const tx = await lucid.newTx()
.mint({
[toUnit(policyId, fromText("Wow"))]: 123n,
})
.validTo(emulator.now() + 30000)
.attachScript(mintingPolicy)
.commit();
const signedTx = await tx.sign().commit();
return signedTx.submit();
}
await mint();
emulator.awaitBlock(4);
console.log(await lucid.wallet.getUtxos());
// This should fail
try {
await mint();
} catch (_e) {
console.error(
"Error: Second transaction failed because upper bound exceeded in mint script.",
);
}