Small tweaks on the hello_world examples.

This commit is contained in:
KtorZ 2023-03-08 09:47:08 +01:00
parent 4ea50ca9ab
commit 7257c2d89e
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 20 additions and 11 deletions

View File

@ -2,9 +2,13 @@ import { Lucid } from "https://deno.land/x/lucid@0.8.3/mod.ts";
const lucid = await Lucid.new(undefined, "Preview");
const privateKey = lucid.utils.generatePrivateKey();
const privateKey = lucid
.utils
.generatePrivateKey();
await Deno.writeTextFile("key.sk", privateKey);
const address = await lucid.selectWalletFromPrivateKey(privateKey).wallet
const address = await lucid
.selectWalletFromPrivateKey(privateKey)
.wallet
.address();
await Deno.writeTextFile("key.addr", address);

View File

@ -25,8 +25,10 @@ const validator = await readValidator();
// --- Supporting functions
async function readValidator(): Promise<SpendingValidator> {
const validator =
JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
const validator = JSON
.parse(await Deno.readTextFile("plutus.json"))
.validators[0];
return {
type: "PlutusV2",
script: toHex(cbor.encode(fromHex(validator.compiledCode))),
@ -40,12 +42,12 @@ const publicKeyHash = lucid.utils
const datum = Data.to(new Constr(0, [publicKeyHash]));
const txHash = await lock(BigInt(1000000), { into: validator, owner: datum });
const txHash = await lock(1000000n, { into: validator, owner: datum });
await lucid.awaitTx(txHash);
console.log(`1 ADA locked into the contract at:
Tx Hash: ${txHash}
console.log(`1 tADA locked into the contract at:
Tx ID: ${txHash}
Datum: ${datum}
`);

View File

@ -34,10 +34,11 @@ const unlockTxHash = await unlock(utxo, {
using: redeemer,
});
await lucid.awaitTx(unlockTxHash);
console.log(`1 ADA unlocked from the contract
Tx Hash: ${unlockTxHash}
console.log(`1 tADA unlocked from the contract
Tx ID: ${unlockTxHash}
Redeemer: ${redeemer}
`);
@ -64,8 +65,10 @@ async function unlock(
}
async function readValidator(): Promise<SpendingValidator> {
const validator =
JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
const validator = JSON
.parse(await Deno.readTextFile("plutus.json"))
.validators[0];
return {
type: "PlutusV2",
script: toHex(cbor.encode(fromHex(validator.compiledCode))),