BlockfrostServerError: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (WrappedShelleyEraFailure (MissingVKeyWitnessesUTXOW (WitHashes (fromList [KeyHash \"b5cfe7a19bd626bd0d26657e

I am trying to generate a transaction using @emurgo/cardano-serialization-lib-nodejs I am gettting this error when i am trying to generate a transaction.

i am generating my private key and base address using bip39 library function mnemonicToEntropy

const getKeyDetails = () => {
  const rootKey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(
    Buffer.from(entropy, "hex"),
    Buffer.from("")
  );
  const privateKey = rootKey.to_raw_key();
  const publicKey = rootKey.to_public().to_raw_key();
  const accountKey = rootKey
    .derive(harden(1852))
    .derive(harden(1815))
    .derive(harden(0));
  const utxoPubKey = accountKey.derive(0).derive(0).to_public();
  const stakeKey = accountKey.derive(2).derive(0).to_public();
  return { privateKey, publicKey, utxoPubKey, stakeKey, accountKey };
};

function harden(num) {
  return 0x80000000 + num;
}

const getPublicKey = () => {
  const keyDetails = getKeyDetails();
  return keyDetails.publicKey;
};
const getPrivateKey = () => {
  const keyDetails = getKeyDetails();
  return keyDetails.privateKey;
};
const ptrAddr = CardanoWasm.PointerAddress.new(
  CardanoWasm.NetworkInfo.testnet().network_id(),
  CardanoWasm.StakeCredential.from_keyhash(
    getKeyDetails().utxoPubKey.to_raw_key().hash()
  ),
  CardanoWasm.Pointer.new(
    100, // slot
    2, // tx index in slot
    0 // cert indiex in tx
  )
);

const getBaseAddress = () => {
  const keyDetails = getKeyDetails();
  const baseAddr = CardanoWasm.BaseAddress.new(
    CardanoWasm.NetworkInfo.testnet().network_id(),

    CardanoWasm.StakeCredential.from_keyhash(
      keyDetails.utxoPubKey.to_raw_key().hash()
    ),

    CardanoWasm.StakeCredential.from_keyhash(
      keyDetails.stakeKey.to_raw_key().hash()
    )
  );

  return baseAddr;
};```
i am getting the private key through this method 
getPrivateKey().to_bech32()

and base address like this 
getBaseAddress().to_address().to_bech32()

and the way i am generating the transaction is below:

```javascript
let utxo = [];
  try {
    utxo = await client.addressesUtxosAll(OWNER_ADDRESS);
  } catch (error) {
    if (error instanceof BlockfrostServerError && error.status_code === 404) {
      // Address derived from the seed was not used yet
      // In this case Blockfrost API will return 404
      utxo = [];
    } else {
      throw error;
    }
  }
  if (utxo.length === 0) {
    console.log();
    console.log(
      `You should send ADA to ${OWNER_ADDRESS} to have enough funds to sent a transaction`
    );
    console.log();
  }
  console.log(`UTXO on ${OWNER_ADDRESS}:`);
  console.log(JSON.stringify(utxo, undefined, 4));
  transaction();
}
async function transaction() {
  let user_address = CardanoWasm.Address.from_bech32(
    "addr_test1qz6uleapn0tzd0gdyejhanadqnw3jnxg9gvxzwfr8g3x4d220lldl3pyxdvp8nxdgd2hjmleruq6fqjyu4caztnx6scq53l9kh"
  );
  // instantiate the tx builder with the Cardano protocol parameters - these may change later on
  const linearFee = CardanoWasm.LinearFee.new(
    CardanoWasm.BigNum.from_str("44"),
    CardanoWasm.BigNum.from_str("155381")
  );
  const txBuilderCfg = CardanoWasm.TransactionBuilderConfigBuilder.new()
    .fee_algo(linearFee)
    .pool_deposit(CardanoWasm.BigNum.from_str("500000000"))
    .key_deposit(CardanoWasm.BigNum.from_str("2000000"))
    .max_value_size(4000)
    .max_tx_size(8000)
    .coins_per_utxo_word(CardanoWasm.BigNum.from_str("34482"))
    .build();
  try {
    const txBuilder = CardanoWasm.TransactionBuilder.new(txBuilderCfg);
    // add a keyhash input - for ADA held in a Shelley-era normal address (Base, Enterprise, Pointer)

    txBuilder.add_key_input(
      PRIVATE_KEY.to_public().hash(),
      CardanoWasm.TransactionInput.new(
        CardanoWasm.TransactionHash.from_bytes(
          Buffer.from(
            "feee31f50c61b8f6eef59029796700e00396f8a3e6d602e64d27ae3bed33d168",
            "hex"
          )
        ), // tx hash
        1 // index
      ),
      CardanoWasm.Value.new(CardanoWasm.BigNum.from_str("1997663190"))
    );

    let remaining = 10000000000 - 3168273;

    // txBuilder.add_output(
    //   CardanoWasm.TransactionOutput.new(
    //     user_address,
    //     CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(remaining.toString()))
    //   )
    // );
    // base address
    const shelleyOutputAddress = CardanoWasm.Address.from_bech32(
      "addr_test1qq26sg0hxtcwkks59wscc8cqj320r9c03yylrp53n6n3hwstkak86z64tnhw6356lg5axm6s9vk33a9vat9ama0qn6qq9hj3k6"
    );

    // shelley change address
    const shelleyChangeAddress = CardanoWasm.Address.from_bech32(
      "addr_test1gz6uleapn0tzd0gdyejhanadqnw3jnxg9gvxzwfr8g3x4dtyqgqqd9kf3k"
    );
    // add output to the tx
    txBuilder.add_output(
      CardanoWasm.TransactionOutput.new(
        shelleyOutputAddress,
        CardanoWasm.Value.new(CardanoWasm.BigNum.from_str("10000000"))
      )
    );
    const latestBlock = await client.blocksLatest();

    // set the time to live - the absolute slot value before the tx becomes invalid
    txBuilder.set_ttl(latestBlock.slot + 7200);
    // txBuilder.set_fee(CardanoWasm.BigNum.from_str("168273"));
    txBuilder.add_change_if_needed(shelleyChangeAddress);

    // once the transaction is ready, we build it to get the tx body without witnesses
    const txBody = txBuilder.build();
    const txHash = CardanoWasm.hash_transaction(txBody);
    const witnesses = CardanoWasm.TransactionWitnessSet.new();

    // // add keyhash witnesses
    const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
    const vkeyWitness = CardanoWasm.make_vkey_witness(txHash, PRIVATE_KEY);
    vkeyWitnesses.add(vkeyWitness);
    witnesses.set_vkeys(vkeyWitnesses);

    // create the finalized transaction with witnesses
    const transaction = CardanoWasm.Transaction.new(txBody, witnesses);

    const response = await client.txSubmit(
      Buffer.from(transaction.to_bytes(), "hex")
    );
    return response;
  } catch (error) {
    console.error(error);
  }

i would be grateful if someone can help me sort out this.
i am getting this error

BlockfrostServerError: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (WrappedShelleyEraFailure (MissingVKeyWitnessesUTXOW (WitHashes (fromList [KeyHash \"b5cfe7a19bd626bd0d26657ecfad04dd194cc82a186139233a226ab5\"])))))])"

i followed this link to generate transaction

So, is OWNER_ADDRESS the one you get from getBaseAddress()?

But you are not using the utxo array you get from that, anyway.

…, but just hard-coding one specific transaction output that you want to use as input.

If that hard-coded input is not from your address, you can’t sign it.

means that you are trying to spend from an input, but have not provided a witness/signature for that input.

So, is OWNER_ADDRESS the one you get from getBaseAddress() ?

yes I got it from the base address function

…, but just hard-coding one specific transaction output that you want to use as input.

I was getting the UTXO from the owner address using the blockfrost just for testing purposes(just to get tx_hash and indexes), the tx_hash I got from there is in the add_input_key() function

this is the owner base address from getBaseAddress method:

addr_test1qz6uleapn0tzd0gdyejhanadqnw3jnxg9gvxzwfr8g3x4d220lldl3pyxdvp8nxdgd2hjmleruq6fqjyu4caztnx6scq53l9kh

and for the PRIVATE_KEY

getKeyDetails().privateKey

and storing it in the PRIVATE_KEY variable after using this method:

CardanoWasm.PrivateKey.from_bech32()

i am signing from the same private key and still getting the error

here is the tx_hash for the owner address UTXO

feee31f50c61b8f6eef59029796700e00396f8a3e6d602e64d27ae3bed33d168

That all looks correct, but I think I may have found something:

You are providing privateKey = rootKey.to_raw_key() here. You need to sign with the private key of the payment key, not with the root private key.

For a quick check try something like privateKey = accountKey.derive(0).derive(0) (maybe .to_raw_key() is needed?).

1 Like

i think it worked!!! the utxo is no more there but i can’t see the transaction on the cardanoscan yet i’ll update if i see it

oh my goddness !! it worked thank you so much :face_holding_back_tears: i couldn’t have make it if you didn’t helped once again thank you so much !!!

1 Like