aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
478 stars 94 forks source link

Hello world demo failed - Cannot convert undefined to a BigInt #300

Closed gaganyaan2 closed 1 year ago

gaganyaan2 commented 1 year ago

What Git revision are you using?

aiken v0.0.28 git 2.38.1

What operating system are you using, and which version?

Describe what the problem is?

cannot submit the hello_world-lock.ts transaction as described here https://aiken-lang.org/getting-started/hello-world#setup

I'm getting this error.

[home@fedora hello_world]$ deno run --allow-net --allow-read 2.lock.ts
error: Uncaught (in promise) TypeError: Cannot convert undefined to a BigInt
      keyDeposit: BigInt(result.key_deposit),
                  ^
    at BigInt (<anonymous>)
    at Blockfrost.getProtocolParameters (https://deno.land/x/lucid@0.8.3/src/provider/blockfrost.ts:38:19)
    at async Function.new (https://deno.land/x/lucid@0.8.3/src/lucid/lucid.ts:52:34)
    at async file:///home/alok/cardano-lucid/hello_world/2.lock.ts:15:15

2.lock.ts

import {
  Blockfrost,
  C,
  Constr,
  Data,
  Lucid,
  SpendingValidator,
  TxHash,
  fromHex,
  toHex,
  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",
    "TOKEN"
  ),
  "Preview",
);

lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk"));

const validator = await readValidator("./assets/hello_world/spend/script.cbor");

  async function readValidator(filepath: String): Promise<SpendingValidator> {
    return {
    type: "PlutusV2",
    script: toHex(cbor.encode(fromHex(await Deno.readTextFile(filepath)))),
    };
  }

  const publicKeyHash = lucid.utils
  .getAddressDetails(await lucid.wallet.address())
  .paymentCredential
  .hash;

  const datum = Data.to(new Constr(0, [publicKeyHash]));

  const txLock = await lock(10000000, { into: validator, owner: datum });

  await lucid.awaitTx(txLock);

  console.log(`10 ADA locked into the contract
    Tx ID: ${txLock}
    Datum: ${datum}
  `);

async function lock(lovelace, { into, owner }): Promise<TxHash>{
  const contractAddress = lucid.utils.validatorToAddress(into);

  const tx = await lucid
    .newTx()
    .payToContract(contractAddress, { inline: owner }, { lovelace })
    .complete();

  const signedTx = await tx
    .sign()
    .complete();

  return signedTx.submit();
}

What should be the expected behavior?

the transaction should be completed.

gaganyaan2 commented 1 year ago

I think it will be related to Lucid https://github.com/spacebudz/lucid/issues/144 . hence closing this.