diff --git a/examples/hello_world/generate-credentials.ts b/examples/hello_world/generate-credentials.ts index ad297cd6..cd9ff01b 100644 --- a/examples/hello_world/generate-credentials.ts +++ b/examples/hello_world/generate-credentials.ts @@ -1,9 +1,10 @@ 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(); await Deno.writeTextFile("key.sk", privateKey); - -const address = await lucid.selectWalletFromPrivateKey(privateKey).wallet.address(); + +const address = await lucid.selectWalletFromPrivateKey(privateKey).wallet + .address(); await Deno.writeTextFile("key.addr", address); diff --git a/examples/hello_world/hello_world-lock.ts b/examples/hello_world/hello_world-lock.ts index 2cb1d00f..3e060248 100644 --- a/examples/hello_world/hello_world-lock.ts +++ b/examples/hello_world/hello_world-lock.ts @@ -2,18 +2,18 @@ import { Blockfrost, Constr, Data, + fromHex, Lucid, SpendingValidator, + toHex, TxHash, - fromHex, - toHex } from "https://deno.land/x/lucid@0.8.3/mod.ts"; import * as cbor from "https://deno.land/x/cbor@v1.4.1/index.js"; const lucid = await Lucid.new( new Blockfrost( "https://cardano-preview.blockfrost.io/api/v0", - Deno.env.get('BLOCKFROST_API_KEY'), + Deno.env.get("BLOCKFROST_API_KEY"), ), "Preview", ); @@ -25,7 +25,8 @@ const validator = await readValidator(); // --- Supporting functions async function readValidator(): Promise { - 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))), @@ -35,22 +36,25 @@ async function readValidator(): Promise { const publicKeyHash = lucid.utils .getAddressDetails(await lucid.wallet.address()) .paymentCredential - .hash; + ?.hash; -const datum = Data.to(new Constr(0, [ publicKeyHash ])); +const datum = Data.to(new Constr(0, [publicKeyHash])); -const txLock = await lock(1000000, { into: validator, owner: datum }); +const txHash = await lock(BigInt(1000000), { into: validator, owner: datum }); -await lucid.awaitTx(txLock); +await lucid.awaitTx(txHash); -console.log(`1 ADA locked into the contract - Tx ID: ${txLock} +console.log(`1 ADA locked into the contract at: + Tx Hash: ${txHash} Datum: ${datum} `); // --- Supporting functions -async function lock(lovelace, { into, owner }): Promise{ +async function lock( + lovelace: bigint, + { into, owner }: { into: SpendingValidator; owner: string }, +): Promise { const contractAddress = lucid.utils.validatorToAddress(into); const tx = await lucid diff --git a/examples/hello_world/hello_world-unlock.ts b/examples/hello_world/hello_world-unlock.ts index 646cfc12..37bb7289 100644 --- a/examples/hello_world/hello_world-unlock.ts +++ b/examples/hello_world/hello_world-unlock.ts @@ -1,20 +1,22 @@ import { - Blockfrost, - Constr, - Data, - Lucid, - SpendingValidator, - TxHash, - fromHex, - toHex, - utf8ToHex - } from "https://deno.land/x/lucid@0.8.3/mod.ts"; + Blockfrost, + Constr, + Data, + fromHex, + Lucid, + OutRef, + Redeemer, + SpendingValidator, + toHex, + TxHash, + utf8ToHex, +} from "https://deno.land/x/lucid@0.8.3/mod.ts"; import * as cbor from "https://deno.land/x/cbor@v1.4.1/index.js"; const lucid = await Lucid.new( new Blockfrost( "https://cardano-preview.blockfrost.io/api/v0", - Deno.env.get('BLOCKFROST_API_KEY'), + Deno.env.get("BLOCKFROST_API_KEY"), ), "Preview", ); @@ -23,22 +25,28 @@ lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk")); const validator = await readValidator(); -const utxo = { txHash: Deno.args[0], outputIndex: 0 }; +const lockOutRef: OutRef = { txHash: Deno.args[0], outputIndex: 0 }; -const redeemer = Data.to(new Constr(0, [ utf8ToHex("Hello, World!")]) ); +const redeemer = Data.to(new Constr(0, [utf8ToHex("Hello, World!")])); -const txUnlock = await unlock(utxo, { from: validator, using: redeemer }); +const unlockTxHash = await unlock(lockOutRef, { + from: validator, + using: redeemer, +}); -await lucid.awaitTx(txUnlock); +await lucid.awaitTx(unlockTxHash); -console.log(`1 ADA recovered from the contract - Tx ID: ${txUnlock} +console.log(`1 ADA unlocked from the contract + Tx Hash: ${unlockTxHash} Redeemer: ${redeemer} `); // --- Supporting functions -async function unlock(ref, { from, using }): Promise { +async function unlock( + ref: OutRef, + { from, using }: { from: SpendingValidator; using: Redeemer }, +): Promise { const [utxo] = await lucid.utxosByOutRef([ref]); const tx = await lucid @@ -56,7 +64,8 @@ async function unlock(ref, { from, using }): Promise { } async function readValidator(): Promise { - 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))),