cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

mininum utxo ada set to 39 ada

Open dawar330 opened this issue 3 years ago • 3 comments

I am using @emurgo/cardano-serialization-lib-nodejs": "^10.0.4 to build my minting transactions but minada is 29 ada and when i add add_mint_asset_output it increases to 39 ada! Can anyone help ?

dawar330 avatar Mar 01 '22 09:03 dawar330

I am using @emurgo/cardano-serialization-lib-nodejs": "^10.0.4 to build my minting transactions but minada is 29 ada and when i add add_mint_asset_output it increases to 39 ada! Can anyone help ?

Provide the data on how are you building the transaction

vsubhuman avatar Mar 01 '22 09:03 vsubhuman

Here the code used to generate the mint transaction

const initializeTx = (lib) => { const metadata = {};

const Parameters = getProtocolParameters(); var TransactionBuilderConfig = lib.TransactionBuilderConfigBuilder.new() .fee_algo( lib.LinearFee.new( lib.BigNum.from_str(Parameters.linearFee.minFeeA), lib.BigNum.from_str(Parameters.linearFee.minFeeB) ) ) .coins_per_utxo_word(lib.BigNum.from_str(Parameters.coinsPerUtxoWord)) .pool_deposit(lib.BigNum.from_str(Parameters.poolDeposit)) .key_deposit(lib.BigNum.from_str(Parameters.keyDeposit)) .max_value_size(Parameters.maxValSize) .max_tx_size(Parameters.maxTxSize) .build();

const txBuilder = lib.TransactionBuilder.new(TransactionBuilderConfig); const datums = lib.PlutusList.new();

const outputs = lib.TransactionOutputs.new();

return { metadata, txBuilder, datums, outputs }; };

Cardano().then(async (lib) => { const rootKey = lib.Bip32PrivateKey.from_bech32( "xprv1lpzrf96pu0akj5klet24gk8swpyzp0lmy2yp2gpalan99ael5fp9yk35fjjs8vkms3zq2qg9n79q2f36jf4gnzpgyqaw8aqh964q6slqm0cmpspprmfgj65jrkxwp76h3ncyzpjyjuv388yrkem5ypj00vlsawg6" ); const accountKey = rootKey .derive(harden(1852)) // purpose .derive(harden(1815)) // coin type .derive(harden(0)); const Wallet = { rootKey: rootKey,

paymentKey: accountKey
  .derive(0) // external
  .derive(0)
  .to_raw_key(),
stakeKey: accountKey
  .derive(2) // chimeric
  .derive(0)
  .to_raw_key(),
paymentAddr: lib.BaseAddress.new(
  lib.NetworkInfo.testnet().network_id(),
  lib.StakeCredential.from_keyhash(
    accountKey
      .derive(0) // external
      .derive(0)
      .to_raw_key()
      .to_public()
      .hash()
  ),
  lib.StakeCredential.from_keyhash(
    accountKey
      .derive(2) // chimeric
      .derive(0)
      .to_raw_key()
      .to_public()
      .hash()
  )
)
  .to_address()
  .to_bech32(),

}; console.log(Wallet.paymentAddr); const genTx = ( lib, addr_keyhash, change_addr, timelockExpirySlot, assetNames, assetNum, addr, utxos, txBuilder ) => { try { const nativeScripts = lib.NativeScripts.new(); const scriptPubkey = lib.NativeScript.new_script_pubkey( lib.ScriptPubkey.new(addr_keyhash) ); const scriptTimelock = lib.NativeScript.new_timelock_expiry( lib.TimelockExpiry.new(timelockExpirySlot) );

  nativeScripts.add(scriptPubkey);
  nativeScripts.add(scriptTimelock);
  const nativeScript = lib.NativeScript.new_script_all(
    lib.ScriptAll.new(nativeScripts)
  );

  const policyId = Buffer.from(nativeScript.hash(0).to_bytes()).toString(
    "hex"
  );

  assetNames.map((assetNameStr) => {
    const assetName = lib.AssetName.new(Buffer.from(assetNameStr, "utf-8"));
    const assetNumber = lib.Int.new_i32(assetNum);

    txBuilder.add_mint_asset_and_output(
      nativeScript,
      assetName,
      assetNumber,
      lib.TransactionOutputBuilder.new().with_address(addr).next(),
      lib.BigNum.from_str("12 00000")
    );
  });
  txBuilder.set_ttl(timelockExpirySlot);

  var inputs = [];
  utxos.forEach((utxo) => {
    inputs.push({
      utxo: utxo.input(),
      value: utxo.output().amount(),
    });
  });
  txBuilder.add_key_input(addr_keyhash, inputs[0].utxo, inputs[0].value);

  txBuilder.add_change_if_needed(lib.Address.from_bech32(change_addr));
  console.log(txBuilder.get_fee_if_set().to_str());
  const tx = txBuilder.build_tx();

  return { tx, nativeScript };
} catch (error) {
  console.log(error, "asda");
}

}; const mintToken = async (lib, wallet, addr) => { var timelockExpirySlot = 51749091 + 100000; // some slot in the future const { txBuilder } = transactions.initializeTx(lib);

const rawUtxos = await getUtxos(
  "addr_test1qpw5zprwnvyw7adzd5leps4uwj5hz9ca9dumrhu5z88zy8kmapmlerstcmpgv025epwdlwhvhyk6ysgc3tvlgdktyajshegfyv"
);

const utxos = rawUtxos.map((utxo) =>
  transactions.serializeTxUnspentOutput(
    lib,
    utxo,
    "addr_test1qpw5zprwnvyw7adzd5leps4uwj5hz9ca9dumrhu5z88zy8kmapmlerstcmpgv025epwdlwhvhyk6ysgc3tvlgdktyajshegfyv"
  )
);

const keyHash = wallet.paymentKey.to_public().hash();

console.log(keyHash);

const { tx, nativeScript } = genTx(
  lib,
  keyHash,
  Wallet.paymentAddr,
  timelockExpirySlot,
  ["Dawar", "umer", "Bilal", "zain", "warda", "Rafay", "Mateen", "saad"],
  1,
  addr,
  utxos,
  txBuilder
);

// We use a custom signTx method similar to the one in Nami wallet but it also takes a wallet object as an argument
// which is used for signing the transaction.

const txVkeyWitness = transactions.signTx(wallet, lib, tx);
console.log(txVkeyWitness, "SIGNED");
const txWitnesses = lib.TransactionWitnessSet.from_bytes(
  Buffer.from(txVkeyWitness.to_bytes(), "hex")
);

const transactionWitnessSet = tx.witness_set();
transactionWitnessSet.set_vkeys(txWitnesses.vkeys());

const signedTx = lib.Transaction.new(tx.body(), transactionWitnessSet);
console.log(Buffer.from(signedTx.to_bytes(), "hex").toString("hex"));
// return await submitTx(
//   Buffer.from(signedTx.to_bytes(), "hex").toString("hex")
// );

};

// In this example a wallet object has the following properties: // const w = { // "rootKey": ..., // "paymentKey": ..., // "stakeKey": .., // "paymentAddr": .. // }

const rawUtxos = await getUtxos( "addr_test1qpw5zprwnvyw7adzd5leps4uwj5hz9ca9dumrhu5z88zy8kmapmlerstcmpgv025epwdlwhvhyk6ysgc3tvlgdktyajshegfyv" );

const utxos = rawUtxos.map((utxo) => transactions.serializeTxUnspentOutput( lib, utxo, "addr_test1qpw5zprwnvyw7adzd5leps4uwj5hz9ca9dumrhu5z88zy8kmapmlerstcmpgv025epwdlwhvhyk6ysgc3tvlgdktyajshegfyv" ) );

const tx = mintToken( lib, Wallet, lib.Address.from_bech32( "addr_test1qzlvtscwzwpet54zt2qdnlg36v94efjyu3ghtuaqxhuswkk2gv8e2enjnw5fnhf06xq7a3n4cq2ngmnre0f7pdzyrr4s69m25x" ) ); });

dawar330 avatar Mar 02 '22 06:03 dawar330

??????

dawar330 avatar Mar 04 '22 06:03 dawar330