nikhils9 / cip68-nfts Goto Github PK
View Code? Open in Web Editor NEWA project to kickstart minting and updating CIP68 NFTs
License: GNU General Public License v3.0
A project to kickstart minting and updating CIP68 NFTs
License: GNU General Public License v3.0
Hi, I am trying to use your cip68 Aiken smart contract but I am getting the error:
Redeemer (Mint, 0): The provided Plutus code called 'error'.
ExBudget {
mem: 167311,
cpu: 69164532,
}
code
export const readValidator = (
blueprint: Blueprint,
title: string
): Validator => {
const validator = blueprint.validators.find((v) => v.title === title);
if (!validator) {
throw new Error('Gift Card validator not found');
}
return {
type: 'PlutusV2',
script: validator.compiledCode,
};
};
export const applyValidatorsParams = (
rawValidator: Validator,
params: Data[],
Lucid: Lucid
) => {
const script = applyParamsToScript(rawValidator.script, params);
const validator: Validator = {
type: 'PlutusV2',
// script: toHex(cbor.encode(fromHex(script))),
script: applyDoubleCborEncoding(script),
};
const policyID = Lucid.utils.validatorToScriptHash(validator);
const lockedAddress = Lucid.utils.validatorToAddress(validator);
return {
validator,
policyID,
lockedAddress,
};
};
When I change the script: applyDoubleCborEncoding(script),
to script: toHex(cbor.encode(fromHex(script))),
I get different error
{
"message": "Redeemer (Mint, 0): unexpected type tag at position 0: expected bytes (definite length)"
}
building transaction
export default async function handler(
req: NextApiRequestToken,
res: NextApiResponse
) {
const { meerkatAddress, metadata } = req.body;
console.log(meerkatAddress);
console.log(metadata);
const lucid = await Lucid.new(
new Blockfrost(
"https://cardano-preprod.blockfrost.io/api/v0/",
"preprod"
),
"Preprod"
);
// const privateKey = lucid.utils.generatePrivateKey();
// console.log(privateKey)
// const issuerAddress = await lucid
// .selectWalletFromPrivateKey(
// "ed25519_sk"
// )
// .wallet.address();
// console.log(issuerAddress);
const privateKey = C.PrivateKey.from_bytes(
fromHex(
"5820"
)
);
const issuerAddress = await lucid
.selectWalletFromPrivateKey(privateKey.to_bech32())
.wallet.address();
lucid.selectWalletFrom({ address: meerkatAddress });
const userUtxos = await lucid.utxosAt(meerkatAddress);
if (!userUtxos || !userUtxos.length) {
console.error(`No UTxO found at user address: ${meerkatAddress}`);
}
const publicKeyHash =
lucid.utils.getAddressDetails(issuerAddress).paymentCredential?.hash!;
const store = applyValidatorsParams(
readValidator(blueprint, "store.store"),
[publicKeyHash],
lucid
);
const minter = applyValidatorsParams(
readValidator(blueprint, "minter.mint"),
[publicKeyHash, store.policyID],
lucid
);
const selectedUtxo = getUtxoWithAssets(userUtxos, { lovelace: 5000000n });
console.log(store.lockedAddress);
// const assetNameSuffix = await getUniqueAssetName(userUtxos[0]!);
const assetNameSuffix = await getUniqueAssetName(selectedUtxo);
const refNFT = toUnit(
minter.policyID,
assetNameSuffix,
REFERENCE_TOKEN_LABEL
);
const userNFT = toUnit(
minter.policyID,
assetNameSuffix,
NON_FUNGIBLE_TOKEN_LABEL
);
console.log(refNFT);
console.log(userNFT);
const metadataData = Data.fromJson({ metadata });
const version = 1n;
const extra = Data.void();
const metadatum = Data.to(new Constr(0, [metadataData, version, extra]));
const mintRdmr = Data.to(new Constr(0, []));
// TODO: Instead of selecting all utxos at script and user addresses, select based on tx costs
try {
const tx = await lucid
.newTx()
.collectFrom([selectedUtxo])
.mintAssets({ [userNFT]: 1n, [refNFT]: 1n }, mintRdmr)
.attachMintingPolicy(minter.validator)
.payToAddress(meerkatAddress, { [userNFT]: 1n })
.payToContract(
store.lockedAddress,
{ inline: metadatum },
{
[refNFT]: 1n,
}
)
.addSigner(issuerAddress)
.addSigner(meerkatAddress)
.validFrom(Date.now() - 60 * 1000) // Substracting 1 minute to offset diff (blockfrost server time - local system time)
.validTo(Date.now() + 15 * 60 * 2000)
.complete({
change: { address: meerkatAddress },
coinSelection: false, // Setting to false to avoid using distributor funds
});
console.log("I am here");
const partialSignedTx = await tx.partialSign();
res.status(200).json({ tx, partialSignedTx });
} catch (error: any) {
console.log(error);
res.status(404).json({ message: error });
}
}
I appreciate your help. thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.