# Blockfrost/Cardano serialisation lib - Issue while signing transaction - signing key

**URL:** <https://forum.cardano.org/t/blockfrost-cardano-serialisation-lib-issue-while-signing-transaction-signing-key/95233>\
**Category:** Cardano Integration\
**Created:** [9 February 2022 17:28 UTC](https://forum.cardano.org/t/blockfrost-cardano-serialisation-lib-issue-while-signing-transaction-signing-key/95233 "2022-02-09T17:28:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AkshitV](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@AkshitV](https://forum.cardano.org/u/AkshitV)\
**Post date:** [9 February 2022 17:28 UTC](https://forum.cardano.org/t/blockfrost-cardano-serialisation-lib-issue-while-signing-transaction-signing-key/95233/1 "2022-02-09T17:28:55Z")

</div>

Hi fellas, i am following this to create and submit a transaction using this ([https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/index.ts](https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/index.ts))

But as we can see that this is basically only considering the utxos of the address 0. And it uses Address 0’s private key i guess to submit a transaction.

However there could be a case where utxos might be in some other address of the same account with same mnemonics.

So to use utxos of different addresses, i just looped through all the associated addreses which have utxos and i pushed them here in this utxo array ([https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/index.ts#L45](https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/index.ts#L45))

But as you can see the signing key that they are using is derived and returned over here ([https://github.com/blockfrost/blockfrost-js/blob/fb9a55fee07927f8d7c8b0a5aa9efd2d3daf6c77/examples/simple-transaction/src/helpers/key.ts#L45](https://github.com/blockfrost/blockfrost-js/blob/fb9a55fee07927f8d7c8b0a5aa9efd2d3daf6c77/examples/simple-transaction/src/helpers/key.ts#L45))

And then using this key to sign transaction over here  
([https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/helpers/signTransaction.ts](https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/helpers/signTransaction.ts))

So i wanted to know what should i pass as the sign key so that every utxo, which is from any address can be signed. Also what should be its format ?

I am getting this error when i use bipPrvKey.to\_raw\_key() as the sign key:

transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (MissingVKeyWitnessesUTXOW (WitHashes (fromList [KeyHash “some \_hash\_here”]))))])"

Also i might not understand anything apart from blockfrost or cardano serialization library.  
Open to any kind of help or suggestions .  
Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![bakon11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/bakon11/32/47167_2.png) [@bakon11](https://forum.cardano.org/u/bakon11)\
**Post date:** [12 February 2022 16:12 UTC](https://forum.cardano.org/t/blockfrost-cardano-serialisation-lib-issue-while-signing-transaction-signing-key/95233/2 "2022-02-12T16:12:04Z")

</div>

Hey,

I was wondering if you’ve made any head way on your issue?

I’m facing the same problem and also made an issue on the github here.

> <https://github.com/Emurgo/cardano-serialization-lib/issues/366>
>
> So I'm just creating a simple TX of sending some ADA from one address to another… and cardano-cli spits out the following error.
> 
> \`Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError \[UtxowFailure (WrappedShelleyEraFailure (MissingVKeyWitnessesUTXOW (WitHashes (fromList \[KeyHash "a1c10c4767a63fe4983f1882d74d110652e9e7335d49db55f94e9841"\]))))\])
> \`
> 
> Am I understanding correctly based on this\`MissingVKeyWitnessesUTXOW\`: that I'm not signing the TX correctly?
> 
> Thank you.
> 
> Example of my code:  
> 
> \`\`\`typescript
> import CardanoWasm = require('@emurgo/cardano-serialization-lib-nodejs')
> import { mnemonicToEntropy } from 'bip39';
> import { entropyToRoot } from "../utils/wallet";
> 
> export const buildTX = async ( key: string, txix: string, txixIndex: number, inputValue: string, outputAddress: string, outputValue: 
> string, changeAddress: string, txTTL: number ) =\> {
> 
> // instantiate the tx builder with the Cardano protocol parameters - these may change later on
> const txBuilder = CardanoWasm.TransactionBuilder.new(
> CardanoWasm.TransactionBuilderConfigBuilder.new()
> .fee\_algo( CardanoWasm.LinearFee.new(CardanoWasm.BigNum.from\_str('44'),CardanoWasm.BigNum.from\_str('155381')))
> .pool\_deposit(CardanoWasm.BigNum.from\_str('500000000'),)
> .key\_deposit( CardanoWasm.BigNum.from\_str('2000000'),)
> .coins\_per\_utxo\_word(CardanoWasm.BigNum.from\_str('34482'))
> .max\_value\_size(5000)
> .max\_tx\_size(16384)
> .build()
> );
> 
> // NOTE: The private key here is modified and will not work it is just show as an example
> const entropy = await mnemonicToEntropy("fantasy length rug fatal bounce shield dad went out soccer sustain almost female street merit finish raven cost play shove height extra anxiety hint");
>     
> //Creates Root key from Entropy
> const rootKey = await entropyToRoot( entropy );
> // derives a hardened account xprv key 
> const xprvKey: any = await genAccountKeyPrv(rootKey, purpose, coinType);
> 
> // output address
> const shelleyOutputAddress = CardanoWasm.Address.from\_bech32(outputAddress);
> // change address
> const shelleyChangeAddress = CardanoWasm.Address.from\_bech32(changeAddress);
> 
> txBuilder.add\_key\_input(
> xprvKey.to\_public().to\_raw\_key().hash(),
> CardanoWasm.TransactionInput.new(
> CardanoWasm.TransactionHash.from\_bytes(
> Buffer.from(txix, "hex")
> ), // tx hash
> txixIndex, // index
> ),
> CardanoWasm.Value.new(CardanoWasm.BigNum.from\_str(inputValue))
> );
> 
> // output for receiver
> txBuilder.add\_output(
> CardanoWasm.TransactionOutputBuilder.new()
> .with\_address(shelleyOutputAddress)
> .next()
> .with\_value(CardanoWasm.Value.new(CardanoWasm.BigNum.from\_str(outputValue)))
> .build()
> );
>     
> // set the time to live - the absolute slot value before the tx becomes invalid
> txBuilder.set\_ttl(txTTL);
> 
> // calculate the min fee required and send any change to an address
> 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, xprvKey.to\_raw\_key());
> vkeyWitnesses.add(vkeyWitness);
> witnesses.set\_vkeys(vkeyWitnesses);
> 
> // create the finalized transaction with witnesses
> const transaction = CardanoWasm.Transaction.new(
> txBody,
> witnesses,
> undefined, // transaction metadata
> );
> 
> const txHex = Buffer.from(transaction.to\_bytes()).toString("hex");
> console.log(txHex);
> return(txHex);
> };
> \`\`\`

Thanks.

---

<div class="post-metadata">

**Author:** ![AkshitV](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@AkshitV](https://forum.cardano.org/u/AkshitV)\
**Post date:** [16 February 2022 07:59 UTC](https://forum.cardano.org/t/blockfrost-cardano-serialisation-lib-issue-while-signing-transaction-signing-key/95233/3 "2022-02-16T07:59:01Z")

</div>

Hi @bakon11

Yes that got resolved with correct signKey.

But i am currently facing this issue : were transaction.to\_bytes() defined over here ([blockfrost-js/index.ts at master · blockfrost/blockfrost-js · GitHub](https://github.com/blockfrost/blockfrost-js/blob/master/examples/simple-transaction/src/index.ts#L88))  
return an empty array : Uint8Array(0)

It sometimes return correct Array when i run from one file, then if i call this from some other file it returns this empty Array.

The variable transaction is of class Transaction only (when i log it).

Could this be somehow related to some wasm memory buffer issue ?
