@mutants/cardano v1.20.3
Mutants Cardano BETA
This library is an alternative to the cardano-serialization-lib and does not require your app to load WebAssembly code.
Sample transaction
In this transaction, the seller is sending a Mutant Croc NFT to our Marketplace validator, including a datum.
import {
UTXOS,
AssetUtils,
RequiredInputs,
RequiredOutputs,
TransactionBuilder,
} from "@mutants/cardano";
// This is the asset the seller is going to send to our validator.
const mutantCrocAsset = {
unit: "d517f38dd2c5acc3347c8e933e2c0185fafe3ba838f8830000a3c95f44724361726f6e6f566163696e75733030303030",
quantity: "1"
};
const estimateFee = 500000;
const sellerAddress = "addr1..." // Here you define the NFT seller payment address
// Here we calculate the min ADA required to be attached to the NFT
const minAdaUtxo = UTXOS.calculateMinMultiassetCost(
AssetUtils.fromAssetsToPolicyMap([mutantCrocAsset])
);
// Here we define the seller required inputs. In order to send the NFT to the validator, we need to consume the NFT utxo,
// so we add the token, the min ADA that needs to be attached to it and an estimate fee (fee will be recalculated later)
const requiredInputs: RequiredInputs = {
[sellerAddress]: {
totalCoin: requiredUtxoADA + estimateFee,
tokens: inputToken,
},
};
// Here we define the required outputs. Since we want to send our NFT to our validator, we use the validator address here
// and determine that an output should be created with the Mutant NFT asset plus the minimum ADA required to be attached to that NFT.
// We also add the datum here, that will be used in our Plutus validator.
// In this case the datum has only 2 fields but ofc this would change depending in your validator script.
const datum = {
constructor: 0,
fields: [
{
bytes: seller,
},
{
int: price,
}
]
};
const requiredOutputs: RequiredOutputs = {
[validator.address]: {
totalCoin: minAdaUtxo,
tokens: [mutantCrocAsset],
datum,
},
};
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago