Small tweaks on the hello_world examples.
This commit is contained in:
parent
4ea50ca9ab
commit
7257c2d89e
|
@ -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 lucid = await Lucid.new(undefined, "Preview");
|
||||||
|
|
||||||
const privateKey = lucid.utils.generatePrivateKey();
|
const privateKey = lucid
|
||||||
|
.utils
|
||||||
|
.generatePrivateKey();
|
||||||
await Deno.writeTextFile("key.sk", privateKey);
|
await Deno.writeTextFile("key.sk", privateKey);
|
||||||
|
|
||||||
const address = await lucid.selectWalletFromPrivateKey(privateKey).wallet
|
const address = await lucid
|
||||||
|
.selectWalletFromPrivateKey(privateKey)
|
||||||
|
.wallet
|
||||||
.address();
|
.address();
|
||||||
await Deno.writeTextFile("key.addr", address);
|
await Deno.writeTextFile("key.addr", address);
|
||||||
|
|
|
@ -25,8 +25,10 @@ const validator = await readValidator();
|
||||||
// --- Supporting functions
|
// --- Supporting functions
|
||||||
|
|
||||||
async function readValidator(): Promise<SpendingValidator> {
|
async function readValidator(): Promise<SpendingValidator> {
|
||||||
const validator =
|
const validator = JSON
|
||||||
JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
|
.parse(await Deno.readTextFile("plutus.json"))
|
||||||
|
.validators[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "PlutusV2",
|
type: "PlutusV2",
|
||||||
script: toHex(cbor.encode(fromHex(validator.compiledCode))),
|
script: toHex(cbor.encode(fromHex(validator.compiledCode))),
|
||||||
|
@ -40,12 +42,12 @@ const publicKeyHash = lucid.utils
|
||||||
|
|
||||||
const datum = Data.to(new Constr(0, [publicKeyHash]));
|
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);
|
await lucid.awaitTx(txHash);
|
||||||
|
|
||||||
console.log(`1 ADA locked into the contract at:
|
console.log(`1 tADA locked into the contract at:
|
||||||
Tx Hash: ${txHash}
|
Tx ID: ${txHash}
|
||||||
Datum: ${datum}
|
Datum: ${datum}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,11 @@ const unlockTxHash = await unlock(utxo, {
|
||||||
using: redeemer,
|
using: redeemer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
await lucid.awaitTx(unlockTxHash);
|
await lucid.awaitTx(unlockTxHash);
|
||||||
|
|
||||||
console.log(`1 ADA unlocked from the contract
|
console.log(`1 tADA unlocked from the contract
|
||||||
Tx Hash: ${unlockTxHash}
|
Tx ID: ${unlockTxHash}
|
||||||
Redeemer: ${redeemer}
|
Redeemer: ${redeemer}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -64,8 +65,10 @@ async function unlock(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readValidator(): Promise<SpendingValidator> {
|
async function readValidator(): Promise<SpendingValidator> {
|
||||||
const validator =
|
const validator = JSON
|
||||||
JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
|
.parse(await Deno.readTextFile("plutus.json"))
|
||||||
|
.validators[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "PlutusV2",
|
type: "PlutusV2",
|
||||||
script: toHex(cbor.encode(fromHex(validator.compiledCode))),
|
script: toHex(cbor.encode(fromHex(validator.compiledCode))),
|
||||||
|
|
Loading…
Reference in New Issue