spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
336 stars 133 forks source link

Error: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (OutsideValidityIntervalUTxO (ValidityInterval {invalidBefore = SNothing, invalidHereafter = SJust (SlotNo 34773223)}) (SlotNo 34773230))))])" #208

Open riteshbehera857 opened 12 months ago

riteshbehera857 commented 12 months ago

`import { BurnType, MintMetadataType, MintType } from "../../types"; import { Label, NFTMetadataDetails, Unit, fromText } from "lucid-cardano"; import { lucid, mintingPolicy, policyId } from ".";

import Burn from "../models/burnModel"; import Mint from "../models/mintModel"; import MintMetadata from "../models/mintMetadata.model"; import { PointsCreatedPublisher } from "../events/publishers/points-created-publisher"; import { Types } from "mongoose"; import { burnNFT } from "./burnNFT"; import { mintNFT } from "./mintNFT"; import { natsClient } from "../nats-client"; import { secretSeed } from "../services/seed";

class NftService {

private mintModel = Mint; private burnModel = Burn; private mintMetadataModel = MintMetadata; private address: string = ""; private MINT_UNIT_VALUE: bigint = 0n; private mintTxHash: string = ""; private burnTxHash: string = ""; private BURN_UNIT_VALUE: bigint = 0n;

public async getAddress(): Promise { this.address = await lucid .selectWalletFromSeed(secretSeed) .wallet.address(); }

public async mintNft(tokenName?: string): Promise { const { txHash, UNIT_VALUE } = await mintNFT(tokenName);

this.mintTxHash = txHash;
this.MINT_UNIT_VALUE = UNIT_VALUE;

}

public async burnNft(tokenName?: string): Promise { const { txHash, UNIT_VALUE } = await burnNFT(tokenName);

this.burnTxHash = txHash;
this.BURN_UNIT_VALUE = UNIT_VALUE;

}

public async mintNFTMetadata(data: { name: any; email: string; description: string; label: Label; tokenName: string; managerId: Types.ObjectId; }): Promise<{ txHash: string; UNIT_VALUE: bigint; metadata: NFTMetadataDetails; }> { const unit: Unit = policyId + fromText(data.tokenName); const UNIT_VALUE = 1n;

const metadata: NFTMetadataDetails = {
  email: data.email,
  description: data.description,
  label: "ERC20",
  policyId: policyId,
  tokenName: data.tokenName,
  managerId: data.managerId,
  name: data.name,
  image: "",
};

const res = await this.mintMetadataModel.create({
  policyId: policyId,
  metadata: {
    email: data.email,
    description: data.description,
    label: data.label,
    policyId: policyId,
    tokenName: data.tokenName,
    managerId: data.managerId,
    image: "",
    unit: UNIT_VALUE.toString(),
  },
});

// const totalUnits = await this.getPoints(data.email);

// await new PointsCreatedPublisher(natsClient.client).publish({
//   email: data.email,
//   points: totalUnits,
// });

const tx = await lucid
  .newTx()
  .mintAssets({ [unit]: UNIT_VALUE })
  .validTo(Date.now() + 100)
  .attachMintingPolicy(mintingPolicy)
  .attachMetadata(data.label, res.metadata)
  .complete();

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

const txHash = await signedTx.submit();

return { txHash, UNIT_VALUE, metadata };

} }

export const nftService = new NftService(); import { Listener, ReservationCreatedEvent } from "@c10lms/common";

import { PointsCreatedPublisher } from "../publishers/points-created-publisher"; import { Subjects } from "@c10lms/common/build/events/subjects"; import { natsClient } from "../../nats-client"; import { nftService } from "../../services/nft.db"; import { userService } from "../../services/user.db";

export class ReservationCreatedListener extends Listener { subject: Subjects.ReservationCreated = Subjects.ReservationCreated; queueGroupName = "wallet-service";

async onMessage(data: ReservationCreatedEvent["data"], msg: any) { const { user: { email, firstname, lastname }, managerId, } = data;

const { txHash, UNIT_VALUE, metadata } = await nftService.mintNFTMetadata({
  email,
  description: "This is a token for " + firstname + lastname,
  label: 20,
  tokenName: firstname + lastname,
  name: firstname,
  managerId: data.managerId,
});

const totalUnits = await nftService.getPoints(email, managerId);

await new PointsCreatedPublisher(natsClient.client).publish({
  email: email,
  points: totalUnits,
  managerId: data.managerId,
});

console.log({ txHash, UNIT_VALUE, metadata });

const user = await userService.getUserByEmail(email);
// await reservationService.createReservation(data);
msg.ack();

} }

`

The Complete Error is this: file:///app/node_modules/lucid-cardano/esm/src/provider/blockfrost.js:177 [wallet] throw new Error(result.message); [wallet] ^ [wallet] Error: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (OutsideValidityIntervalUTxO (ValidityInterval {invalidBefore = SNothing, invalidHereafter = SJust (SlotNo 34773223)}) (SlotNo 34773230))))])" [wallet] at Blockfrost.submitTx (file:///app/node_modules/lucid-cardano/esm/src/provider/blockfrost.js:177:23) [wallet] at processTicksAndRejections (node:internal/process/task_queues:95:5) [wallet] at async Object.submitTx (file:///app/node_modules/lucid-cardano/esm/src/lucid/lucid.js:371:24) [wallet] at async TxSigned.submit (file:///app/node_modules/lucid-cardano/esm/src/lucid/tx_signed.js:21:16) [wallet] at async NftService.mintNFTMetadata (file:///app/src/services/nft.db.ts:132:20) [wallet] at async ReservationCreatedListener.onMessage (file:///app/src/events/listeners/reservation-created-listener.ts:19:46)

AlexDochioiu commented 11 months ago

.validTo(Date.now() + 100) Your problem is here. Transaction is valid for 100 milliseconds from the moment it's build. This is way too short for it to have a chance and be submitted/registered on chain.