I've forked a dApp Connector I found on Github and I'm trying to add some transaction metadata to the ADA transaction it builds. This is what I currently have:
buildSendADATransaction = async () => {
//metadata
const messageData = {
receiver_id: "SJKdj34k3jjKFDKfjFUDfdjkfd",
sender_id: "jkfdsufjdk34h3Sdfjdhfduf873",
comment: "happy birthday",
tags: [0, 264, -1024, 32],
};
const generalMetadata = GeneralTransactionMetadata.new();
console.log(Buffer.from(generalMetadata.to_bytes(), "hex").toString("hex"));
generalMetadata.insert(
BigNum.from_str("674"),
encode_json_str_to_metadatum(JSON.stringify(messageData))
);
const _metadata = AuxiliaryData.new();
_metadata.set_metadata(generalMetadata);
console.log(`the metadata is ${_metadata.metadata()}`);
// build tx
const txBuilder = await this.initTransactionBuilder();
const shelleyOutputAddress = Address.from_bech32(
this.state.addressBech32SendADA
);
const shelleyChangeAddress = Address.from_bech32(this.state.changeAddress);
txBuilder.add_output(
TransactionOutput.new(
shelleyOutputAddress,
Value.new(BigNum.from_str(this.state.lovelaceToSend.toString()))
)
);
// Find the available UTXOs in the wallet and
// use them as Inputs
const txUnspentOutputs = await this.getTxUnspentOutputs();
txBuilder.add_inputs_from(txUnspentOutputs, 1);
// 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();
txBody.set_auxiliary_data_hash(hash_auxiliary_data(_metadata));
// Tx witness
const transactionWitnessSet = TransactionWitnessSet.new();
const tx = Transaction.new(
txBody,
TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes()),
_metadata
);
let txVkeyWitnesses = await this.API.signTx(
Buffer.from(tx.to_bytes(), "utf8").toString("hex"),
true
);
txVkeyWitnesses = TransactionWitnessSet.from_bytes(
Buffer.from(txVkeyWitnesses, "hex")
);
transactionWitnessSet.set_vkeys(txVkeyWitnesses.vkeys());
const txBodyFinal = tx.body();
const signedTx = Transaction.new(
txBodyFinal,
transactionWitnessSet,
_metadata
);
const submittedTxHash = await this.API.submitTx(
Buffer.from(signedTx.to_bytes(), "utf8").toString("hex")
);
console.log(submittedTxHash);
this.setState({ submittedTxHash });
};
It constructs the transaction just fine with a wallet like Nami, but there's no metadata attached to that transaction. Any thoughts?