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 )
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 )
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 )
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 )
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
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.
opened 01:58PM - 10 Feb 22 UTC
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.
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 )
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 ?